From 488e09a789fe633309abda5f9b65d55a9ab6e10a Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 2 May 2017 14:17:48 -0400 Subject: [PATCH] ir: make bt_ctf_trace_create() create an empty packet header FT MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently bt_ctf_trace_create() creates an initial default packet header field type with the `magic`, `uuid`, and `stream_id` fields. This is, in fact, specific to CTF writer. Since the trace API is not public yet, move this default packet header FT creation from bt_ctf_trace_create() to bt_ctf_writer_create() to ensure backward compatibility. This patch also fixes a few things in the API doc. of trace.h. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- include/babeltrace/ctf-ir/trace.h | 21 +++++------ lib/ctf-ir/trace.c | 61 +++---------------------------- lib/ctf-writer/writer.c | 57 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 67 deletions(-) diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index 5d611f8c..feb5a6de 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -155,21 +155,18 @@ struct bt_ctf_clock_class; @brief Creates a default CTF IR trace class. On success, the trace packet header field type of the created trace -class has the following fields: - -- magic: a 32-bit unsigned integer field type. -- uuid: an array field type of 16 8-bit unsigned integer - field types. -- stream_id: a 32-bit unsigned integer field type. - -You can modify this default trace packet header field type after the -trace class is created with bt_ctf_trace_set_packet_header_type(). +class is an empty structure field type. You can modify this default +trace packet header field type after the trace class is created with +bt_ctf_trace_get_packet_header_type() and +bt_ctf_trace_set_packet_header_type(). The created trace class has the following initial properties: - Name: none. You can set a name with bt_ctf_trace_set_name(). -- Default byte order: #BT_CTF_BYTE_ORDER_NATIVE. You +- UUID: none. You can set a UUID with + bt_ctf_trace_set_uuid(). +- Native byte order: #BT_CTF_BYTE_ORDER_NATIVE. You can set a native byte order with bt_ctf_trace_set_native_byte_order(). Note that you \em must set the native byte order if any field type @@ -236,7 +233,7 @@ extern int bt_ctf_trace_set_name(struct bt_ctf_trace *trace_class, @param[in] trace_class Trace class of which to get the default byte order. -@returns Default byte order of \p trace_class, +@returns Native byte order of \p trace_class, or #BT_CTF_BYTE_ORDER_UNKNOWN on error. @prenotnull{trace_class} @@ -260,7 +257,7 @@ extern enum bt_ctf_byte_order bt_ctf_trace_get_native_byte_order( @param[in] trace_class Trace class of which to set the native byte order. -@param[in] native_byte_order Default byte order of the trace class. +@param[in] native_byte_order Native byte order of the trace class. @returns 0 on success, or a negative value on error. @prenotnull{trace_class} diff --git a/lib/ctf-ir/trace.c b/lib/ctf-ir/trace.c index a4bc9906..ba18eab8 100644 --- a/lib/ctf-ir/trace.c +++ b/lib/ctf-ir/trace.c @@ -59,8 +59,6 @@ struct listener_wrapper { static void bt_ctf_trace_destroy(struct bt_object *obj); static -int init_trace_packet_header(struct bt_ctf_trace *trace); -static void bt_ctf_trace_freeze(struct bt_ctf_trace *trace); static @@ -84,6 +82,7 @@ const unsigned int field_type_aliases_sizes[] = { struct bt_ctf_trace *bt_ctf_trace_create(void) { struct bt_ctf_trace *trace = NULL; + struct bt_ctf_field_type *packet_header_type = NULL; trace = g_new0(struct bt_ctf_trace, 1); if (!trace) { @@ -102,10 +101,13 @@ struct bt_ctf_trace *bt_ctf_trace_create(void) goto error; } - if (init_trace_packet_header(trace)) { + packet_header_type = bt_ctf_field_type_structure_create(); + if (!packet_header_type) { goto error; } + BT_MOVE(trace->packet_header_type, packet_header_type); + /* Create the environment array object */ trace->environment = bt_ctf_attributes_create(); if (!trace->environment) { @@ -122,6 +124,7 @@ struct bt_ctf_trace *bt_ctf_trace_create(void) error: BT_PUT(trace); + bt_put(packet_header_type); return trace; } @@ -1289,58 +1292,6 @@ void bt_ctf_trace_freeze(struct bt_ctf_trace *trace) trace->frozen = 1; } -static -int init_trace_packet_header(struct bt_ctf_trace *trace) -{ - int ret = 0; - struct bt_ctf_field *magic = NULL, *uuid_array = NULL; - struct bt_ctf_field_type *_uint32_t = - get_field_type(FIELD_TYPE_ALIAS_UINT32_T); - struct bt_ctf_field_type *_uint8_t = - get_field_type(FIELD_TYPE_ALIAS_UINT8_T); - struct bt_ctf_field_type *trace_packet_header_type = - bt_ctf_field_type_structure_create(); - struct bt_ctf_field_type *uuid_array_type = - bt_ctf_field_type_array_create(_uint8_t, 16); - - if (!trace_packet_header_type || !uuid_array_type) { - ret = -1; - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, - _uint32_t, "magic"); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, - uuid_array_type, "uuid"); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, - _uint32_t, "stream_id"); - if (ret) { - goto end; - } - - ret = bt_ctf_trace_set_packet_header_type(trace, - trace_packet_header_type); - if (ret) { - goto end; - } -end: - bt_put(uuid_array_type); - bt_put(_uint32_t); - bt_put(_uint8_t); - bt_put(magic); - bt_put(uuid_array); - bt_put(trace_packet_header_type); - return ret; -} - bool bt_ctf_trace_is_static(struct bt_ctf_trace *trace) { bool is_static = false; diff --git a/lib/ctf-writer/writer.c b/lib/ctf-writer/writer.c index 9fd2f7dd..6c4bbded 100644 --- a/lib/ctf-writer/writer.c +++ b/lib/ctf-writer/writer.c @@ -49,6 +49,58 @@ static void bt_ctf_writer_destroy(struct bt_object *obj); +static +int init_trace_packet_header(struct bt_ctf_trace *trace) +{ + int ret = 0; + struct bt_ctf_field *magic = NULL, *uuid_array = NULL; + struct bt_ctf_field_type *_uint32_t = + get_field_type(FIELD_TYPE_ALIAS_UINT32_T); + struct bt_ctf_field_type *_uint8_t = + get_field_type(FIELD_TYPE_ALIAS_UINT8_T); + struct bt_ctf_field_type *trace_packet_header_type = + bt_ctf_field_type_structure_create(); + struct bt_ctf_field_type *uuid_array_type = + bt_ctf_field_type_array_create(_uint8_t, 16); + + if (!trace_packet_header_type || !uuid_array_type) { + ret = -1; + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, + _uint32_t, "magic"); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, + uuid_array_type, "uuid"); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, + _uint32_t, "stream_id"); + if (ret) { + goto end; + } + + ret = bt_ctf_trace_set_packet_header_type(trace, + trace_packet_header_type); + if (ret) { + goto end; + } +end: + bt_put(uuid_array_type); + bt_put(_uint32_t); + bt_put(_uint8_t); + bt_put(magic); + bt_put(uuid_array); + bt_put(trace_packet_header_type); + return ret; +} + struct bt_ctf_writer *bt_ctf_writer_create(const char *path) { int ret; @@ -75,6 +127,11 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) goto error_destroy; } + ret = init_trace_packet_header(writer->trace); + if (ret) { + goto error_destroy; + } + /* Generate a UUID for this writer's trace */ uuid_generate(uuid); ret = bt_ctf_trace_set_uuid(writer->trace, uuid); -- 2.34.1