X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Futils%2Ftrimmer%2Fiterator.c;h=06623086e20589a1942e9413a7ed26be789eaa25;hb=86e2016257efab15a90791c1688beea6ee5fce05;hp=f35f3a9705dd449ed03d407cc78ab8b0af96211d;hpb=5fc02ebca6fce559b7f1e7c35d2c73f67b262a7b;p=babeltrace.git diff --git a/plugins/utils/trimmer/iterator.c b/plugins/utils/trimmer/iterator.c index f35f3a97..06623086 100644 --- a/plugins/utils/trimmer/iterator.c +++ b/plugins/utils/trimmer/iterator.c @@ -51,17 +51,28 @@ #include "iterator.h" #include "copy.h" +static +gboolean close_packets(gpointer key, gpointer value, gpointer user_data) +{ + struct bt_ctf_packet *writer_packet = value; + + bt_put(writer_packet); + return TRUE; +} + BT_HIDDEN void trimmer_iterator_finalize(struct bt_private_notification_iterator *it) { - struct trimmer_iterator *it_data; + struct trimmer_iterator *trim_it; - it_data = bt_private_notification_iterator_get_user_data(it); - assert(it_data); + trim_it = bt_private_notification_iterator_get_user_data(it); + assert(trim_it); - bt_put(it_data->input_iterator); - g_hash_table_destroy(it_data->packet_map); - g_free(it_data); + bt_put(trim_it->input_iterator); + g_hash_table_foreach_remove(trim_it->packet_map, + close_packets, NULL); + g_hash_table_destroy(trim_it->packet_map); + g_free(trim_it); } BT_HIDDEN @@ -186,7 +197,7 @@ struct bt_notification *evaluate_event_notification( struct bt_notification *notification, struct trimmer_iterator *trim_it, struct trimmer_bound *begin, struct trimmer_bound *end, - bool *_event_in_range) + bool *_event_in_range, bool *finished) { int64_t ts; int clock_ret; @@ -256,6 +267,7 @@ struct bt_notification *evaluate_event_notification( } if (end->set && ts > end->value) { in_range = false; + *finished = true; } goto end; @@ -385,7 +397,7 @@ struct bt_notification *evaluate_packet_notification( struct bt_notification *notification, struct trimmer_iterator *trim_it, struct trimmer_bound *begin, struct trimmer_bound *end, - bool *_packet_in_range) + bool *_packet_in_range, bool *finished) { int64_t begin_ns, pkt_begin_ns, end_ns, pkt_end_ns; bool in_range = true; @@ -465,6 +477,9 @@ struct bt_notification *evaluate_packet_notification( if (!in_range) { goto end_no_notif; } + if (pkt_begin_ns > end_ns) { + *finished = true; + } if (begin_ns > pkt_begin_ns) { ret = update_packet_context_field(trim_it->err, writer_packet, @@ -527,18 +542,19 @@ enum bt_notification_iterator_status evaluate_notification( { enum bt_notification_type type; struct bt_notification *new_notification = NULL; + bool finished = false; *in_range = true; type = bt_notification_get_type(*notification); switch (type) { case BT_NOTIFICATION_TYPE_EVENT: new_notification = evaluate_event_notification(*notification, - trim_it, begin, end, in_range); + trim_it, begin, end, in_range, &finished); break; case BT_NOTIFICATION_TYPE_PACKET_BEGIN: case BT_NOTIFICATION_TYPE_PACKET_END: new_notification = evaluate_packet_notification(*notification, - trim_it, begin, end, in_range); + trim_it, begin, end, in_range, &finished); break; case BT_NOTIFICATION_TYPE_STREAM_END: new_notification = evaluate_stream_notification(*notification, @@ -551,6 +567,10 @@ enum bt_notification_iterator_status evaluate_notification( BT_PUT(*notification); *notification = new_notification; + if (finished) { + return BT_NOTIFICATION_ITERATOR_STATUS_END; + } + return BT_NOTIFICATION_ITERATOR_STATUS_OK; }