From 11b0cdc8d08794b52c9b07561fac1abac9b809a9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 15 Apr 2014 16:56:21 -0400 Subject: [PATCH] Split the CTF-Writer implementation in IR and Writer parts MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- configure.ac | 1 + formats/ctf/Makefile.am | 5 +- formats/ctf/ir/Makefile.am | 20 ++ formats/ctf/{writer => ir}/clock.c | 0 formats/ctf/{writer => ir}/event-fields.c | 0 formats/ctf/{writer => ir}/event-types.c | 0 formats/ctf/{writer => ir}/event.c | 0 formats/ctf/ir/stream-class.c | 416 ++++++++++++++++++++++ formats/ctf/writer/Makefile.am | 4 - formats/ctf/writer/stream.c | 376 ------------------- 10 files changed, 440 insertions(+), 382 deletions(-) create mode 100644 formats/ctf/ir/Makefile.am rename formats/ctf/{writer => ir}/clock.c (100%) rename formats/ctf/{writer => ir}/event-fields.c (100%) rename formats/ctf/{writer => ir}/event-types.c (100%) rename formats/ctf/{writer => ir}/event.c (100%) create mode 100644 formats/ctf/ir/stream-class.c diff --git a/configure.ac b/configure.ac index aefa8a59..c9a25e09 100644 --- a/configure.ac +++ b/configure.ac @@ -178,6 +178,7 @@ AC_CONFIG_FILES([ formats/lttng-live/Makefile formats/ctf/metadata/Makefile formats/ctf/writer/Makefile + formats/ctf/ir/Makefile converter/Makefile doc/Makefile lib/Makefile diff --git a/formats/ctf/Makefile.am b/formats/ctf/Makefile.am index 5d8a2970..7d97f8e6 100644 --- a/formats/ctf/Makefile.am +++ b/formats/ctf/Makefile.am @@ -1,6 +1,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -SUBDIRS = types metadata writer . +SUBDIRS = types metadata writer ir . lib_LTLIBRARIES = libbabeltrace-ctf.la @@ -20,4 +20,5 @@ libbabeltrace_ctf_la_LIBADD = \ types/libctf-types.la \ metadata/libctf-parser.la \ metadata/libctf-ast.la \ - writer/libctf-writer.la + writer/libctf-writer.la \ + ir/libctf-ir.la diff --git a/formats/ctf/ir/Makefile.am b/formats/ctf/ir/Makefile.am new file mode 100644 index 00000000..0247445c --- /dev/null +++ b/formats/ctf/ir/Makefile.am @@ -0,0 +1,20 @@ +AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include + +noinst_LTLIBRARIES = libctf-ir.la + +libctf_ir_la_SOURCES = \ + clock.c \ + event.c \ + event-fields.c \ + event-types.c \ + stream-class.c + +libctf_ir_la_LIBADD = \ + $(top_builddir)/lib/libbabeltrace.la + +if BABELTRACE_BUILD_WITH_LIBUUID +libctf_ir_la_LIBADD += -luuid +endif +if BABELTRACE_BUILD_WITH_LIBC_UUID +libctf_ir_la_LIBADD += -lc +endif diff --git a/formats/ctf/writer/clock.c b/formats/ctf/ir/clock.c similarity index 100% rename from formats/ctf/writer/clock.c rename to formats/ctf/ir/clock.c diff --git a/formats/ctf/writer/event-fields.c b/formats/ctf/ir/event-fields.c similarity index 100% rename from formats/ctf/writer/event-fields.c rename to formats/ctf/ir/event-fields.c diff --git a/formats/ctf/writer/event-types.c b/formats/ctf/ir/event-types.c similarity index 100% rename from formats/ctf/writer/event-types.c rename to formats/ctf/ir/event-types.c diff --git a/formats/ctf/writer/event.c b/formats/ctf/ir/event.c similarity index 100% rename from formats/ctf/writer/event.c rename to formats/ctf/ir/event.c diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c new file mode 100644 index 00000000..31224966 --- /dev/null +++ b/formats/ctf/ir/stream-class.c @@ -0,0 +1,416 @@ +/* + * stream.c + * + * Babeltrace CTF Writer + * + * Copyright 2013 EfficiOS Inc. + * + * Author: Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static +void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref); +static +int init_event_header(struct bt_ctf_stream_class *stream_class, + enum bt_ctf_byte_order byte_order); +static +int init_packet_context(struct bt_ctf_stream_class *stream_class, + enum bt_ctf_byte_order byte_order); + +struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name) +{ + struct bt_ctf_stream_class *stream_class = NULL; + + if (!name || !strlen(name)) { + goto error; + } + + stream_class = g_new0(struct bt_ctf_stream_class, 1); + if (!stream_class) { + goto error; + } + + stream_class->name = g_string_new(name); + stream_class->event_classes = g_ptr_array_new_with_free_func( + (GDestroyNotify)bt_ctf_event_class_put); + if (!stream_class->event_classes) { + goto error_destroy; + } + + bt_ctf_ref_init(&stream_class->ref_count); + return stream_class; + +error_destroy: + bt_ctf_stream_class_destroy(&stream_class->ref_count); + stream_class = NULL; +error: + return stream_class; +} + +int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, + struct bt_ctf_clock *clock) +{ + int ret = 0; + + if (!stream_class || !clock || stream_class->frozen) { + ret = -1; + goto end; + } + + if (stream_class->clock) { + bt_ctf_clock_put(stream_class->clock); + } + + stream_class->clock = clock; + bt_ctf_clock_get(clock); +end: + return ret; +} + +int bt_ctf_stream_class_add_event_class( + struct bt_ctf_stream_class *stream_class, + struct bt_ctf_event_class *event_class) +{ + int ret = 0; + + if (!stream_class || !event_class) { + ret = -1; + goto end; + } + + /* Check for duplicate event classes */ + struct search_query query = { .value = event_class, .found = 0 }; + g_ptr_array_foreach(stream_class->event_classes, value_exists, &query); + if (query.found) { + ret = -1; + goto end; + } + + if (bt_ctf_event_class_set_id(event_class, + stream_class->next_event_id++)) { + /* The event is already associated to a stream class */ + ret = -1; + goto end; + } + + bt_ctf_event_class_get(event_class); + g_ptr_array_add(stream_class->event_classes, event_class); +end: + return ret; +} + +void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class) +{ + if (!stream_class) { + return; + } + + bt_ctf_ref_get(&stream_class->ref_count); +} + +void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class) +{ + if (!stream_class) { + return; + } + + bt_ctf_ref_put(&stream_class->ref_count, bt_ctf_stream_class_destroy); +} + +BT_HIDDEN +void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class) +{ + if (!stream_class) { + return; + } + + stream_class->frozen = 1; + bt_ctf_clock_freeze(stream_class->clock); + g_ptr_array_foreach(stream_class->event_classes, + (GFunc)bt_ctf_event_class_freeze, NULL); +} + +BT_HIDDEN +int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, + uint32_t id) +{ + int ret = 0; + + if (!stream_class || + (stream_class->id_set && (id != stream_class->id))) { + ret = -1; + goto end; + } + + stream_class->id = id; + stream_class->id_set = 1; +end: + return ret; +} + +BT_HIDDEN +int bt_ctf_stream_class_set_byte_order(struct bt_ctf_stream_class *stream_class, + enum bt_ctf_byte_order byte_order) +{ + int ret = 0; + + ret = init_packet_context(stream_class, byte_order); + if (ret) { + goto end; + } + + ret = init_event_header(stream_class, byte_order); + if (ret) { + goto end; + } +end: + return ret; +} + +BT_HIDDEN +int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class, + struct metadata_context *context) +{ + int ret = 0; + size_t i; + + g_string_assign(context->field_name, ""); + context->current_indentation_level = 1; + if (!stream_class->id_set) { + ret = -1; + goto end; + } + + g_string_append_printf(context->string, + "stream {\n\tid = %" PRIu32 ";\n\tevent.header := ", + stream_class->id); + ret = bt_ctf_field_type_serialize(stream_class->event_header_type, + context); + if (ret) { + goto end; + } + + g_string_append(context->string, ";\n\n\tpacket.context := "); + ret = bt_ctf_field_type_serialize(stream_class->packet_context_type, + context); + if (ret) { + goto end; + } + + if (stream_class->event_context_type) { + g_string_append(context->string, ";\n\n\tevent.context := "); + ret = bt_ctf_field_type_serialize( + stream_class->event_context_type, context); + if (ret) { + goto end; + } + } + + g_string_append(context->string, ";\n};\n\n"); + + /* Assign this stream's ID to every event and serialize them */ + g_ptr_array_foreach(stream_class->event_classes, + (GFunc) bt_ctf_event_class_set_stream_id, + GUINT_TO_POINTER(stream_class->id)); + for (i = 0; i < stream_class->event_classes->len; i++) { + struct bt_ctf_event_class *event_class = + stream_class->event_classes->pdata[i]; + + ret = bt_ctf_event_class_set_stream_id(event_class, + stream_class->id); + if (ret) { + goto end; + } + + ret = bt_ctf_event_class_serialize(event_class, context); + if (ret) { + goto end; + } + } +end: + context->current_indentation_level = 0; + return ret; +} + +static +void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref) +{ + struct bt_ctf_stream_class *stream_class; + + if (!ref) { + return; + } + + stream_class = container_of(ref, struct bt_ctf_stream_class, ref_count); + bt_ctf_clock_put(stream_class->clock); + + if (stream_class->event_classes) { + g_ptr_array_free(stream_class->event_classes, TRUE); + } + + if (stream_class->name) { + g_string_free(stream_class->name, TRUE); + } + + bt_ctf_field_type_put(stream_class->event_header_type); + bt_ctf_field_put(stream_class->event_header); + bt_ctf_field_type_put(stream_class->packet_context_type); + bt_ctf_field_put(stream_class->packet_context); + bt_ctf_field_type_put(stream_class->event_context_type); + bt_ctf_field_put(stream_class->event_context); + g_free(stream_class); +} + +static +int init_event_header(struct bt_ctf_stream_class *stream_class, + enum bt_ctf_byte_order byte_order) +{ + int ret = 0; + struct bt_ctf_field_type *event_header_type = + bt_ctf_field_type_structure_create(); + struct bt_ctf_field_type *_uint32_t = + get_field_type(FIELD_TYPE_ALIAS_UINT32_T); + struct bt_ctf_field_type *_uint64_t = + get_field_type(FIELD_TYPE_ALIAS_UINT64_T); + + if (!event_header_type) { + ret = -1; + goto end; + } + + ret = bt_ctf_field_type_set_byte_order(_uint32_t, byte_order); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_set_byte_order(_uint64_t, byte_order); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(event_header_type, + _uint32_t, "id"); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(event_header_type, + _uint64_t, "timestamp"); + if (ret) { + goto end; + } + + stream_class->event_header_type = event_header_type; + stream_class->event_header = bt_ctf_field_create( + stream_class->event_header_type); + if (!stream_class->event_header) { + ret = -1; + } +end: + if (ret) { + bt_ctf_field_type_put(event_header_type); + } + + bt_ctf_field_type_put(_uint32_t); + bt_ctf_field_type_put(_uint64_t); + return ret; +} + +static +int init_packet_context(struct bt_ctf_stream_class *stream_class, + enum bt_ctf_byte_order byte_order) +{ + int ret = 0; + struct bt_ctf_field_type *packet_context_type = + bt_ctf_field_type_structure_create(); + struct bt_ctf_field_type *_uint64_t = + get_field_type(FIELD_TYPE_ALIAS_UINT64_T); + + if (!packet_context_type) { + ret = -1; + goto end; + } + + /* + * We create a stream packet context as proposed in the CTF + * specification. + */ + ret = bt_ctf_field_type_set_byte_order(_uint64_t, byte_order); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(packet_context_type, + _uint64_t, "timestamp_begin"); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(packet_context_type, + _uint64_t, "timestamp_end"); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(packet_context_type, + _uint64_t, "content_size"); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(packet_context_type, + _uint64_t, "packet_size"); + if (ret) { + goto end; + } + + ret = bt_ctf_field_type_structure_add_field(packet_context_type, + _uint64_t, "events_discarded"); + if (ret) { + goto end; + } + + stream_class->packet_context_type = packet_context_type; + stream_class->packet_context = bt_ctf_field_create(packet_context_type); + if (!stream_class->packet_context) { + ret = -1; + } +end: + if (ret) { + bt_ctf_field_type_put(packet_context_type); + goto end; + } + + bt_ctf_field_type_put(_uint64_t); + return ret; +} diff --git a/formats/ctf/writer/Makefile.am b/formats/ctf/writer/Makefile.am index 84ac03d5..6f791f55 100644 --- a/formats/ctf/writer/Makefile.am +++ b/formats/ctf/writer/Makefile.am @@ -4,11 +4,7 @@ noinst_LTLIBRARIES = libctf-writer.la libctf_writer_la_SOURCES = \ writer.c \ - clock.c \ stream.c \ - event-types.c \ - event-fields.c \ - event.c \ functor.c libctf_writer_la_LIBADD = \ diff --git a/formats/ctf/writer/stream.c b/formats/ctf/writer/stream.c index 71a8212e..1076dd3e 100644 --- a/formats/ctf/writer/stream.c +++ b/formats/ctf/writer/stream.c @@ -42,231 +42,8 @@ static void bt_ctf_stream_destroy(struct bt_ctf_ref *ref); static -void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref); -static -int init_event_header(struct bt_ctf_stream_class *stream_class, - enum bt_ctf_byte_order byte_order); -static -int init_packet_context(struct bt_ctf_stream_class *stream_class, - enum bt_ctf_byte_order byte_order); -static int set_structure_field_integer(struct bt_ctf_field *, char *, uint64_t); -struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name) -{ - struct bt_ctf_stream_class *stream_class = NULL; - - if (!name || !strlen(name)) { - goto error; - } - - stream_class = g_new0(struct bt_ctf_stream_class, 1); - if (!stream_class) { - goto error; - } - - stream_class->name = g_string_new(name); - stream_class->event_classes = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_event_class_put); - if (!stream_class->event_classes) { - goto error_destroy; - } - - bt_ctf_ref_init(&stream_class->ref_count); - return stream_class; - -error_destroy: - bt_ctf_stream_class_destroy(&stream_class->ref_count); - stream_class = NULL; -error: - return stream_class; -} - -int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, - struct bt_ctf_clock *clock) -{ - int ret = 0; - - if (!stream_class || !clock || stream_class->frozen) { - ret = -1; - goto end; - } - - if (stream_class->clock) { - bt_ctf_clock_put(stream_class->clock); - } - - stream_class->clock = clock; - bt_ctf_clock_get(clock); -end: - return ret; -} - -int bt_ctf_stream_class_add_event_class( - struct bt_ctf_stream_class *stream_class, - struct bt_ctf_event_class *event_class) -{ - int ret = 0; - - if (!stream_class || !event_class) { - ret = -1; - goto end; - } - - /* Check for duplicate event classes */ - struct search_query query = { .value = event_class, .found = 0 }; - g_ptr_array_foreach(stream_class->event_classes, value_exists, &query); - if (query.found) { - ret = -1; - goto end; - } - - if (bt_ctf_event_class_set_id(event_class, - stream_class->next_event_id++)) { - /* The event is already associated to a stream class */ - ret = -1; - goto end; - } - - bt_ctf_event_class_get(event_class); - g_ptr_array_add(stream_class->event_classes, event_class); -end: - return ret; -} - -void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class) -{ - if (!stream_class) { - return; - } - - bt_ctf_ref_get(&stream_class->ref_count); -} - -void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class) -{ - if (!stream_class) { - return; - } - - bt_ctf_ref_put(&stream_class->ref_count, bt_ctf_stream_class_destroy); -} - -BT_HIDDEN -void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class) -{ - if (!stream_class) { - return; - } - - stream_class->frozen = 1; - bt_ctf_clock_freeze(stream_class->clock); - g_ptr_array_foreach(stream_class->event_classes, - (GFunc)bt_ctf_event_class_freeze, NULL); -} - -BT_HIDDEN -int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, - uint32_t id) -{ - int ret = 0; - - if (!stream_class || - (stream_class->id_set && (id != stream_class->id))) { - ret = -1; - goto end; - } - - stream_class->id = id; - stream_class->id_set = 1; -end: - return ret; -} - -BT_HIDDEN -int bt_ctf_stream_class_set_byte_order(struct bt_ctf_stream_class *stream_class, - enum bt_ctf_byte_order byte_order) -{ - int ret = 0; - - ret = init_packet_context(stream_class, byte_order); - if (ret) { - goto end; - } - - ret = init_event_header(stream_class, byte_order); - if (ret) { - goto end; - } -end: - return ret; -} - -BT_HIDDEN -int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class, - struct metadata_context *context) -{ - int ret = 0; - size_t i; - - g_string_assign(context->field_name, ""); - context->current_indentation_level = 1; - if (!stream_class->id_set) { - ret = -1; - goto end; - } - - g_string_append_printf(context->string, - "stream {\n\tid = %" PRIu32 ";\n\tevent.header := ", - stream_class->id); - ret = bt_ctf_field_type_serialize(stream_class->event_header_type, - context); - if (ret) { - goto end; - } - - g_string_append(context->string, ";\n\n\tpacket.context := "); - ret = bt_ctf_field_type_serialize(stream_class->packet_context_type, - context); - if (ret) { - goto end; - } - - if (stream_class->event_context_type) { - g_string_append(context->string, ";\n\n\tevent.context := "); - ret = bt_ctf_field_type_serialize( - stream_class->event_context_type, context); - if (ret) { - goto end; - } - } - - g_string_append(context->string, ";\n};\n\n"); - - /* Assign this stream's ID to every event and serialize them */ - g_ptr_array_foreach(stream_class->event_classes, - (GFunc) bt_ctf_event_class_set_stream_id, - GUINT_TO_POINTER(stream_class->id)); - for (i = 0; i < stream_class->event_classes->len; i++) { - struct bt_ctf_event_class *event_class = - stream_class->event_classes->pdata[i]; - - ret = bt_ctf_event_class_set_stream_id(event_class, - stream_class->id); - if (ret) { - goto end; - } - - ret = bt_ctf_event_class_serialize(event_class, context); - if (ret) { - goto end; - } - } -end: - context->current_indentation_level = 0; - return ret; -} - BT_HIDDEN struct bt_ctf_stream *bt_ctf_stream_create( struct bt_ctf_stream_class *stream_class) @@ -531,159 +308,6 @@ void bt_ctf_stream_destroy(struct bt_ctf_ref *ref) g_free(stream); } -static -void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref) -{ - struct bt_ctf_stream_class *stream_class; - - if (!ref) { - return; - } - - stream_class = container_of(ref, struct bt_ctf_stream_class, ref_count); - bt_ctf_clock_put(stream_class->clock); - - if (stream_class->event_classes) { - g_ptr_array_free(stream_class->event_classes, TRUE); - } - - if (stream_class->name) { - g_string_free(stream_class->name, TRUE); - } - - bt_ctf_field_type_put(stream_class->event_header_type); - bt_ctf_field_put(stream_class->event_header); - bt_ctf_field_type_put(stream_class->packet_context_type); - bt_ctf_field_put(stream_class->packet_context); - bt_ctf_field_type_put(stream_class->event_context_type); - bt_ctf_field_put(stream_class->event_context); - g_free(stream_class); -} - -static -int init_event_header(struct bt_ctf_stream_class *stream_class, - enum bt_ctf_byte_order byte_order) -{ - int ret = 0; - struct bt_ctf_field_type *event_header_type = - bt_ctf_field_type_structure_create(); - struct bt_ctf_field_type *_uint32_t = - get_field_type(FIELD_TYPE_ALIAS_UINT32_T); - struct bt_ctf_field_type *_uint64_t = - get_field_type(FIELD_TYPE_ALIAS_UINT64_T); - - if (!event_header_type) { - ret = -1; - goto end; - } - - ret = bt_ctf_field_type_set_byte_order(_uint32_t, byte_order); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_set_byte_order(_uint64_t, byte_order); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(event_header_type, - _uint32_t, "id"); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(event_header_type, - _uint64_t, "timestamp"); - if (ret) { - goto end; - } - - stream_class->event_header_type = event_header_type; - stream_class->event_header = bt_ctf_field_create( - stream_class->event_header_type); - if (!stream_class->event_header) { - ret = -1; - } -end: - if (ret) { - bt_ctf_field_type_put(event_header_type); - } - - bt_ctf_field_type_put(_uint32_t); - bt_ctf_field_type_put(_uint64_t); - return ret; -} - -static -int init_packet_context(struct bt_ctf_stream_class *stream_class, - enum bt_ctf_byte_order byte_order) -{ - int ret = 0; - struct bt_ctf_field_type *packet_context_type = - bt_ctf_field_type_structure_create(); - struct bt_ctf_field_type *_uint64_t = - get_field_type(FIELD_TYPE_ALIAS_UINT64_T); - - if (!packet_context_type) { - ret = -1; - goto end; - } - - /* - * We create a stream packet context as proposed in the CTF - * specification. - */ - ret = bt_ctf_field_type_set_byte_order(_uint64_t, byte_order); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(packet_context_type, - _uint64_t, "timestamp_begin"); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(packet_context_type, - _uint64_t, "timestamp_end"); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(packet_context_type, - _uint64_t, "content_size"); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(packet_context_type, - _uint64_t, "packet_size"); - if (ret) { - goto end; - } - - ret = bt_ctf_field_type_structure_add_field(packet_context_type, - _uint64_t, "events_discarded"); - if (ret) { - goto end; - } - - stream_class->packet_context_type = packet_context_type; - stream_class->packet_context = bt_ctf_field_create(packet_context_type); - if (!stream_class->packet_context) { - ret = -1; - } -end: - if (ret) { - bt_ctf_field_type_put(packet_context_type); - goto end; - } - - bt_ctf_field_type_put(_uint64_t); - return ret; -} - static int set_structure_field_integer(struct bt_ctf_field *structure, char *name, uint64_t value) -- 2.34.1