static void ctf_destroy (void) { if (ctf_iter != NULL) { bt_ctf_iter_destroy (ctf_iter); ctf_iter = NULL; } if (ctx != NULL) { bt_context_put (ctx); ctx = NULL; } }
static int convert_trace(struct bt_trace_descriptor *td_write, struct bt_context *ctx) { struct bt_ctf_iter *iter; struct ctf_text_stream_pos *sout; struct bt_iter_pos *begin_pos = NULL, *end_pos = NULL; struct bt_ctf_event *ctf_event; int ret; sout = container_of(td_write, struct ctf_text_stream_pos, trace_descriptor); if (!sout->parent.event_cb) { return 0; } if (opt_stream_intersection) { iter = bt_ctf_iter_create_intersect(ctx, &begin_pos, &end_pos); } else { begin_pos = bt_iter_create_time_pos(NULL, 0); begin_pos->type = BT_SEEK_BEGIN; iter = bt_ctf_iter_create(ctx, begin_pos, NULL); } if (!iter) { ret = -1; goto error_iter; } while ((ctf_event = bt_ctf_iter_read_event(iter))) { ret = sout->parent.event_cb(&sout->parent, ctf_event->parent->stream); if (ret) { fprintf(stderr, "[error] Writing event failed.\n"); goto end; } ret = bt_iter_next(bt_ctf_get_iter(iter)); if (ret < 0) { goto end; } } ret = 0; end: bt_ctf_iter_destroy(iter); error_iter: bt_iter_free_pos(begin_pos); bt_iter_free_pos(end_pos); return ret; }