From 6f25f7c4a60d3646fd14741803895a3aad1c4ab1 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Mon, 5 Jun 2017 15:56:24 -0400 Subject: [PATCH] fs-sink: fix check trace completed when static is set MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The input trace could be set static when all its streams are closed, so we need to check if the trace is completed in the trace_static callback as well. Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- plugins/ctf/fs-sink/write.c | 36 ++++++++++++++++++++++++------------ plugins/ctf/fs-sink/writer.h | 1 + 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/plugins/ctf/fs-sink/write.c b/plugins/ctf/fs-sink/write.c index 3ac1b6f2..d8131d31 100644 --- a/plugins/ctf/fs-sink/write.c +++ b/plugins/ctf/fs-sink/write.c @@ -63,10 +63,31 @@ void destroy_stream_state_key(gpointer key) g_free((enum fs_writer_stream_state *) key); } +void check_completed_trace(gpointer key, gpointer value, gpointer user_data) +{ + enum fs_writer_stream_state *state = value; + int *trace_completed = user_data; + + if (*state != FS_WRITER_COMPLETED_STREAM) { + *trace_completed = 0; + } +} + static void trace_is_static_listener(struct bt_ctf_trace *trace, void *data) { - *((int *) data) = 1; + struct fs_writer *fs_writer = data; + int trace_completed = 1; + + fs_writer->trace_static = 1; + + g_hash_table_foreach(fs_writer->stream_states, + check_completed_trace, &trace_completed); + if (trace_completed) { + writer_close(fs_writer->writer_component, fs_writer); + g_hash_table_remove(fs_writer->writer_component->trace_map, + fs_writer->trace); + } } static @@ -258,6 +279,7 @@ struct fs_writer *insert_new_writer( fs_writer->writer = ctf_writer; fs_writer->trace = trace; fs_writer->writer_trace = writer_trace; + fs_writer->writer_component = writer_component; BT_PUT(writer_trace); fs_writer->stream_class_map = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) unref_stream_class); @@ -286,7 +308,7 @@ struct fs_writer *insert_new_writer( fs_writer->static_listener_id = -1; } else { ret = bt_ctf_trace_add_is_static_listener(trace, - trace_is_static_listener, &fs_writer->trace_static); + trace_is_static_listener, fs_writer); if (ret < 0) { fprintf(writer_component->err, "[error] %s in %s:%d\n", __func__, __FILE__, @@ -551,16 +573,6 @@ end: return ret; } -void check_completed_trace(gpointer key, gpointer value, gpointer user_data) -{ - enum fs_writer_stream_state *state = value; - int *trace_completed = user_data; - - if (*state != FS_WRITER_COMPLETED_STREAM) { - *trace_completed = 0; - } -} - BT_HIDDEN enum bt_component_status writer_stream_end( struct writer_component *writer_component, diff --git a/plugins/ctf/fs-sink/writer.h b/plugins/ctf/fs-sink/writer.h index 566b42ec..f1a4605b 100644 --- a/plugins/ctf/fs-sink/writer.h +++ b/plugins/ctf/fs-sink/writer.h @@ -60,6 +60,7 @@ struct fs_writer { struct bt_ctf_writer *writer; struct bt_ctf_trace *trace; struct bt_ctf_trace *writer_trace; + struct writer_component *writer_component; int static_listener_id; unsigned int active_streams; int trace_static; -- 2.34.1