From 387483fca23fe90a5d2470581192049ef74ec3ec Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Wed, 14 Jun 2017 17:38:24 -0400 Subject: [PATCH] Copy the packet_header in the plugins MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The trimmer, debug-info and fs-sink plugins now copy the packet_header from the trace received as parameter. Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- plugins/ctf/fs-sink/write.c | 9 +++- plugins/libctfcopytrace/ctfcopytrace.c | 75 +++++++++++++++++++++++++- plugins/libctfcopytrace/ctfcopytrace.h | 21 ++++++++ plugins/lttng-utils/copy.c | 17 +++++- plugins/utils/trimmer/copy.c | 17 +++++- 5 files changed, 133 insertions(+), 6 deletions(-) diff --git a/plugins/ctf/fs-sink/write.c b/plugins/ctf/fs-sink/write.c index 51bd7208..dd380f5b 100644 --- a/plugins/ctf/fs-sink/write.c +++ b/plugins/ctf/fs-sink/write.c @@ -673,7 +673,14 @@ enum bt_component_status writer_new_packet( __func__, __FILE__, __LINE__); goto error; } - BT_PUT(writer_stream); + + ret = ctf_stream_copy_packet_header(writer_component->err, + packet, writer_stream); + if (ret != 0) { + fprintf(writer_component->err, "[error] %s in %s:%d\n", + __func__, __FILE__, __LINE__); + goto error; + } goto end; diff --git a/plugins/libctfcopytrace/ctfcopytrace.c b/plugins/libctfcopytrace/ctfcopytrace.c index f5cd071a..d3373c1e 100644 --- a/plugins/libctfcopytrace/ctfcopytrace.c +++ b/plugins/libctfcopytrace/ctfcopytrace.c @@ -466,6 +466,79 @@ end: return writer_stream_class; } +BT_HIDDEN +int ctf_stream_copy_packet_header(FILE *err, struct bt_ctf_packet *packet, + struct bt_ctf_stream *writer_stream) +{ + struct bt_ctf_field *packet_header = NULL, *writer_packet_header = NULL; + int ret = 0; + + packet_header = bt_ctf_packet_get_header(packet); + if (!packet_header) { + goto end; + } + + writer_packet_header = bt_ctf_field_copy(packet_header); + if (!writer_packet_header) { + fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, + __LINE__); + goto error; + } + + ret = bt_ctf_stream_set_packet_header(writer_stream, + writer_packet_header); + if (ret) { + fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, + __LINE__); + goto error; + } + + goto end; + +error: + ret = -1; +end: + bt_put(writer_packet_header); + bt_put(packet_header); + return ret; +} + +BT_HIDDEN +int ctf_packet_copy_header(FILE *err, struct bt_ctf_packet *packet, + struct bt_ctf_packet *writer_packet) +{ + struct bt_ctf_field *packet_header = NULL, *writer_packet_header = NULL; + int ret = 0; + + packet_header = bt_ctf_packet_get_header(packet); + if (!packet_header) { + goto end; + } + + writer_packet_header = bt_ctf_field_copy(packet_header); + if (!writer_packet_header) { + fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, + __LINE__); + goto error; + } + + ret = bt_ctf_packet_set_header(writer_packet, writer_packet_header); + if (ret) { + fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, + __LINE__); + goto error; + } + + goto end; + +error: + ret = -1; +end: + bt_put(packet_header); + bt_put(writer_packet_header); + return ret; +} + BT_HIDDEN int ctf_stream_copy_packet_context(FILE *err, struct bt_ctf_packet *packet, struct bt_ctf_stream *writer_stream) @@ -813,7 +886,7 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_ctf_trace *trace, } } - header_type = bt_ctf_trace_get_packet_header_type(writer_trace); + header_type = bt_ctf_trace_get_packet_header_type(trace); if (header_type) { int_ret = bt_ctf_trace_set_packet_header_type(writer_trace, header_type); BT_PUT(header_type); diff --git a/plugins/libctfcopytrace/ctfcopytrace.h b/plugins/libctfcopytrace/ctfcopytrace.h index 785f8a47..74460f13 100644 --- a/plugins/libctfcopytrace/ctfcopytrace.h +++ b/plugins/libctfcopytrace/ctfcopytrace.h @@ -102,6 +102,27 @@ enum bt_component_status ctf_copy_packet_context_field(FILE *err, struct bt_ctf_field *writer_packet_context, struct bt_ctf_field_type *writer_packet_context_type); + +/* + * Copy the packet_header from the packet passed in parameter and assign it + * to the writer_stream. + * + * Returns 0 on success or -1 on error. + */ +BT_HIDDEN +int ctf_stream_copy_packet_header(FILE *err, struct bt_ctf_packet *packet, + struct bt_ctf_stream *writer_stream); + +/* + * Copy the packet_header from the packet passed in parameter and assign it + * to the writer_packet. + * + * Returns 0 on success or -1 on error. + */ +BT_HIDDEN +int ctf_packet_copy_header(FILE *err, struct bt_ctf_packet *packet, + struct bt_ctf_packet *writer_packet); + /* * Copy all the field values of the packet context from the packet passed in * parameter and set it to the writer_stream. diff --git a/plugins/lttng-utils/copy.c b/plugins/lttng-utils/copy.c index 629d81be..07590c7b 100644 --- a/plugins/lttng-utils/copy.c +++ b/plugins/lttng-utils/copy.c @@ -867,15 +867,28 @@ struct bt_ctf_packet *insert_new_packet(struct debug_info_iterator *debug_it, struct debug_info_trace *di_trace) { struct bt_ctf_packet *writer_packet; + int ret; writer_packet = bt_ctf_packet_create(writer_stream); if (!writer_packet) { fprintf(debug_it->err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__); - goto end; + goto error; + } + + ret = ctf_packet_copy_header(debug_it->err, packet, writer_packet); + if (ret) { + fprintf(debug_it->err, "[error] %s in %s:%d\n", __func__, + __FILE__, __LINE__); + goto error; } - g_hash_table_insert(di_trace->packet_map, (gpointer) packet, writer_packet); + g_hash_table_insert(di_trace->packet_map, (gpointer) packet, + writer_packet); + goto end; + +error: + BT_PUT(writer_packet); end: return writer_packet; } diff --git a/plugins/utils/trimmer/copy.c b/plugins/utils/trimmer/copy.c index ca0970a0..7bba7ac7 100644 --- a/plugins/utils/trimmer/copy.c +++ b/plugins/utils/trimmer/copy.c @@ -54,15 +54,28 @@ struct bt_ctf_packet *insert_new_packet(struct trimmer_iterator *trim_it, struct bt_ctf_stream *stream) { struct bt_ctf_packet *writer_packet = NULL; + int ret; writer_packet = bt_ctf_packet_create(stream); if (!writer_packet) { fprintf(trim_it->err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__); - goto end; + goto error; } - g_hash_table_insert(trim_it->packet_map, (gpointer) packet, writer_packet); + ret = ctf_packet_copy_header(trim_it->err, packet, writer_packet); + if (ret) { + fprintf(trim_it->err, "[error] %s in %s:%d\n", __func__, + __FILE__, __LINE__); + goto error; + } + + g_hash_table_insert(trim_it->packet_map, (gpointer) packet, + writer_packet); + goto end; + +error: + BT_PUT(writer_packet); end: return writer_packet; } -- 2.34.1