From 862ca4ed7b3a8ef14f69529d252bccc48a33108a Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 7 Dec 2018 15:02:41 -0500 Subject: [PATCH] lib: split trace API into trace class and trace APIs This patch adds the _trace class_ object and its API, moving some trace API functions to this one instead. The trace object was the only one holding both metadata and data objects (stream classes and streams, for example). To be more consistent, a trace class now deals with metadata only (no streams, no static state) and a trace with data only. A trace is an instance (data streams) of a trace class: you can have many traces described by the same trace class. You create a trace class with no parameters, while you create a trace with an existing trace class. Like for the trace object, the trace class API has both const and non-const APIs. Both a trace and a trace class can have a name (optional), just like both a stream and a stream class can have a name, and so on. With this patch, I chose to set the name of the trace object in both src.ctf.fs and src.text.dmesg, and to display the trace object's name in sink.text.pretty. Signed-off-by: Philippe Proulx --- include/Makefile.am | 2 + include/babeltrace/babeltrace.h | 2 + include/babeltrace/lib-logging-internal.h | 3 + include/babeltrace/trace-ir/event-internal.h | 5 + .../trace-ir/field-classes-internal.h | 11 +- .../babeltrace/trace-ir/packet-header-field.h | 4 +- .../babeltrace/trace-ir/stream-class-const.h | 4 +- .../trace-ir/stream-class-internal.h | 2 +- include/babeltrace/trace-ir/stream-class.h | 9 +- include/babeltrace/trace-ir/stream-const.h | 4 + include/babeltrace/trace-ir/stream-internal.h | 9 +- include/babeltrace/trace-ir/stream.h | 9 +- .../babeltrace/trace-ir/trace-class-const.h | 83 ++++ .../trace-ir/trace-class-internal.h | 84 ++++ include/babeltrace/trace-ir/trace-class.h | 77 ++++ include/babeltrace/trace-ir/trace-const.h | 28 +- include/babeltrace/trace-ir/trace-internal.h | 27 +- include/babeltrace/trace-ir/trace.h | 30 +- lib/graph/notification/event.c | 2 +- lib/lib-logging.c | 307 +++++++------ lib/trace-ir/Makefile.am | 1 + lib/trace-ir/event-class.c | 16 +- lib/trace-ir/event-header-field.c | 2 +- lib/trace-ir/field-classes.c | 10 +- lib/trace-ir/packet-context-field.c | 3 +- lib/trace-ir/packet-header-field.c | 18 +- lib/trace-ir/packet.c | 37 +- lib/trace-ir/stream-class.c | 75 ++-- lib/trace-ir/stream.c | 43 +- lib/trace-ir/trace-class.c | 422 ++++++++++++++++++ lib/trace-ir/trace.c | 322 ++----------- plugins/ctf/common/metadata/ast.h | 5 +- .../ctf/common/metadata/ctf-meta-translate.c | 40 +- .../ctf/common/metadata/ctf-meta-visitors.h | 2 +- plugins/ctf/common/metadata/ctf-meta.h | 9 +- plugins/ctf/common/metadata/decoder.c | 19 +- plugins/ctf/common/metadata/decoder.h | 10 +- .../ctf/common/metadata/visitor-generate-ir.c | 102 +---- plugins/ctf/common/notif-iter/notif-iter.c | 54 +-- plugins/ctf/fs-src/fs.c | 67 ++- plugins/ctf/fs-src/fs.h | 5 +- plugins/ctf/fs-src/metadata.c | 16 +- plugins/ctf/fs-src/metadata.h | 2 +- plugins/text/dmesg/dmesg.c | 78 ++-- plugins/text/pretty/print.c | 38 +- tests/lib/test_bt_notification_iterator.c | 90 ++-- tests/lib/test_trace_ir_ref.c | 32 +- 47 files changed, 1304 insertions(+), 916 deletions(-) create mode 100644 include/babeltrace/trace-ir/trace-class-const.h create mode 100644 include/babeltrace/trace-ir/trace-class-internal.h create mode 100644 include/babeltrace/trace-ir/trace-class.h create mode 100644 lib/trace-ir/trace-class.c diff --git a/include/Makefile.am b/include/Makefile.am index d3eb841d..da92f90b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -139,6 +139,8 @@ babeltracetraceirinclude_HEADERS = \ babeltrace/trace-ir/stream-class.h \ babeltrace/trace-ir/stream-const.h \ babeltrace/trace-ir/stream.h \ + babeltrace/trace-ir/trace-class-const.h \ + babeltrace/trace-ir/trace-class.h \ babeltrace/trace-ir/trace-const.h \ babeltrace/trace-ir/trace.h diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h index dc77567f..23e86821 100644 --- a/include/babeltrace/babeltrace.h +++ b/include/babeltrace/babeltrace.h @@ -85,6 +85,8 @@ #include #include #include +#include +#include #include #include diff --git a/include/babeltrace/lib-logging-internal.h b/include/babeltrace/lib-logging-internal.h index f7c20586..e3a74624 100644 --- a/include/babeltrace/lib-logging-internal.h +++ b/include/babeltrace/lib-logging-internal.h @@ -105,6 +105,9 @@ int bt_lib_log_level; * `a`: * Packet. The parameter type is `struct bt_packet *`. * + * `T`: + * Trace IR trace class. The parameter type is `struct bt_trace_class *`. + * * `t`: * Trace IR trace. The parameter type is `struct bt_trace *`. * diff --git a/include/babeltrace/trace-ir/event-internal.h b/include/babeltrace/trace-ir/event-internal.h index 884de630..eedceaea 100644 --- a/include/babeltrace/trace-ir/event-internal.h +++ b/include/babeltrace/trace-ir/event-internal.h @@ -53,8 +53,13 @@ struct bt_event { struct bt_object base; + + /* Owned by this */ struct bt_event_class *class; + + /* Owned by this */ struct bt_packet *packet; + struct bt_field_wrapper *header_field; struct bt_field *common_context_field; struct bt_field *specific_context_field; diff --git a/include/babeltrace/trace-ir/field-classes-internal.h b/include/babeltrace/trace-ir/field-classes-internal.h index b0860cd1..94056c3e 100644 --- a/include/babeltrace/trace-ir/field-classes-internal.h +++ b/include/babeltrace/trace-ir/field-classes-internal.h @@ -91,9 +91,9 @@ struct bt_field_class { /* * Only used in developer mode, this flag indicates whether or - * not this field class is part of a trace. + * not this field class is part of a trace class. */ - bool part_of_trace; + bool part_of_trace_class; }; struct bt_field_class_integer { @@ -242,12 +242,13 @@ void _bt_field_class_freeze(const struct bt_field_class *field_class); * shared objects for other purposes. */ BT_HIDDEN -void _bt_field_class_make_part_of_trace(const struct bt_field_class *field_class); +void _bt_field_class_make_part_of_trace_class( + const struct bt_field_class *field_class); #ifdef BT_DEV_MODE -# define bt_field_class_make_part_of_trace _bt_field_class_make_part_of_trace +# define bt_field_class_make_part_of_trace_class _bt_field_class_make_part_of_trace_class #else -# define bt_field_class_make_part_of_trace(_fc) ((void) _fc) +# define bt_field_class_make_part_of_trace_class(_fc) ((void) _fc) #endif #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */ diff --git a/include/babeltrace/trace-ir/packet-header-field.h b/include/babeltrace/trace-ir/packet-header-field.h index 34270443..ed03ae9a 100644 --- a/include/babeltrace/trace-ir/packet-header-field.h +++ b/include/babeltrace/trace-ir/packet-header-field.h @@ -30,13 +30,13 @@ extern "C" { #endif -struct bt_trace; +struct bt_trace_class; struct bt_packet_header_field; struct bt_field; extern struct bt_packet_header_field *bt_packet_header_field_create( - struct bt_trace *trace); + struct bt_trace_class *trace_class); extern struct bt_field *bt_packet_header_field_borrow_field( diff --git a/include/babeltrace/trace-ir/stream-class-const.h b/include/babeltrace/trace-ir/stream-class-const.h index 2b4cb3d3..57010987 100644 --- a/include/babeltrace/trace-ir/stream-class-const.h +++ b/include/babeltrace/trace-ir/stream-class-const.h @@ -37,14 +37,14 @@ extern "C" { #endif -struct bt_trace; +struct bt_trace_class; struct bt_stream_class; struct bt_event_class; struct bt_clock_class; struct bt_event_header_field; struct bt_packet_context_field; -extern const struct bt_trace *bt_stream_class_borrow_trace_const( +extern const struct bt_trace_class *bt_stream_class_borrow_trace_class_const( const struct bt_stream_class *stream_class); extern const char *bt_stream_class_get_name( diff --git a/include/babeltrace/trace-ir/stream-class-internal.h b/include/babeltrace/trace-ir/stream-class-internal.h index 72bbdd2b..8774db7a 100644 --- a/include/babeltrace/trace-ir/stream-class-internal.h +++ b/include/babeltrace/trace-ir/stream-class-internal.h @@ -80,7 +80,7 @@ void _bt_stream_class_freeze(const struct bt_stream_class *stream_class); #endif static inline -struct bt_trace *bt_stream_class_borrow_trace_inline( +struct bt_trace_class *bt_stream_class_borrow_trace_class_inline( const struct bt_stream_class *stream_class) { BT_ASSERT(stream_class); diff --git a/include/babeltrace/trace-ir/stream-class.h b/include/babeltrace/trace-ir/stream-class.h index 06ca44a7..67641477 100644 --- a/include/babeltrace/trace-ir/stream-class.h +++ b/include/babeltrace/trace-ir/stream-class.h @@ -37,17 +37,18 @@ extern "C" { #endif +struct bt_trace_class; struct bt_stream_class; -struct bt_trace; struct bt_event_class; struct bt_clock_class; -extern struct bt_stream_class *bt_stream_class_create(struct bt_trace *trace); +extern struct bt_stream_class *bt_stream_class_create( + struct bt_trace_class *trace_class); extern struct bt_stream_class *bt_stream_class_create_with_id( - struct bt_trace *trace, uint64_t id); + struct bt_trace_class *trace_class, uint64_t id); -extern struct bt_trace *bt_stream_class_borrow_trace( +extern struct bt_trace_class *bt_stream_class_borrow_trace_class( struct bt_stream_class *stream_class); extern int bt_stream_class_set_name(struct bt_stream_class *stream_class, diff --git a/include/babeltrace/trace-ir/stream-const.h b/include/babeltrace/trace-ir/stream-const.h index 7d4f0e36..f12ced9c 100644 --- a/include/babeltrace/trace-ir/stream-const.h +++ b/include/babeltrace/trace-ir/stream-const.h @@ -34,12 +34,16 @@ extern "C" { #endif +struct bt_trace; struct bt_stream; struct bt_stream_class; extern const struct bt_stream_class *bt_stream_borrow_class_const( const struct bt_stream *stream); +extern const struct bt_trace *bt_stream_borrow_trace_const( + const struct bt_stream *stream); + extern const char *bt_stream_get_name(const struct bt_stream *stream); extern uint64_t bt_stream_get_id(const struct bt_stream *stream); diff --git a/include/babeltrace/trace-ir/stream-internal.h b/include/babeltrace/trace-ir/stream-internal.h index a22bad25..a95f90c0 100644 --- a/include/babeltrace/trace-ir/stream-internal.h +++ b/include/babeltrace/trace-ir/stream-internal.h @@ -38,7 +38,7 @@ struct bt_stream; struct bt_stream { struct bt_object base; - /* Weak: parent is this class's trace */ + /* Owned by this */ struct bt_stream_class *class; struct { @@ -65,4 +65,11 @@ void _bt_stream_freeze(const struct bt_stream *stream); # define bt_stream_freeze(_stream) #endif +static inline +struct bt_trace *bt_stream_borrow_trace_inline(const struct bt_stream *stream) +{ + BT_ASSERT(stream); + return (void *) bt_object_borrow_parent(&stream->base); +} + #endif /* BABELTRACE_TRACE_IR_STREAM_INTERNAL_H */ diff --git a/include/babeltrace/trace-ir/stream.h b/include/babeltrace/trace-ir/stream.h index 4ef5c179..4e7899eb 100644 --- a/include/babeltrace/trace-ir/stream.h +++ b/include/babeltrace/trace-ir/stream.h @@ -34,13 +34,18 @@ extern "C" { #endif +struct bt_trace; struct bt_stream; struct bt_stream_class; -extern struct bt_stream *bt_stream_create(struct bt_stream_class *stream_class); +extern struct bt_stream *bt_stream_create(struct bt_stream_class *stream_class, + struct bt_trace *trace); extern struct bt_stream *bt_stream_create_with_id( - struct bt_stream_class *stream_class, uint64_t id); + struct bt_stream_class *stream_class, + struct bt_trace *trace, uint64_t id); + +extern struct bt_trace *bt_stream_borrow_trace(struct bt_stream *stream); extern struct bt_stream_class *bt_stream_borrow_class(struct bt_stream *stream); diff --git a/include/babeltrace/trace-ir/trace-class-const.h b/include/babeltrace/trace-ir/trace-class-const.h new file mode 100644 index 00000000..55a20d8e --- /dev/null +++ b/include/babeltrace/trace-ir/trace-class-const.h @@ -0,0 +1,83 @@ +#ifndef BABELTRACE_TRACE_IR_TRACE_CLASS_CONST_H +#define BABELTRACE_TRACE_IR_TRACE_CLASS_CONST_H + +/* + * Copyright 2014 Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +/* For bt_bool, bt_uuid */ +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_trace_class; +struct bt_stream_class; +struct bt_field_class; +struct bt_value; + +extern bt_bool bt_trace_class_assigns_automatic_stream_class_id( + const struct bt_trace_class *trace_class); + +extern const char *bt_trace_class_get_name( + const struct bt_trace_class *trace_class); + +extern bt_uuid bt_trace_class_get_uuid( + const struct bt_trace_class *trace_class); + +extern uint64_t bt_trace_class_get_environment_entry_count( + const struct bt_trace_class *trace_class); + +extern void bt_trace_class_borrow_environment_entry_by_index_const( + const struct bt_trace_class *trace_class, uint64_t index, + const char **name, const struct bt_value **value); + +extern const struct bt_value * +bt_trace_class_borrow_environment_entry_value_by_name_const( + const struct bt_trace_class *trace_class, const char *name); + +extern const struct bt_field_class * +bt_trace_class_borrow_packet_header_field_class_const( + const struct bt_trace_class *trace_class); + +extern uint64_t bt_trace_class_get_stream_class_count( + const struct bt_trace_class *trace_class); + +extern const struct bt_stream_class * +bt_trace_class_borrow_stream_class_by_index_const( + const struct bt_trace_class *trace_class, uint64_t index); + +extern const struct bt_stream_class *bt_trace_class_borrow_stream_class_by_id_const( + const struct bt_trace_class *trace_class, uint64_t id); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_TRACE_IR_TRACE_CLASS_CONST_H */ diff --git a/include/babeltrace/trace-ir/trace-class-internal.h b/include/babeltrace/trace-ir/trace-class-internal.h new file mode 100644 index 00000000..46bf525f --- /dev/null +++ b/include/babeltrace/trace-ir/trace-class-internal.h @@ -0,0 +1,84 @@ +#ifndef BABELTRACE_TRACE_IR_TRACE_CLASS_INTERNAL_H +#define BABELTRACE_TRACE_IR_TRACE_CLASS_INTERNAL_H + +/* + * Copyright 2014 Jérémie Galarneau + * + * 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 +#include +#include +#include +#include + +struct bt_trace_class { + struct bt_object base; + + struct { + GString *str; + + /* NULL or `str->str` above */ + const char *value; + } name; + + struct { + uint8_t uuid[BABELTRACE_UUID_LEN]; + + /* NULL or `uuid` above */ + bt_uuid value; + } uuid; + + struct bt_value *environment; + + /* Array of `struct bt_stream_class *` */ + GPtrArray *stream_classes; + + struct bt_field_class *packet_header_fc; + bool assigns_automatic_stream_class_id; + + /* Pool of `struct bt_field_wrapper *` */ + struct bt_object_pool packet_header_field_pool; + + bool frozen; +}; + +BT_HIDDEN +void _bt_trace_class_freeze(const struct bt_trace_class *trace_class); + +#ifdef BT_DEV_MODE +# define bt_trace_class_freeze _bt_trace_class_freeze +#else +# define bt_trace_class_freeze(_tc) +#endif + +#endif /* BABELTRACE_TRACE_IR_TRACE_CLASS_INTERNAL_H */ diff --git a/include/babeltrace/trace-ir/trace-class.h b/include/babeltrace/trace-ir/trace-class.h new file mode 100644 index 00000000..d7e93a62 --- /dev/null +++ b/include/babeltrace/trace-ir/trace-class.h @@ -0,0 +1,77 @@ +#ifndef BABELTRACE_TRACE_IR_TRACE_CLASS_H +#define BABELTRACE_TRACE_IR_TRACE_CLASS_H + +/* + * Copyright 2014 Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +/* For bt_bool, bt_uuid */ +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_trace_class; +struct bt_stream_class; +struct bt_field_class; + +extern struct bt_trace_class *bt_trace_class_create(void); + +extern void bt_trace_class_set_assigns_automatic_stream_class_id( + struct bt_trace_class *trace_class, bt_bool value); + +extern int bt_trace_class_set_name(struct bt_trace_class *trace_class, + const char *name); + +extern void bt_trace_class_set_uuid(struct bt_trace_class *trace_class, + bt_uuid uuid); + +extern int bt_trace_class_set_environment_entry_integer( + struct bt_trace_class *trace_class, + const char *name, int64_t value); + +extern int bt_trace_class_set_environment_entry_string( + struct bt_trace_class *trace_class, + const char *name, const char *value); + +extern int bt_trace_class_set_packet_header_field_class( + struct bt_trace_class *trace_class, + struct bt_field_class *packet_header_field_class); + +extern struct bt_stream_class *bt_trace_class_borrow_stream_class_by_index( + struct bt_trace_class *trace_class, uint64_t index); + +extern struct bt_stream_class *bt_trace_class_borrow_stream_class_by_id( + struct bt_trace_class *trace_class, uint64_t id); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_TRACE_IR_TRACE_CLASS_H */ diff --git a/include/babeltrace/trace-ir/trace-const.h b/include/babeltrace/trace-ir/trace-const.h index 4443056a..0a7919e0 100644 --- a/include/babeltrace/trace-ir/trace-const.h +++ b/include/babeltrace/trace-ir/trace-const.h @@ -49,37 +49,11 @@ typedef void (* bt_trace_is_static_listener_func)(const struct bt_trace *trace, typedef void (* bt_trace_listener_removed_func)(const struct bt_trace *trace, void *data); -extern bt_bool bt_trace_assigns_automatic_stream_class_id( +extern const struct bt_trace_class *bt_trace_borrow_class_const( const struct bt_trace *trace); extern const char *bt_trace_get_name(const struct bt_trace *trace); -extern bt_uuid bt_trace_get_uuid(const struct bt_trace *trace); - -extern uint64_t bt_trace_get_environment_entry_count( - const struct bt_trace *trace); - -extern void bt_trace_borrow_environment_entry_by_index_const( - const struct bt_trace *trace, uint64_t index, - const char **name, const struct bt_value **value); - -extern const struct bt_value * -bt_trace_borrow_environment_entry_value_by_name_const( - const struct bt_trace *trace, const char *name); - -extern const struct bt_field_class * -bt_trace_borrow_packet_header_field_class_const( - const struct bt_trace *trace); - -extern uint64_t bt_trace_get_stream_class_count(const struct bt_trace *trace); - -extern const struct bt_stream_class * -bt_trace_borrow_stream_class_by_index_const(const struct bt_trace *trace, - uint64_t index); - -extern const struct bt_stream_class *bt_trace_borrow_stream_class_by_id_const( - const struct bt_trace *trace, uint64_t id); - extern uint64_t bt_trace_get_stream_count(const struct bt_trace *trace); extern const struct bt_stream *bt_trace_borrow_stream_by_index_const( diff --git a/include/babeltrace/trace-ir/trace-internal.h b/include/babeltrace/trace-ir/trace-internal.h index fcf1bd29..3b6eb1c7 100644 --- a/include/babeltrace/trace-ir/trace-internal.h +++ b/include/babeltrace/trace-ir/trace-internal.h @@ -26,6 +26,7 @@ */ #include +#include #include #include #include @@ -44,6 +45,9 @@ struct bt_trace { struct bt_object base; + /* Owned by this */ + struct bt_trace_class *class; + struct { GString *str; @@ -51,37 +55,20 @@ struct bt_trace { const char *value; } name; - struct { - uint8_t uuid[BABELTRACE_UUID_LEN]; - - /* NULL or `uuid` above */ - bt_uuid value; - } uuid; - - struct bt_value *environment; - - /* Array of `struct bt_stream_class *` */ - GPtrArray *stream_classes; - /* Array of `struct bt_stream *` */ GPtrArray *streams; /* - * Stream class (weak) to number of instantiated streams, used - * to automatically assign stream IDs per stream class. + * Stream class (weak, owned by owned trace class) to number of + * instantiated streams, used to automatically assign stream IDs + * per stream class within this trace. */ GHashTable *stream_classes_stream_count; struct bt_field_class *packet_header_fc; - bool assigns_automatic_stream_class_id; - GArray *is_static_listeners; bool is_static; bool in_remove_listener; - - /* Pool of `struct bt_field_wrapper *` */ - struct bt_object_pool packet_header_field_pool; - bool frozen; }; diff --git a/include/babeltrace/trace-ir/trace.h b/include/babeltrace/trace-ir/trace.h index 370a89b3..da493f38 100644 --- a/include/babeltrace/trace-ir/trace.h +++ b/include/babeltrace/trace-ir/trace.h @@ -28,7 +28,7 @@ * http://www.efficios.com/ctf */ -/* For bt_bool, bt_uuid */ +/* For bt_bool */ #include #include @@ -38,37 +38,15 @@ extern "C" { #endif struct bt_trace; +struct bt_trace_class; struct bt_stream; -struct bt_stream_class; -struct bt_field_class; -struct bt_value; -struct bt_packet_header_field; -extern struct bt_trace *bt_trace_create(void); +extern struct bt_trace_class *bt_trace_borrow_class(struct bt_trace *trace); -extern void bt_trace_set_assigns_automatic_stream_class_id( - struct bt_trace *trace, bt_bool value); +extern struct bt_trace *bt_trace_create(struct bt_trace_class *trace_class); extern int bt_trace_set_name(struct bt_trace *trace, const char *name); -extern void bt_trace_set_uuid(struct bt_trace *trace, bt_uuid uuid); - -extern int bt_trace_set_environment_entry_integer(struct bt_trace *trace, - const char *name, int64_t value); - -extern int bt_trace_set_environment_entry_string(struct bt_trace *trace, - const char *name, const char *value); - -extern int bt_trace_set_packet_header_field_class( - struct bt_trace *trace, - struct bt_field_class *packet_header_field_class); - -extern struct bt_stream_class *bt_trace_borrow_stream_class_by_index( - struct bt_trace *trace, uint64_t index); - -extern struct bt_stream_class *bt_trace_borrow_stream_class_by_id( - struct bt_trace *trace, uint64_t id); - extern struct bt_stream *bt_trace_borrow_stream_by_index(struct bt_trace *trace, uint64_t index); diff --git a/lib/graph/notification/event.c b/lib/graph/notification/event.c index 303a6520..d466852c 100644 --- a/lib/graph/notification/event.c +++ b/lib/graph/notification/event.c @@ -50,7 +50,7 @@ static inline bool event_class_has_trace(struct bt_event_class *event_class) stream_class = bt_event_class_borrow_stream_class(event_class); BT_ASSERT(stream_class); - return bt_stream_class_borrow_trace(stream_class) != NULL; + return bt_stream_class_borrow_trace_class(stream_class) != NULL; } BT_HIDDEN diff --git a/lib/lib-logging.c b/lib/lib-logging.c index b595263c..a72cdd98 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -38,11 +38,15 @@ #include #include #include +#include #include +#include #include #include #include +#include #include +#include #include #include #include @@ -99,22 +103,22 @@ static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE]; } while (0) static inline void format_component(char **buf_ch, bool extended, - const char *prefix, struct bt_component *component); + const char *prefix, const struct bt_component *component); static inline void format_port(char **buf_ch, bool extended, - const char *prefix, struct bt_port *port); + const char *prefix, const struct bt_port *port); static inline void format_connection(char **buf_ch, bool extended, - const char *prefix, struct bt_connection *connection); + const char *prefix, const struct bt_connection *connection); static inline void format_clock_value(char **buf_ch, bool extended, - const char *prefix, struct bt_clock_value *clock_value); + const char *prefix, const struct bt_clock_value *clock_value); static inline void format_field_path(char **buf_ch, bool extended, - const char *prefix, struct bt_field_path *field_path); + const char *prefix, const struct bt_field_path *field_path); static inline void format_object(char **buf_ch, bool extended, - const char *prefix, struct bt_object *obj) + const char *prefix, const struct bt_object *obj) { BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count); } @@ -141,7 +145,7 @@ static inline void format_uuid(char **buf_ch, bt_uuid uuid) } static inline void format_object_pool(char **buf_ch, bool extended, - const char *prefix, struct bt_object_pool *pool) + const char *prefix, const struct bt_object_pool *pool) { BUF_APPEND(", %ssize=%zu", PRFIELD(pool->size)); @@ -152,9 +156,10 @@ static inline void format_object_pool(char **buf_ch, bool extended, static inline void format_integer_field_class(char **buf_ch, bool extended, const char *prefix, - struct bt_field_class *field_class) + const struct bt_field_class *field_class) { - struct bt_field_class_integer *int_fc = (void *) field_class; + const struct bt_field_class_integer *int_fc = + (const void *) field_class; BUF_APPEND(", %srange-size=%" PRIu64 ", %sbase=%s", PRFIELD(int_fc->range), @@ -163,9 +168,10 @@ static inline void format_integer_field_class(char **buf_ch, static inline void format_array_field_class(char **buf_ch, bool extended, const char *prefix, - struct bt_field_class *field_class) + const struct bt_field_class *field_class) { - struct bt_field_class_array *array_fc = (void *) field_class; + const struct bt_field_class_array *array_fc = + (const void *) field_class; BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s", PRFIELD(array_fc->element_fc), @@ -173,7 +179,7 @@ static inline void format_array_field_class(char **buf_ch, } static inline void format_field_class(char **buf_ch, bool extended, - const char *prefix, struct bt_field_class *field_class) + const char *prefix, const struct bt_field_class *field_class) { char tmp_prefix[64]; @@ -182,8 +188,8 @@ static inline void format_field_class(char **buf_ch, bool extended, if (extended) { BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class->frozen)); - BUF_APPEND(", %sis-part-of-trace=%d", - PRFIELD(field_class->part_of_trace)); + BUF_APPEND(", %sis-part-of-trace-class=%d", + PRFIELD(field_class->part_of_trace_class)); } else { return; } @@ -197,7 +203,7 @@ static inline void format_field_class(char **buf_ch, bool extended, } case BT_FIELD_CLASS_TYPE_REAL: { - struct bt_field_class_real *real_fc = (void *) field_class; + const struct bt_field_class_real *real_fc = (void *) field_class; BUF_APPEND(", %sis-single-precision=%d", PRFIELD(real_fc->is_single_precision)); @@ -206,8 +212,8 @@ static inline void format_field_class(char **buf_ch, bool extended, case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: { - struct bt_field_class_enumeration *enum_fc = - (void *) field_class; + const struct bt_field_class_enumeration *enum_fc = + (const void *) field_class; format_integer_field_class(buf_ch, extended, prefix, field_class); BUF_APPEND(", %smapping-count=%u", @@ -216,8 +222,8 @@ static inline void format_field_class(char **buf_ch, bool extended, } case BT_FIELD_CLASS_TYPE_STRUCTURE: { - struct bt_field_class_structure *struct_fc = - (void *) field_class; + const struct bt_field_class_structure *struct_fc = + (const void *) field_class; if (struct_fc->common.named_fcs) { BUF_APPEND(", %smember-count=%u", @@ -228,8 +234,8 @@ static inline void format_field_class(char **buf_ch, bool extended, } case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: { - struct bt_field_class_static_array *array_fc = - (void *) field_class; + const struct bt_field_class_static_array *array_fc = + (const void *) field_class; format_array_field_class(buf_ch, extended, prefix, field_class); BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_fc->length)); @@ -237,8 +243,8 @@ static inline void format_field_class(char **buf_ch, bool extended, } case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: { - struct bt_field_class_dynamic_array *array_fc = - (void *) field_class; + const struct bt_field_class_dynamic_array *array_fc = + (const void *) field_class; format_array_field_class(buf_ch, extended, prefix, field_class); @@ -258,7 +264,8 @@ static inline void format_field_class(char **buf_ch, bool extended, } case BT_FIELD_CLASS_TYPE_VARIANT: { - struct bt_field_class_variant *var_fc = (void *) field_class; + const struct bt_field_class_variant *var_fc = + (const void *) field_class; if (var_fc->common.named_fcs) { BUF_APPEND(", %soption-count=%u", @@ -285,10 +292,11 @@ static inline void format_field_class(char **buf_ch, bool extended, } static inline void format_field_integer_extended(char **buf_ch, - const char *prefix, struct bt_field *field) + const char *prefix, const struct bt_field *field) { - struct bt_field_integer *integer = (void *) field; - struct bt_field_class_integer *field_class = (void *) field->class; + const struct bt_field_integer *integer = (void *) field; + const struct bt_field_class_integer *field_class = + (void *) field->class; const char *fmt = NULL; BT_ASSERT(field_class); @@ -316,7 +324,7 @@ static inline void format_field_integer_extended(char **buf_ch, } static inline void format_field(char **buf_ch, bool extended, - const char *prefix, struct bt_field *field) + const char *prefix, const struct bt_field *field) { BUF_APPEND(", %sis-set=%d", PRFIELD(field->is_set)); @@ -348,14 +356,14 @@ static inline void format_field(char **buf_ch, bool extended, } case BT_FIELD_CLASS_TYPE_REAL: { - struct bt_field_real *real_field = (void *) field; + const struct bt_field_real *real_field = (const void *) field; BUF_APPEND(", %svalue=%f", PRFIELD(real_field->value)); break; } case BT_FIELD_CLASS_TYPE_STRING: { - struct bt_field_string *str = (void *) field; + const struct bt_field_string *str = (const void *) field; if (str->buf) { BT_ASSERT(str->buf->data); @@ -368,7 +376,7 @@ static inline void format_field(char **buf_ch, bool extended, case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: { - struct bt_field_array *array_field = (void *) field; + const struct bt_field_array *array_field = (const void *) field; BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_field->length)); @@ -381,7 +389,7 @@ static inline void format_field(char **buf_ch, bool extended, } case BT_FIELD_CLASS_TYPE_VARIANT: { - struct bt_field_variant *var_field = (void *) field; + const struct bt_field_variant *var_field = (const void *) field; BUF_APPEND(", %sselected-field-index=%" PRIu64, PRFIELD(var_field->selected_index)); @@ -393,7 +401,7 @@ static inline void format_field(char **buf_ch, bool extended, } static inline void format_field_path(char **buf_ch, bool extended, - const char *prefix, struct bt_field_path *field_path) + const char *prefix, const struct bt_field_path *field_path) { uint64_t i; @@ -420,49 +428,76 @@ static inline void format_field_path(char **buf_ch, bool extended, BUF_APPEND("%s", "]"); } -static inline void format_trace(char **buf_ch, bool extended, - const char *prefix, struct bt_trace *trace) +static inline void format_trace_class(char **buf_ch, bool extended, + const char *prefix, const struct bt_trace_class *trace_class) { char tmp_prefix[64]; - if (trace->name.value) { - BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value)); + if (trace_class->name.value) { + BUF_APPEND(", %sname=\"%s\"", + PRFIELD(trace_class->name.value)); } if (!extended) { return; } - BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen)); + BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class->frozen)); - if (trace->uuid.value) { - BUF_APPEND_UUID(trace->uuid.value); + if (trace_class->uuid.value) { + BUF_APPEND_UUID(trace_class->uuid.value); } - if (trace->stream_classes) { + if (trace_class->stream_classes) { BUF_APPEND(", %sstream-class-count=%u", - PRFIELD(trace->stream_classes->len)); + PRFIELD(trace_class->stream_classes->len)); } + BUF_APPEND(", %spacket-header-fc-addr=%p, " + "%sassigns-auto-sc-id=%d", + PRFIELD(trace_class->packet_header_fc), + PRFIELD(trace_class->assigns_automatic_stream_class_id)); + SET_TMP_PREFIX("phf-pool-"); + format_object_pool(buf_ch, extended, prefix, + &trace_class->packet_header_field_pool); +} + +static inline void format_trace(char **buf_ch, bool extended, + const char *prefix, const struct bt_trace *trace) +{ + char tmp_prefix[64]; + + if (trace->name.value) { + BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value)); + } + + if (!extended) { + return; + } + + BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen)); + if (trace->streams) { BUF_APPEND(", %sstream-count=%u", PRFIELD(trace->streams->len)); } - BUF_APPEND(", %spacket-header-fc-addr=%p, %sis-static=%d, " - "%sassigns-auto-sc-id=%d", - PRFIELD(trace->packet_header_fc), - PRFIELD(trace->is_static), - PRFIELD(trace->assigns_automatic_stream_class_id)); - SET_TMP_PREFIX("phf-pool-"); - format_object_pool(buf_ch, extended, prefix, - &trace->packet_header_field_pool); + BUF_APPEND(", %sis-static=%d", PRFIELD(trace->is_static)); + + if (!trace->class) { + return; + } + + BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace->class)); + SET_TMP_PREFIX("trace-class-"); + format_trace_class(buf_ch, false, tmp_prefix, trace->class); } static inline void format_stream_class(char **buf_ch, bool extended, - const char *prefix, struct bt_stream_class *stream_class) + const char *prefix, + const struct bt_stream_class *stream_class) { - struct bt_trace *trace; + const struct bt_trace_class *trace_class; char tmp_prefix[64]; BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id)); @@ -488,8 +523,8 @@ static inline void format_stream_class(char **buf_ch, bool extended, PRFIELD(stream_class->packet_context_fc), PRFIELD(stream_class->event_header_fc), PRFIELD(stream_class->event_common_context_fc)); - trace = bt_stream_class_borrow_trace_inline(stream_class); - if (!trace) { + trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); + if (!trace_class) { return; } @@ -504,9 +539,9 @@ static inline void format_stream_class(char **buf_ch, bool extended, PRFIELD(stream_class->packets_have_packet_counter_snapshot), PRFIELD(stream_class->packets_have_default_beginning_cv), PRFIELD(stream_class->packets_have_default_end_cv)); - BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); - SET_TMP_PREFIX("trace-"); - format_trace(buf_ch, false, tmp_prefix, trace); + BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); + SET_TMP_PREFIX("trace-class-"); + format_trace_class(buf_ch, false, tmp_prefix, trace_class); SET_TMP_PREFIX("ehf-pool-"); format_object_pool(buf_ch, extended, prefix, &stream_class->event_header_field_pool); @@ -516,10 +551,10 @@ static inline void format_stream_class(char **buf_ch, bool extended, } static inline void format_event_class(char **buf_ch, bool extended, - const char *prefix, struct bt_event_class *event_class) + const char *prefix, const struct bt_event_class *event_class) { - struct bt_stream_class *stream_class; - struct bt_trace *trace; + const struct bt_stream_class *stream_class; + const struct bt_trace_class *trace_class; char tmp_prefix[64]; BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id)); @@ -550,7 +585,7 @@ static inline void format_event_class(char **buf_ch, bool extended, PRFIELD(event_class->specific_context_fc), PRFIELD(event_class->payload_fc)); - stream_class = bt_event_class_borrow_stream_class(event_class); + stream_class = bt_event_class_borrow_stream_class_const(event_class); if (!stream_class) { return; } @@ -558,23 +593,24 @@ static inline void format_event_class(char **buf_ch, bool extended, BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); SET_TMP_PREFIX("stream-class-"); format_stream_class(buf_ch, false, tmp_prefix, stream_class); - trace = bt_stream_class_borrow_trace_inline(stream_class); - if (!trace) { + trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); + if (!trace_class) { return; } - BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); - SET_TMP_PREFIX("trace-"); - format_trace(buf_ch, false, tmp_prefix, trace); + BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); + SET_TMP_PREFIX("trace-class-"); + format_trace_class(buf_ch, false, tmp_prefix, trace_class); SET_TMP_PREFIX("event-pool-"); format_object_pool(buf_ch, extended, prefix, &event_class->event_pool); } static inline void format_stream(char **buf_ch, bool extended, - const char *prefix, struct bt_stream *stream) + const char *prefix, const struct bt_stream *stream) { - struct bt_stream_class *stream_class; - struct bt_trace *trace; + const struct bt_stream_class *stream_class; + const struct bt_trace_class *trace_class = NULL; + const struct bt_trace *trace = NULL; char tmp_prefix[64]; BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream->id)); @@ -587,31 +623,36 @@ static inline void format_stream(char **buf_ch, bool extended, return; } - stream_class = bt_stream_borrow_class(stream); - if (!stream_class) { - return; + stream_class = bt_stream_borrow_class_const(stream); + if (stream_class) { + BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); + SET_TMP_PREFIX("stream-class-"); + format_stream_class(buf_ch, false, tmp_prefix, stream_class); + trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); } - BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); - SET_TMP_PREFIX("stream-class-"); - format_stream_class(buf_ch, false, tmp_prefix, stream_class); - trace = bt_stream_class_borrow_trace_inline(stream_class); - if (!trace) { - return; + if (trace_class) { + BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); + SET_TMP_PREFIX("trace-class-"); + format_trace_class(buf_ch, false, tmp_prefix, trace_class); + } + + trace = bt_stream_borrow_trace_inline(stream); + if (trace) { + BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); + SET_TMP_PREFIX("trace-"); + format_trace(buf_ch, false, tmp_prefix, trace); } - BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); - SET_TMP_PREFIX("trace-"); - format_trace(buf_ch, false, tmp_prefix, trace); SET_TMP_PREFIX("packet-pool-"); format_object_pool(buf_ch, extended, prefix, &stream->packet_pool); } static inline void format_packet(char **buf_ch, bool extended, - const char *prefix, struct bt_packet *packet) + const char *prefix, const struct bt_packet *packet) { - struct bt_stream *stream; - struct bt_trace *trace; + const struct bt_stream *stream; + const struct bt_trace_class *trace_class; char tmp_prefix[64]; if (!extended) { @@ -623,7 +664,7 @@ static inline void format_packet(char **buf_ch, bool extended, PRFIELD(packet->frozen), PRFIELD(packet->header_field ? packet->header_field->field : NULL), PRFIELD(packet->context_field ? packet->context_field->field : NULL)); - stream = bt_packet_borrow_stream(packet); + stream = bt_packet_borrow_stream_const(packet); if (!stream) { return; } @@ -653,23 +694,23 @@ static inline void format_packet(char **buf_ch, bool extended, BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream)); SET_TMP_PREFIX("stream-"); format_stream(buf_ch, false, tmp_prefix, stream); - trace = (struct bt_trace *) bt_object_borrow_parent(&stream->base); - if (!trace) { + trace_class = (const struct bt_trace_class *) bt_object_borrow_parent(&stream->base); + if (!trace_class) { return; } - BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); - SET_TMP_PREFIX("trace-"); - format_trace(buf_ch, false, tmp_prefix, trace); + BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); + SET_TMP_PREFIX("trace-class-"); + format_trace_class(buf_ch, false, tmp_prefix, trace_class); } static inline void format_event(char **buf_ch, bool extended, - const char *prefix, struct bt_event *event) + const char *prefix, const struct bt_event *event) { - struct bt_packet *packet; - struct bt_stream *stream; - struct bt_trace *trace; - struct bt_stream_class *stream_class; + const struct bt_packet *packet; + const struct bt_stream *stream; + const struct bt_trace_class *trace_class; + const struct bt_stream_class *stream_class; char tmp_prefix[64]; if (!extended) { @@ -701,11 +742,14 @@ static inline void format_event(char **buf_ch, bool extended, format_stream_class(buf_ch, false, tmp_prefix, stream_class); - trace = bt_stream_class_borrow_trace_inline(stream_class); - if (trace) { - BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); - SET_TMP_PREFIX("trace-"); - format_trace(buf_ch, false, tmp_prefix, trace); + trace_class = bt_stream_class_borrow_trace_class_inline( + stream_class); + if (trace_class) { + BUF_APPEND(", %strace-class-addr=%p", + PRFIELD(trace_class)); + SET_TMP_PREFIX("trace-class-"); + format_trace_class(buf_ch, false, tmp_prefix, + trace_class); } } @@ -715,7 +759,7 @@ static inline void format_event(char **buf_ch, bool extended, event->default_cv); } - packet = bt_event_borrow_packet(event); + packet = bt_event_borrow_packet_const(event); if (!packet) { return; } @@ -723,7 +767,7 @@ static inline void format_event(char **buf_ch, bool extended, BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet)); SET_TMP_PREFIX("packet-"); format_packet(buf_ch, false, tmp_prefix, packet); - stream = bt_packet_borrow_stream(packet); + stream = bt_packet_borrow_stream_const(packet); if (!stream) { return; } @@ -734,7 +778,7 @@ static inline void format_event(char **buf_ch, bool extended, } static inline void format_clock_class(char **buf_ch, bool extended, - const char *prefix, struct bt_clock_class *clock_class) + const char *prefix, const struct bt_clock_class *clock_class) { char tmp_prefix[64]; @@ -772,7 +816,7 @@ static inline void format_clock_class(char **buf_ch, bool extended, } static inline void format_clock_value(char **buf_ch, bool extended, - const char *prefix, struct bt_clock_value *clock_value) + const char *prefix, const struct bt_clock_value *clock_value) { char tmp_prefix[64]; BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-origin=%" PRId64, @@ -795,7 +839,7 @@ static inline void format_clock_value(char **buf_ch, bool extended, } static inline void format_value(char **buf_ch, bool extended, - const char *prefix, struct bt_value *value) + const char *prefix, const struct bt_value *value) { BUF_APPEND(", %stype=%s", PRFIELD(bt_common_value_type_string(bt_value_get_type(value)))); @@ -855,7 +899,7 @@ static inline void format_value(char **buf_ch, bool extended, } static inline void format_notification(char **buf_ch, bool extended, - const char *prefix, struct bt_notification *notif) + const char *prefix, const struct bt_notification *notif) { char tmp_prefix[64]; @@ -872,7 +916,8 @@ static inline void format_notification(char **buf_ch, bool extended, switch (notif->type) { case BT_NOTIFICATION_TYPE_EVENT: { - struct bt_notification_event *notif_event = (void *) notif; + const struct bt_notification_event *notif_event = + (const void *) notif; if (notif_event->event) { SET_TMP_PREFIX("event-"); @@ -883,8 +928,8 @@ static inline void format_notification(char **buf_ch, bool extended, } case BT_NOTIFICATION_TYPE_STREAM_BEGIN: { - struct bt_notification_stream_begin *notif_stream = - (void *) notif; + const struct bt_notification_stream_begin *notif_stream = + (const void *) notif; if (notif_stream->stream) { SET_TMP_PREFIX("stream-"); @@ -895,8 +940,8 @@ static inline void format_notification(char **buf_ch, bool extended, } case BT_NOTIFICATION_TYPE_STREAM_END: { - struct bt_notification_stream_end *notif_stream = - (void *) notif; + const struct bt_notification_stream_end *notif_stream = + (const void *) notif; if (notif_stream->stream) { SET_TMP_PREFIX("stream-"); @@ -907,8 +952,8 @@ static inline void format_notification(char **buf_ch, bool extended, } case BT_NOTIFICATION_TYPE_PACKET_BEGIN: { - struct bt_notification_packet_begin *notif_packet = - (void *) notif; + const struct bt_notification_packet_begin *notif_packet = + (const void *) notif; if (notif_packet->packet) { SET_TMP_PREFIX("packet-"); @@ -919,8 +964,8 @@ static inline void format_notification(char **buf_ch, bool extended, } case BT_NOTIFICATION_TYPE_PACKET_END: { - struct bt_notification_packet_end *notif_packet = - (void *) notif; + const struct bt_notification_packet_end *notif_packet = + (const void *) notif; if (notif_packet->packet) { SET_TMP_PREFIX("packet-"); @@ -936,7 +981,7 @@ static inline void format_notification(char **buf_ch, bool extended, static inline void format_plugin_so_shared_lib_handle(char **buf_ch, const char *prefix, - struct bt_plugin_so_shared_lib_handle *handle) + const struct bt_plugin_so_shared_lib_handle *handle) { BUF_APPEND(", %saddr=%p", PRFIELD(handle)); @@ -946,7 +991,8 @@ static inline void format_plugin_so_shared_lib_handle(char **buf_ch, } static inline void format_component_class(char **buf_ch, bool extended, - const char *prefix, struct bt_component_class *comp_class) + const char *prefix, + const struct bt_component_class *comp_class) { char tmp_prefix[64]; @@ -973,7 +1019,7 @@ static inline void format_component_class(char **buf_ch, bool extended, } static inline void format_component(char **buf_ch, bool extended, - const char *prefix, struct bt_component *component) + const char *prefix, const struct bt_component *component) { char tmp_prefix[64]; @@ -1002,7 +1048,7 @@ static inline void format_component(char **buf_ch, bool extended, } static inline void format_port(char **buf_ch, bool extended, - const char *prefix, struct bt_port *port) + const char *prefix, const struct bt_port *port) { char tmp_prefix[64]; @@ -1021,7 +1067,7 @@ static inline void format_port(char **buf_ch, bool extended, } static inline void format_connection(char **buf_ch, bool extended, - const char *prefix, struct bt_connection *connection) + const char *prefix, const struct bt_connection *connection) { char tmp_prefix[64]; @@ -1043,7 +1089,7 @@ static inline void format_connection(char **buf_ch, bool extended, } static inline void format_graph(char **buf_ch, bool extended, - const char *prefix, struct bt_graph *graph) + const char *prefix, const struct bt_graph *graph) { char tmp_prefix[64]; @@ -1076,7 +1122,7 @@ static inline void format_graph(char **buf_ch, bool extended, static inline void format_notification_iterator(char **buf_ch, bool extended, const char *prefix, - struct bt_notification_iterator *iterator) + const struct bt_notification_iterator *iterator) { const char *type; char tmp_prefix[64]; @@ -1094,8 +1140,8 @@ static inline void format_notification_iterator(char **buf_ch, switch (iterator->type) { case BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT: { - struct bt_self_component_port_input_notification_iterator * - port_in_iter = (void *) iterator; + const struct bt_self_component_port_input_notification_iterator * + port_in_iter = (const void *) iterator; if (port_in_iter->upstream_component) { SET_TMP_PREFIX("upstream-comp-"); @@ -1118,8 +1164,8 @@ static inline void format_notification_iterator(char **buf_ch, } case BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT: { - struct bt_port_output_notification_iterator *port_out_iter = - (void *) iterator; + const struct bt_port_output_notification_iterator *port_out_iter = + (const void *) iterator; if (port_out_iter->graph) { SET_TMP_PREFIX("graph-"); @@ -1187,8 +1233,8 @@ static inline void format_plugin(char **buf_ch, bool extended, PRFIELD(plugin->sink_comp_classes->len)); if (plugin->spec_data) { - struct bt_plugin_so_spec_data *spec_data = - (void *) plugin->spec_data; + const struct bt_plugin_so_spec_data *spec_data = + (const void *) plugin->spec_data; if (spec_data->shared_lib_handle) { SET_TMP_PREFIX("so-handle-"); @@ -1206,7 +1252,7 @@ static inline void handle_conversion_specifier_bt(void *priv_data, bool extended = false; char prefix[64]; char *prefix_ch = prefix; - void *obj; + const void *obj; /* skip "%!" */ fmt_ch += 2; @@ -1277,6 +1323,9 @@ static inline void handle_conversion_specifier_bt(void *priv_data, case 't': format_trace(buf_ch, extended, prefix, obj); break; + case 'T': + format_trace_class(buf_ch, extended, prefix, obj); + break; case 'K': format_clock_class(buf_ch, extended, prefix, obj); break; diff --git a/lib/trace-ir/Makefile.am b/lib/trace-ir/Makefile.am index bf54eae4..5ddcb37a 100644 --- a/lib/trace-ir/Makefile.am +++ b/lib/trace-ir/Makefile.am @@ -18,6 +18,7 @@ libtrace_ir_la_SOURCES = \ stream.c \ stream-class.c \ trace.c \ + trace-class.c \ utils.c libtrace_ir_la_LIBADD = $(UUID_LIBS) diff --git a/lib/trace-ir/event-class.c b/lib/trace-ir/event-class.c index 6841c1ab..971d8115 100644 --- a/lib/trace-ir/event-class.c +++ b/lib/trace-ir/event-class.c @@ -281,7 +281,7 @@ int bt_event_class_set_specific_context_field_class( { int ret; struct bt_stream_class *stream_class; - struct bt_trace *trace; + struct bt_trace_class *trace_class; struct bt_resolve_field_path_context resolve_ctx = { .packet_header = NULL, .packet_context = NULL, @@ -300,8 +300,8 @@ int bt_event_class_set_specific_context_field_class( "%!+F", field_class); stream_class = bt_event_class_borrow_stream_class_inline( event_class); - trace = bt_stream_class_borrow_trace_inline(stream_class); - resolve_ctx.packet_header = trace->packet_header_fc; + trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); + resolve_ctx.packet_header = trace_class->packet_header_fc; resolve_ctx.packet_context = stream_class->packet_context_fc; resolve_ctx.event_header = stream_class->event_header_fc; resolve_ctx.event_common_context = @@ -312,7 +312,7 @@ int bt_event_class_set_specific_context_field_class( goto end; } - bt_field_class_make_part_of_trace(field_class); + bt_field_class_make_part_of_trace_class(field_class); bt_object_put_ref(event_class->specific_context_fc); event_class->specific_context_fc = field_class; bt_object_get_no_null_check(event_class->specific_context_fc); @@ -337,7 +337,7 @@ int bt_event_class_set_payload_field_class( { int ret; struct bt_stream_class *stream_class; - struct bt_trace *trace; + struct bt_trace_class *trace_class; struct bt_resolve_field_path_context resolve_ctx = { .packet_header = NULL, .packet_context = NULL, @@ -356,8 +356,8 @@ int bt_event_class_set_payload_field_class( field_class); stream_class = bt_event_class_borrow_stream_class_inline( event_class); - trace = bt_stream_class_borrow_trace_inline(stream_class); - resolve_ctx.packet_header = trace->packet_header_fc; + trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); + resolve_ctx.packet_header = trace_class->packet_header_fc; resolve_ctx.packet_context = stream_class->packet_context_fc; resolve_ctx.event_header = stream_class->event_header_fc; resolve_ctx.event_common_context = @@ -369,7 +369,7 @@ int bt_event_class_set_payload_field_class( goto end; } - bt_field_class_make_part_of_trace(field_class); + bt_field_class_make_part_of_trace_class(field_class); bt_object_put_ref(event_class->payload_fc); event_class->payload_fc = field_class; bt_object_get_no_null_check(event_class->payload_fc); diff --git a/lib/trace-ir/event-header-field.c b/lib/trace-ir/event-header-field.c index 8a5f4693..b877180c 100644 --- a/lib/trace-ir/event-header-field.c +++ b/lib/trace-ir/event-header-field.c @@ -62,7 +62,7 @@ struct bt_event_header_field *bt_event_header_field_create( struct bt_field_wrapper *field_wrapper; BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); - BT_ASSERT_PRE(bt_stream_class_borrow_trace_inline(stream_class), + BT_ASSERT_PRE(bt_stream_class_borrow_trace_class_inline(stream_class), "Stream class is not part of a trace: %!+S", stream_class); BT_ASSERT_PRE(stream_class->event_header_fc, "Stream class has no event header field classe: %!+S", diff --git a/lib/trace-ir/field-classes.c b/lib/trace-ir/field-classes.c index a219ddc0..31f67b1d 100644 --- a/lib/trace-ir/field-classes.c +++ b/lib/trace-ir/field-classes.c @@ -1158,14 +1158,14 @@ void _bt_field_class_freeze(const struct bt_field_class *fc) } BT_HIDDEN -void _bt_field_class_make_part_of_trace(const struct bt_field_class *c_fc) +void _bt_field_class_make_part_of_trace_class(const struct bt_field_class *c_fc) { struct bt_field_class *fc = (void *) c_fc; BT_ASSERT(fc); - BT_ASSERT_PRE(!fc->part_of_trace, + BT_ASSERT_PRE(!fc->part_of_trace_class, "Field class is already part of a trace: %!+F", fc); - fc->part_of_trace = true; + fc->part_of_trace_class = true; switch (fc->type) { case BT_FIELD_CLASS_TYPE_STRUCTURE: @@ -1180,7 +1180,7 @@ void _bt_field_class_make_part_of_trace(const struct bt_field_class *c_fc) BT_FIELD_CLASS_NAMED_FC_AT_INDEX( container_fc, i); - bt_field_class_make_part_of_trace(named_fc->fc); + bt_field_class_make_part_of_trace_class(named_fc->fc); } break; @@ -1190,7 +1190,7 @@ void _bt_field_class_make_part_of_trace(const struct bt_field_class *c_fc) { struct bt_field_class_array *array_fc = (void *) fc; - bt_field_class_make_part_of_trace(array_fc->element_fc); + bt_field_class_make_part_of_trace_class(array_fc->element_fc); break; } default: diff --git a/lib/trace-ir/packet-context-field.c b/lib/trace-ir/packet-context-field.c index 393e49ad..9eff755e 100644 --- a/lib/trace-ir/packet-context-field.c +++ b/lib/trace-ir/packet-context-field.c @@ -63,7 +63,8 @@ struct bt_packet_context_field *bt_packet_context_field_create( BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); BT_ASSERT_PRE(stream_class->frozen, - "Stream class is not part of a trace: %!+S", stream_class); + "Stream class is not part of a trace class: %!+S", + stream_class); BT_ASSERT_PRE(stream_class->packet_context_fc, "Stream class has no packet context field classe: %!+S", stream_class); diff --git a/lib/trace-ir/packet-header-field.c b/lib/trace-ir/packet-header-field.c index 6359b882..3b7d89f5 100644 --- a/lib/trace-ir/packet-header-field.c +++ b/lib/trace-ir/packet-header-field.c @@ -57,24 +57,24 @@ void bt_packet_header_field_release( } struct bt_packet_header_field *bt_packet_header_field_create( - struct bt_trace *trace) + struct bt_trace_class *tc) { struct bt_field_wrapper *field_wrapper; - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE(trace->packet_header_fc, - "Trace has no packet header field classe: %!+t", trace); + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE(tc->packet_header_fc, + "Trace class has no packet header field class: %!+T", tc); field_wrapper = bt_field_wrapper_create( - &trace->packet_header_field_pool, - (void *) trace->packet_header_fc); + &tc->packet_header_field_pool, + (void *) tc->packet_header_fc); if (!field_wrapper) { - BT_LIB_LOGE("Cannot allocate one packet header field from trace: " - "%![trace-]+t", trace); + BT_LIB_LOGE("Cannot allocate one packet header field from trace class: " + "%![tc-]+T", tc); goto error; } BT_ASSERT(field_wrapper->field); - bt_trace_freeze(trace); + bt_trace_class_freeze(tc); goto end; error: diff --git a/lib/trace-ir/packet.c b/lib/trace-ir/packet.c index d71c62ed..dd1df856 100644 --- a/lib/trace-ir/packet.c +++ b/lib/trace-ir/packet.c @@ -144,13 +144,13 @@ void reset_packet(struct bt_packet *packet) static void recycle_header_field(struct bt_field_wrapper *header_field, - struct bt_trace *trace) + struct bt_trace_class *tc) { BT_ASSERT(header_field); BT_LIB_LOGD("Recycling packet header field: " - "addr=%p, %![trace-]+t, %![field-]+f", header_field, - trace, header_field->field); - bt_object_pool_recycle_object(&trace->packet_header_field_pool, + "addr=%p, %![tc-]+T, %![field-]+f", header_field, + tc, header_field->field); + bt_object_pool_recycle_object(&tc->packet_header_field_pool, header_field); } @@ -213,7 +213,7 @@ void bt_packet_destroy(struct bt_packet *packet) if (packet->stream) { BT_LOGD_STR("Recycling packet's header field."); recycle_header_field(packet->header_field, - bt_stream_class_borrow_trace_inline( + bt_stream_class_borrow_trace_class_inline( packet->stream->class)); } else { bt_field_wrapper_destroy(packet->header_field); @@ -255,7 +255,7 @@ BT_HIDDEN struct bt_packet *bt_packet_new(struct bt_stream *stream) { struct bt_packet *packet = NULL; - struct bt_trace *trace = NULL; + struct bt_trace_class *trace_class = NULL; BT_ASSERT(stream); BT_LIB_LOGD("Creating packet object: %![stream-]+s", stream); @@ -269,14 +269,14 @@ struct bt_packet *bt_packet_new(struct bt_stream *stream) (bt_object_release_func) bt_packet_recycle); packet->stream = stream; bt_object_get_no_null_check(stream); - trace = bt_stream_class_borrow_trace_inline(stream->class); - BT_ASSERT(trace); + trace_class = bt_stream_class_borrow_trace_class_inline(stream->class); + BT_ASSERT(trace_class); - if (trace->packet_header_fc) { + if (trace_class->packet_header_fc) { BT_LOGD_STR("Creating initial packet header field."); packet->header_field = bt_field_wrapper_create( - &trace->packet_header_field_pool, - trace->packet_header_fc); + &trace_class->packet_header_field_pool, + trace_class->packet_header_fc); if (!packet->header_field) { BT_LOGE_STR("Cannot create packet header field wrapper."); goto error; @@ -350,25 +350,24 @@ end: int bt_packet_move_header_field(struct bt_packet *packet, struct bt_packet_header_field *header_field) { - struct bt_trace *trace; + struct bt_trace_class *tc; struct bt_field_wrapper *field_wrapper = (void *) header_field; BT_ASSERT_PRE_NON_NULL(packet, "Packet"); BT_ASSERT_PRE_NON_NULL(field_wrapper, "Header field"); BT_ASSERT_PRE_PACKET_HOT(packet); - trace = bt_stream_class_borrow_trace_inline(packet->stream->class); - BT_ASSERT_PRE(trace->packet_header_fc, - "Trace has no packet header field classe: %!+t", - trace); + tc = bt_stream_class_borrow_trace_class_inline(packet->stream->class); + BT_ASSERT_PRE(tc->packet_header_fc, + "Trace class has no packet header field classe: %!+T", tc); BT_ASSERT_PRE(field_wrapper->field->class == - trace->packet_header_fc, + tc->packet_header_fc, "Unexpected packet header field's class: " "%![fc-]+F, %![expected-fc-]+F", field_wrapper->field->class, - trace->packet_header_fc); + tc->packet_header_fc); /* Recycle current header field: always exists */ BT_ASSERT(packet->header_field); - recycle_header_field(packet->header_field, trace); + recycle_header_field(packet->header_field, tc); /* Move new field */ packet->header_field = field_wrapper; diff --git a/lib/trace-ir/stream-class.c b/lib/trace-ir/stream-class.c index 3d8d9c37..4a47853f 100644 --- a/lib/trace-ir/stream-class.c +++ b/lib/trace-ir/stream-class.c @@ -90,14 +90,14 @@ void free_field_wrapper(struct bt_field_wrapper *field_wrapper, BT_ASSERT_PRE_FUNC static -bool stream_class_id_is_unique(const struct bt_trace *trace, uint64_t id) +bool stream_class_id_is_unique(const struct bt_trace_class *tc, uint64_t id) { uint64_t i; bool is_unique = true; - for (i = 0; i < trace->stream_classes->len; i++) { + for (i = 0; i < tc->stream_classes->len; i++) { const struct bt_stream_class *sc = - trace->stream_classes->pdata[i]; + tc->stream_classes->pdata[i]; if (sc->id == id) { is_unique = false; @@ -110,18 +110,17 @@ end: } static -struct bt_stream_class *create_stream_class_with_id(struct bt_trace *trace, - uint64_t id) +struct bt_stream_class *create_stream_class_with_id( + struct bt_trace_class *tc, uint64_t id) { struct bt_stream_class *stream_class = NULL; int ret; - BT_ASSERT(trace); - BT_ASSERT_PRE(stream_class_id_is_unique(trace, id), - "Duplicate stream class ID: %![trace-]+t, id=%" PRIu64, - trace, id); - BT_LIB_LOGD("Creating stream class object: %![trace-]+t, id=%" PRIu64, - trace, id); + BT_ASSERT(tc); + BT_ASSERT_PRE(stream_class_id_is_unique(tc, id), + "Duplicate stream class ID: %![tc-]+T, id=%" PRIu64, tc, id); + BT_LIB_LOGD("Creating stream class object: %![tc-]+T, id=%" PRIu64, + tc, id); stream_class = g_new0(struct bt_stream_class, 1); if (!stream_class) { BT_LOGE_STR("Failed to allocate one stream class."); @@ -168,9 +167,9 @@ struct bt_stream_class *create_stream_class_with_id(struct bt_trace *trace, goto error; } - bt_object_set_parent(&stream_class->base, &trace->base); - g_ptr_array_add(trace->stream_classes, stream_class); - bt_trace_freeze(trace); + bt_object_set_parent(&stream_class->base, &tc->base); + g_ptr_array_add(tc->stream_classes, stream_class); + bt_trace_class_freeze(tc); BT_LIB_LOGD("Created stream class object: %!+S", stream_class); goto end; @@ -181,37 +180,37 @@ end: return stream_class; } -struct bt_stream_class *bt_stream_class_create(struct bt_trace *trace) +struct bt_stream_class *bt_stream_class_create(struct bt_trace_class *tc) { - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE(trace->assigns_automatic_stream_class_id, - "Trace does not automatically assigns stream class IDs: " - "%![sc-]+t", trace); - return create_stream_class_with_id(trace, - (uint64_t) trace->stream_classes->len); + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE(tc->assigns_automatic_stream_class_id, + "Trace class does not automatically assigns stream class IDs: " + "%![sc-]+T", tc); + return create_stream_class_with_id(tc, + (uint64_t) tc->stream_classes->len); } struct bt_stream_class *bt_stream_class_create_with_id( - struct bt_trace *trace, uint64_t id) + struct bt_trace_class *tc, uint64_t id) { - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE(!trace->assigns_automatic_stream_class_id, - "Trace automatically assigns stream class IDs: " - "%![sc-]+t", trace); - return create_stream_class_with_id(trace, id); + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE(!tc->assigns_automatic_stream_class_id, + "Trace class automatically assigns stream class IDs: " + "%![sc-]+T", tc); + return create_stream_class_with_id(tc, id); } -struct bt_trace *bt_stream_class_borrow_trace( +struct bt_trace_class *bt_stream_class_borrow_trace_class( struct bt_stream_class *stream_class) { BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); - return bt_stream_class_borrow_trace_inline(stream_class); + return bt_stream_class_borrow_trace_class_inline(stream_class); } -const struct bt_trace *bt_stream_class_borrow_trace_const( +const struct bt_trace_class *bt_stream_class_borrow_trace_class_const( const struct bt_stream_class *stream_class) { - return bt_stream_class_borrow_trace((void *) stream_class); + return bt_stream_class_borrow_trace_class((void *) stream_class); } const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class) @@ -268,7 +267,7 @@ struct bt_event_class *bt_stream_class_borrow_event_class_by_id( struct bt_event_class *event_class = NULL; uint64_t i; - BT_ASSERT_PRE_NON_NULL(stream_class, "Trace"); + BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); for (i = 0; i < stream_class->event_classes->len; i++) { struct bt_event_class *event_class_candidate = @@ -322,13 +321,13 @@ int bt_stream_class_set_packet_context_field_class( "Packet context field classe is not a structure field classe: %!+F", field_class); resolve_ctx.packet_header = - bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; + bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc; ret = bt_resolve_field_paths(field_class, &resolve_ctx); if (ret) { goto end; } - bt_field_class_make_part_of_trace(field_class); + bt_field_class_make_part_of_trace_class(field_class); bt_object_put_ref(stream_class->packet_context_fc); stream_class->packet_context_fc = field_class; bt_object_get_no_null_check(stream_class->packet_context_fc); @@ -369,14 +368,14 @@ int bt_stream_class_set_event_header_field_class( "Event header field classe is not a structure field classe: %!+F", field_class); resolve_ctx.packet_header = - bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; + bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc; resolve_ctx.packet_context = stream_class->packet_context_fc; ret = bt_resolve_field_paths(field_class, &resolve_ctx); if (ret) { goto end; } - bt_field_class_make_part_of_trace(field_class); + bt_field_class_make_part_of_trace_class(field_class); bt_object_put_ref(stream_class->event_header_fc); stream_class->event_header_fc = field_class; bt_object_get_no_null_check(stream_class->event_header_fc); @@ -418,7 +417,7 @@ int bt_stream_class_set_event_common_context_field_class( "Event common context field classe is not a structure field classe: %!+F", field_class); resolve_ctx.packet_header = - bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; + bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc; resolve_ctx.packet_context = stream_class->packet_context_fc; resolve_ctx.event_header = stream_class->event_header_fc; ret = bt_resolve_field_paths(field_class, &resolve_ctx); @@ -426,7 +425,7 @@ int bt_stream_class_set_event_common_context_field_class( goto end; } - bt_field_class_make_part_of_trace(field_class); + bt_field_class_make_part_of_trace_class(field_class); bt_object_put_ref(stream_class->event_common_context_fc); stream_class->event_common_context_fc = field_class; bt_object_get_no_null_check(stream_class->event_common_context_fc); diff --git a/lib/trace-ir/stream.c b/lib/trace-ir/stream.c index c1352400..a75aef34 100644 --- a/lib/trace-ir/stream.c +++ b/lib/trace-ir/stream.c @@ -58,6 +58,8 @@ void destroy_stream(struct bt_object *obj) stream->name.value = NULL; } + BT_LOGD_STR("Putting stream's class."); + bt_object_put_ref(stream->class); bt_object_pool_finalize(&stream->packet_pool); g_free(stream); } @@ -95,14 +97,17 @@ end: static struct bt_stream *create_stream_with_id(struct bt_stream_class *stream_class, - uint64_t id) + struct bt_trace *trace, uint64_t id) { int ret; struct bt_stream *stream; - struct bt_trace *trace; BT_ASSERT(stream_class); - trace = bt_stream_class_borrow_trace_inline(stream_class); + BT_ASSERT(trace); + BT_ASSERT_PRE(trace->class == + bt_stream_class_borrow_trace_class_inline(stream_class), + "Trace's class is different from stream class's parent trace class: " + "%![sc-]+S, %![trace-]+t", stream_class, trace); BT_ASSERT_PRE(stream_id_is_unique(trace, stream_class, id), "Duplicate stream ID: %![trace-]+t, id=%" PRIu64, trace, id); BT_ASSERT_PRE(!trace->is_static, @@ -133,7 +138,11 @@ struct bt_stream *create_stream_with_id(struct bt_stream_class *stream_class, } stream->class = stream_class; + bt_object_get_no_null_check(stream_class); + + /* bt_trace_add_stream() sets the parent trace, and freezes the trace */ bt_trace_add_stream(trace, stream); + bt_stream_class_freeze(stream_class); BT_LIB_LOGD("Created stream object: %!+s", stream); goto end; @@ -145,27 +154,29 @@ end: return stream; } -struct bt_stream *bt_stream_create(struct bt_stream_class *stream_class) +struct bt_stream *bt_stream_create(struct bt_stream_class *stream_class, + struct bt_trace *trace) { uint64_t id; BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); + BT_ASSERT_PRE_NON_NULL(trace, "Trace"); BT_ASSERT_PRE(stream_class->assigns_automatic_stream_id, "Stream class does not automatically assigns stream IDs: " "%![sc-]+S", stream_class); - id = bt_trace_get_automatic_stream_id( - bt_stream_class_borrow_trace_inline(stream_class), - stream_class); - return create_stream_with_id(stream_class, id); + id = bt_trace_get_automatic_stream_id(trace, stream_class); + return create_stream_with_id(stream_class, trace, id); } struct bt_stream *bt_stream_create_with_id(struct bt_stream_class *stream_class, - uint64_t id) + struct bt_trace *trace, uint64_t id) { + BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); + BT_ASSERT_PRE_NON_NULL(trace, "Trace"); BT_ASSERT_PRE(!stream_class->assigns_automatic_stream_id, "Stream class automatically assigns stream IDs: " "%![sc-]+S", stream_class); - return create_stream_with_id(stream_class, id); + return create_stream_with_id(stream_class, trace, id); } struct bt_stream_class *bt_stream_borrow_class(struct bt_stream *stream) @@ -180,6 +191,18 @@ const struct bt_stream_class *bt_stream_borrow_class_const( return bt_stream_borrow_class((void *) stream); } +struct bt_trace *bt_stream_borrow_trace(struct bt_stream *stream) +{ + BT_ASSERT_PRE_NON_NULL(stream, "Stream"); + return bt_stream_borrow_trace_inline(stream); +} + +const struct bt_trace *bt_stream_borrow_trace_const( + const struct bt_stream *stream) +{ + return bt_stream_borrow_trace((void *) stream); +} + const char *bt_stream_get_name(const struct bt_stream *stream) { BT_ASSERT_PRE_NON_NULL(stream, "Stream class"); diff --git a/lib/trace-ir/trace-class.c b/lib/trace-ir/trace-class.c new file mode 100644 index 00000000..b8c99470 --- /dev/null +++ b/lib/trace-ir/trace-class.c @@ -0,0 +1,422 @@ +/* + * Copyright 2014 Jérémie Galarneau + * + * 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. + */ + +#define BT_LOG_TAG "TRACE" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BT_ASSERT_PRE_TRACE_CLASS_HOT(_tc) \ + BT_ASSERT_PRE_HOT((_tc), "Trace class", ": %!+T", (_tc)) + +static +void destroy_trace_class(struct bt_object *obj) +{ + struct bt_trace_class *tc = (void *) obj; + + BT_LIB_LOGD("Destroying trace class object: %!+T", tc); + bt_object_pool_finalize(&tc->packet_header_field_pool); + + if (tc->environment) { + BT_LOGD_STR("Destroying environment attributes."); + bt_attributes_destroy(tc->environment); + tc->environment = NULL; + } + + if (tc->name.str) { + g_string_free(tc->name.str, TRUE); + tc->name.str = NULL; + tc->name.value = NULL; + } + + if (tc->stream_classes) { + BT_LOGD_STR("Destroying stream classes."); + g_ptr_array_free(tc->stream_classes, TRUE); + tc->stream_classes = NULL; + } + + BT_LOGD_STR("Putting packet header field classe."); + bt_object_put_ref(tc->packet_header_fc); + tc->packet_header_fc = NULL; + g_free(tc); +} + +static +void free_packet_header_field(struct bt_field_wrapper *field_wrapper, + struct bt_trace_class *tc) +{ + bt_field_wrapper_destroy(field_wrapper); +} + +struct bt_trace_class *bt_trace_class_create(void) +{ + struct bt_trace_class *tc = NULL; + int ret; + + BT_LOGD_STR("Creating default trace class object."); + tc = g_new0(struct bt_trace_class, 1); + if (!tc) { + BT_LOGE_STR("Failed to allocate one trace class."); + goto error; + } + + bt_object_init_shared_with_parent(&tc->base, destroy_trace_class); + + tc->stream_classes = g_ptr_array_new_with_free_func( + (GDestroyNotify) bt_object_try_spec_release); + if (!tc->stream_classes) { + BT_LOGE_STR("Failed to allocate one GPtrArray."); + goto error; + } + + tc->name.str = g_string_new(NULL); + if (!tc->name.str) { + BT_LOGE_STR("Failed to allocate one GString."); + goto error; + } + + tc->environment = bt_attributes_create(); + if (!tc->environment) { + BT_LOGE_STR("Cannot create empty attributes object."); + goto error; + } + + tc->assigns_automatic_stream_class_id = true; + ret = bt_object_pool_initialize(&tc->packet_header_field_pool, + (bt_object_pool_new_object_func) bt_field_wrapper_new, + (bt_object_pool_destroy_object_func) free_packet_header_field, + tc); + if (ret) { + BT_LOGE("Failed to initialize packet header field pool: ret=%d", + ret); + goto error; + } + + BT_LIB_LOGD("Created trace class object: %!+T", tc); + goto end; + +error: + BT_OBJECT_PUT_REF_AND_RESET(tc); + +end: + return tc; +} + +const char *bt_trace_class_get_name(const struct bt_trace_class *tc) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + return tc->name.value; +} + +int bt_trace_class_set_name(struct bt_trace_class *tc, const char *name) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE_TRACE_CLASS_HOT(tc); + g_string_assign(tc->name.str, name); + tc->name.value = tc->name.str->str; + BT_LIB_LOGV("Set trace class's name: %!+T", tc); + return 0; +} + +bt_uuid bt_trace_class_get_uuid(const struct bt_trace_class *tc) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + return tc->uuid.value; +} + +void bt_trace_class_set_uuid(struct bt_trace_class *tc, bt_uuid uuid) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_NON_NULL(uuid, "UUID"); + BT_ASSERT_PRE_TRACE_CLASS_HOT(tc); + memcpy(tc->uuid.uuid, uuid, BABELTRACE_UUID_LEN); + tc->uuid.value = tc->uuid.uuid; + BT_LIB_LOGV("Set trace class's UUID: %!+T", tc); +} + +BT_ASSERT_FUNC +static +bool trace_has_environment_entry(const struct bt_trace_class *tc, const char *name) +{ + BT_ASSERT(tc); + + return bt_attributes_borrow_field_value_by_name( + tc->environment, name) != NULL; +} + +static +int set_environment_entry(struct bt_trace_class *tc, const char *name, + struct bt_value *value) +{ + int ret; + + BT_ASSERT(tc); + BT_ASSERT(name); + BT_ASSERT(value); + BT_ASSERT_PRE(!tc->frozen || + !trace_has_environment_entry(tc, name), + "Trace class is frozen: cannot replace environment entry: " + "%![tc-]+T, entry-name=\"%s\"", tc, name); + ret = bt_attributes_set_field_value(tc->environment, name, + value); + bt_value_freeze(value); + if (ret) { + BT_LIB_LOGE("Cannot set trace class's environment entry: " + "%![tc-]+T, entry-name=\"%s\"", tc, name); + } else { + BT_LIB_LOGV("Set trace class's environment entry: " + "%![tc-]+T, entry-name=\"%s\"", tc, name); + } + + return ret; +} + +int bt_trace_class_set_environment_entry_string( + struct bt_trace_class *tc, const char *name, const char *value) +{ + int ret; + struct bt_value *value_obj; + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); + value_obj = bt_value_string_create_init(value); + if (!value_obj) { + BT_LOGE_STR("Cannot create a string value object."); + ret = -1; + goto end; + } + + /* set_environment_entry() logs errors */ + ret = set_environment_entry(tc, name, value_obj); + +end: + bt_object_put_ref(value_obj); + return ret; +} + +int bt_trace_class_set_environment_entry_integer(struct bt_trace_class *tc, + const char *name, int64_t value) +{ + int ret; + struct bt_value *value_obj; + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); + value_obj = bt_value_integer_create_init(value); + if (!value_obj) { + BT_LOGE_STR("Cannot create an integer value object."); + ret = -1; + goto end; + } + + /* set_environment_entry() logs errors */ + ret = set_environment_entry(tc, name, value_obj); + +end: + bt_object_put_ref(value_obj); + return ret; +} + +uint64_t bt_trace_class_get_environment_entry_count(const struct bt_trace_class *tc) +{ + int64_t ret; + + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + ret = bt_attributes_get_count(tc->environment); + BT_ASSERT(ret >= 0); + return (uint64_t) ret; +} + +void bt_trace_class_borrow_environment_entry_by_index_const( + const struct bt_trace_class *tc, uint64_t index, + const char **name, const struct bt_value **value) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE_NON_NULL(value, "Value"); + BT_ASSERT_PRE_VALID_INDEX(index, + bt_attributes_get_count(tc->environment)); + *value = bt_attributes_borrow_field_value(tc->environment, index); + BT_ASSERT(*value); + *name = bt_attributes_get_field_name(tc->environment, index); + BT_ASSERT(*name); +} + +const struct bt_value *bt_trace_class_borrow_environment_entry_value_by_name_const( + const struct bt_trace_class *tc, const char *name) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); + return bt_attributes_borrow_field_value_by_name(tc->environment, + name); +} + +uint64_t bt_trace_class_get_stream_class_count(const struct bt_trace_class *tc) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + return (uint64_t) tc->stream_classes->len; +} + +struct bt_stream_class *bt_trace_class_borrow_stream_class_by_index( + struct bt_trace_class *tc, uint64_t index) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_VALID_INDEX(index, tc->stream_classes->len); + return g_ptr_array_index(tc->stream_classes, index); +} + +const struct bt_stream_class * +bt_trace_class_borrow_stream_class_by_index_const( + const struct bt_trace_class *tc, uint64_t index) +{ + return bt_trace_class_borrow_stream_class_by_index( + (void *) tc, index); +} + +struct bt_stream_class *bt_trace_class_borrow_stream_class_by_id( + struct bt_trace_class *tc, uint64_t id) +{ + struct bt_stream_class *stream_class = NULL; + uint64_t i; + + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + + for (i = 0; i < tc->stream_classes->len; i++) { + struct bt_stream_class *stream_class_candidate = + g_ptr_array_index(tc->stream_classes, i); + + if (stream_class_candidate->id == id) { + stream_class = stream_class_candidate; + goto end; + } + } + +end: + return stream_class; +} + +const struct bt_stream_class * +bt_trace_class_borrow_stream_class_by_id_const( + const struct bt_trace_class *tc, uint64_t id) +{ + return bt_trace_class_borrow_stream_class_by_id((void *) tc, id); +} + +const struct bt_field_class *bt_trace_class_borrow_packet_header_field_class_const( + const struct bt_trace_class *tc) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + return tc->packet_header_fc; +} + +int bt_trace_class_set_packet_header_field_class( + struct bt_trace_class *tc, + struct bt_field_class *field_class) +{ + int ret; + struct bt_resolve_field_path_context resolve_ctx = { + .packet_header = field_class, + .packet_context = NULL, + .event_header = NULL, + .event_common_context = NULL, + .event_specific_context = NULL, + .event_payload = NULL, + }; + + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); + BT_ASSERT_PRE_TRACE_CLASS_HOT(tc); + BT_ASSERT_PRE(bt_field_class_get_type(field_class) == + BT_FIELD_CLASS_TYPE_STRUCTURE, + "Packet header field classe is not a structure field classe: %!+F", + field_class); + ret = bt_resolve_field_paths(field_class, &resolve_ctx); + if (ret) { + goto end; + } + + bt_field_class_make_part_of_trace_class(field_class); + bt_object_put_ref(tc->packet_header_fc); + tc->packet_header_fc = field_class; + bt_object_get_no_null_check(tc->packet_header_fc); + bt_field_class_freeze(field_class); + BT_LIB_LOGV("Set trace class's packet header field classe: %!+T", tc); + +end: + return ret; +} + +BT_HIDDEN +void _bt_trace_class_freeze(const struct bt_trace_class *tc) +{ + /* The packet header field classe is already frozen */ + BT_ASSERT(tc); + BT_LIB_LOGD("Freezing trace class: %!+T", tc); + ((struct bt_trace_class *) tc)->frozen = true; +} + +bt_bool bt_trace_class_assigns_automatic_stream_class_id(const struct bt_trace_class *tc) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + return (bt_bool) tc->assigns_automatic_stream_class_id; +} + +void bt_trace_class_set_assigns_automatic_stream_class_id(struct bt_trace_class *tc, + bt_bool value) +{ + BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); + BT_ASSERT_PRE_TRACE_CLASS_HOT(tc); + tc->assigns_automatic_stream_class_id = (bool) value; + BT_LIB_LOGV("Set trace class's automatic stream class ID " + "assignment property: %!+T", tc); +} diff --git a/lib/trace-ir/trace.c b/lib/trace-ir/trace.c index 5fe179d7..f47b23d6 100644 --- a/lib/trace-ir/trace.c +++ b/lib/trace-ir/trace.c @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include #include @@ -92,14 +94,6 @@ void destroy_trace(struct bt_object *obj) trace->is_static_listeners = NULL; } - bt_object_pool_finalize(&trace->packet_header_field_pool); - - if (trace->environment) { - BT_LOGD_STR("Destroying environment attributes."); - bt_attributes_destroy(trace->environment); - trace->environment = NULL; - } - if (trace->name.str) { g_string_free(trace->name.str, TRUE); trace->name.str = NULL; @@ -112,43 +106,29 @@ void destroy_trace(struct bt_object *obj) trace->streams = NULL; } - if (trace->stream_classes) { - BT_LOGD_STR("Destroying stream classes."); - g_ptr_array_free(trace->stream_classes, TRUE); - trace->stream_classes = NULL; - } - if (trace->stream_classes_stream_count) { g_hash_table_destroy(trace->stream_classes_stream_count); trace->stream_classes_stream_count = NULL; } - BT_LOGD_STR("Putting packet header field classe."); - bt_object_put_ref(trace->packet_header_fc); - trace->packet_header_fc = NULL; + BT_LOGD_STR("Putting trace's class."); + bt_object_put_ref(trace->class); + trace->class = NULL; g_free(trace); } -static -void free_packet_header_field(struct bt_field_wrapper *field_wrapper, - struct bt_trace *trace) -{ - bt_field_wrapper_destroy(field_wrapper); -} - -struct bt_trace *bt_trace_create(void) +struct bt_trace *bt_trace_create(struct bt_trace_class *tc) { struct bt_trace *trace = NULL; - int ret; - BT_LOGD_STR("Creating default trace object."); + BT_LIB_LOGD("Creating trace object: %![tc-]+T", tc); trace = g_new0(struct bt_trace, 1); if (!trace) { BT_LOGE_STR("Failed to allocate one trace."); goto error; } - bt_object_init_shared_with_parent(&trace->base, destroy_trace); + bt_object_init_shared(&trace->base, destroy_trace); trace->streams = g_ptr_array_new_with_free_func( (GDestroyNotify) bt_object_try_spec_release); if (!trace->streams) { @@ -156,13 +136,6 @@ struct bt_trace *bt_trace_create(void) goto error; } - trace->stream_classes = g_ptr_array_new_with_free_func( - (GDestroyNotify) bt_object_try_spec_release); - if (!trace->stream_classes) { - BT_LOGE_STR("Failed to allocate one GPtrArray."); - goto error; - } - trace->stream_classes_stream_count = g_hash_table_new(g_direct_hash, g_direct_equal); if (!trace->stream_classes_stream_count) { @@ -176,12 +149,6 @@ struct bt_trace *bt_trace_create(void) goto error; } - trace->environment = bt_attributes_create(); - if (!trace->environment) { - BT_LOGE_STR("Cannot create empty attributes object."); - goto error; - } - trace->is_static_listeners = g_array_new(FALSE, TRUE, sizeof(struct bt_trace_is_static_listener_elem)); if (!trace->is_static_listeners) { @@ -189,17 +156,8 @@ struct bt_trace *bt_trace_create(void) goto error; } - trace->assigns_automatic_stream_class_id = true; - ret = bt_object_pool_initialize(&trace->packet_header_field_pool, - (bt_object_pool_new_object_func) bt_field_wrapper_new, - (bt_object_pool_destroy_object_func) free_packet_header_field, - trace); - if (ret) { - BT_LOGE("Failed to initialize packet header field pool: ret=%d", - ret); - goto error; - } - + trace->class = tc; + bt_object_get_no_null_check(trace->class); BT_LIB_LOGD("Created trace object: %!+t", trace); goto end; @@ -207,7 +165,7 @@ error: BT_OBJECT_PUT_REF_AND_RESET(trace); end: - return (void *) trace; + return trace; } const char *bt_trace_get_name(const struct bt_trace *trace) @@ -227,139 +185,6 @@ int bt_trace_set_name(struct bt_trace *trace, const char *name) return 0; } -bt_uuid bt_trace_get_uuid(const struct bt_trace *trace) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - return trace->uuid.value; -} - -void bt_trace_set_uuid(struct bt_trace *trace, bt_uuid uuid) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE_NON_NULL(uuid, "UUID"); - BT_ASSERT_PRE_TRACE_HOT(trace); - memcpy(trace->uuid.uuid, uuid, BABELTRACE_UUID_LEN); - trace->uuid.value = trace->uuid.uuid; - BT_LIB_LOGV("Set trace's UUID: %!+t", trace); -} - -BT_ASSERT_FUNC -static -bool trace_has_environment_entry(const struct bt_trace *trace, const char *name) -{ - BT_ASSERT(trace); - - return bt_attributes_borrow_field_value_by_name( - trace->environment, name) != NULL; -} - -static -int set_environment_entry(struct bt_trace *trace, const char *name, - struct bt_value *value) -{ - int ret; - - BT_ASSERT(trace); - BT_ASSERT(name); - BT_ASSERT(value); - BT_ASSERT_PRE(!trace->frozen || - !trace_has_environment_entry(trace, name), - "Trace is frozen: cannot replace environment entry: " - "%![trace-]+t, entry-name=\"%s\"", trace, name); - ret = bt_attributes_set_field_value(trace->environment, name, - value); - bt_value_freeze(value); - if (ret) { - BT_LIB_LOGE("Cannot set trace's environment entry: " - "%![trace-]+t, entry-name=\"%s\"", trace, name); - } else { - BT_LIB_LOGV("Set trace's environment entry: " - "%![trace-]+t, entry-name=\"%s\"", trace, name); - } - - return ret; -} - -int bt_trace_set_environment_entry_string( - struct bt_trace *trace, - const char *name, const char *value) -{ - int ret; - struct bt_value *value_obj; - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - BT_ASSERT_PRE_NON_NULL(value, "Value"); - value_obj = bt_value_string_create_init(value); - if (!value_obj) { - BT_LOGE_STR("Cannot create a string value object."); - ret = -1; - goto end; - } - - /* set_environment_entry() logs errors */ - ret = set_environment_entry(trace, name, value_obj); - -end: - bt_object_put_ref(value_obj); - return ret; -} - -int bt_trace_set_environment_entry_integer(struct bt_trace *trace, - const char *name, int64_t value) -{ - int ret; - struct bt_value *value_obj; - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - value_obj = bt_value_integer_create_init(value); - if (!value_obj) { - BT_LOGE_STR("Cannot create an integer value object."); - ret = -1; - goto end; - } - - /* set_environment_entry() logs errors */ - ret = set_environment_entry(trace, name, value_obj); - -end: - bt_object_put_ref(value_obj); - return ret; -} - -uint64_t bt_trace_get_environment_entry_count(const struct bt_trace *trace) -{ - int64_t ret; - - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - ret = bt_attributes_get_count(trace->environment); - BT_ASSERT(ret >= 0); - return (uint64_t) ret; -} - -void bt_trace_borrow_environment_entry_by_index_const( - const struct bt_trace *trace, uint64_t index, - const char **name, const struct bt_value **value) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - BT_ASSERT_PRE_NON_NULL(value, "Value"); - BT_ASSERT_PRE_VALID_INDEX(index, - bt_attributes_get_count(trace->environment)); - *value = bt_attributes_borrow_field_value(trace->environment, index); - BT_ASSERT(*value); - *name = bt_attributes_get_field_name(trace->environment, index); - BT_ASSERT(*name); -} - -const struct bt_value *bt_trace_borrow_environment_entry_value_by_name_const( - const struct bt_trace *trace, const char *name) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - return bt_attributes_borrow_field_value_by_name(trace->environment, - name); -} - uint64_t bt_trace_get_stream_count(const struct bt_trace *trace) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); @@ -408,101 +233,6 @@ const struct bt_stream *bt_trace_borrow_stream_by_id_const( return bt_trace_borrow_stream_by_id((void *) trace, id); } -uint64_t bt_trace_get_stream_class_count(const struct bt_trace *trace) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - return (uint64_t) trace->stream_classes->len; -} - -struct bt_stream_class *bt_trace_borrow_stream_class_by_index( - struct bt_trace *trace, uint64_t index) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE_VALID_INDEX(index, trace->stream_classes->len); - return g_ptr_array_index(trace->stream_classes, index); -} - -const struct bt_stream_class * -bt_trace_borrow_stream_class_by_index_const( - const struct bt_trace *trace, uint64_t index) -{ - return bt_trace_borrow_stream_class_by_index( - (void *) trace, index); -} - -struct bt_stream_class *bt_trace_borrow_stream_class_by_id( - struct bt_trace *trace, uint64_t id) -{ - struct bt_stream_class *stream_class = NULL; - uint64_t i; - - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - - for (i = 0; i < trace->stream_classes->len; i++) { - struct bt_stream_class *stream_class_candidate = - g_ptr_array_index(trace->stream_classes, i); - - if (stream_class_candidate->id == id) { - stream_class = stream_class_candidate; - goto end; - } - } - -end: - return stream_class; -} - -const struct bt_stream_class * -bt_trace_borrow_stream_class_by_id_const( - const struct bt_trace *trace, uint64_t id) -{ - return bt_trace_borrow_stream_class_by_id((void *) trace, id); -} - -const struct bt_field_class *bt_trace_borrow_packet_header_field_class_const( - const struct bt_trace *trace) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - return trace->packet_header_fc; -} - -int bt_trace_set_packet_header_field_class( - struct bt_trace *trace, - struct bt_field_class *field_class) -{ - int ret; - struct bt_resolve_field_path_context resolve_ctx = { - .packet_header = field_class, - .packet_context = NULL, - .event_header = NULL, - .event_common_context = NULL, - .event_specific_context = NULL, - .event_payload = NULL, - }; - - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); - BT_ASSERT_PRE_TRACE_HOT(trace); - BT_ASSERT_PRE(bt_field_class_get_type(field_class) == - BT_FIELD_CLASS_TYPE_STRUCTURE, - "Packet header field classe is not a structure field classe: %!+F", - field_class); - ret = bt_resolve_field_paths(field_class, &resolve_ctx); - if (ret) { - goto end; - } - - bt_field_class_make_part_of_trace(field_class); - bt_object_put_ref(trace->packet_header_fc); - trace->packet_header_fc = field_class; - bt_object_get_no_null_check(trace->packet_header_fc); - bt_field_class_freeze(field_class); - BT_LIB_LOGV("Set trace's packet header field classe: %!+t", trace); - -end: - return ret; -} - bt_bool bt_trace_is_static(const struct bt_trace *trace) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); @@ -633,26 +363,12 @@ void _bt_trace_freeze(const struct bt_trace *trace) { /* The packet header field classe is already frozen */ BT_ASSERT(trace); + BT_LIB_LOGD("Freezing trace's class: %!+T", trace->class); + bt_trace_class_freeze(trace->class); BT_LIB_LOGD("Freezing trace: %!+t", trace); ((struct bt_trace *) trace)->frozen = true; } -bt_bool bt_trace_assigns_automatic_stream_class_id(const struct bt_trace *trace) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - return (bt_bool) trace->assigns_automatic_stream_class_id; -} - -void bt_trace_set_assigns_automatic_stream_class_id(struct bt_trace *trace, - bt_bool value) -{ - BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - BT_ASSERT_PRE_TRACE_HOT(trace); - trace->assigns_automatic_stream_class_id = (bool) value; - BT_LIB_LOGV("Set trace's automatic stream class ID " - "assignment property: %!+t", trace); -} - BT_HIDDEN void bt_trace_add_stream(struct bt_trace *trace, struct bt_stream *stream) { @@ -689,3 +405,15 @@ uint64_t bt_trace_get_automatic_stream_id(const struct bt_trace *trace, return id; } + +struct bt_trace_class *bt_trace_borrow_class(struct bt_trace *trace) +{ + BT_ASSERT_PRE_NON_NULL(trace, "Trace"); + return trace->class; +} + +const struct bt_trace_class *bt_trace_borrow_class_const( + const struct bt_trace *trace) +{ + return bt_trace_borrow_class((void *) trace); +} diff --git a/plugins/ctf/common/metadata/ast.h b/plugins/ctf/common/metadata/ast.h index 601f046d..907cdcd9 100644 --- a/plugins/ctf/common/metadata/ast.h +++ b/plugins/ctf/common/metadata/ast.h @@ -318,13 +318,12 @@ const char *node_type(struct ctf_node *node); BT_HIDDEN struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create( - const struct ctf_metadata_decoder_config *config, - const char *name); + const struct ctf_metadata_decoder_config *config); void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor); BT_HIDDEN -struct bt_trace *ctf_visitor_generate_ir_get_ir_trace( +struct bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class( struct ctf_visitor_generate_ir *visitor); BT_HIDDEN diff --git a/plugins/ctf/common/metadata/ctf-meta-translate.c b/plugins/ctf/common/metadata/ctf-meta-translate.c index 93d61d2e..ddd24f4f 100644 --- a/plugins/ctf/common/metadata/ctf-meta-translate.c +++ b/plugins/ctf/common/metadata/ctf-meta-translate.c @@ -457,20 +457,19 @@ end: static inline struct bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc, - struct bt_trace *ir_trace, struct ctf_trace_class *tc) + struct bt_trace_class *ir_tc, struct ctf_trace_class *tc) { int ret; struct bt_stream_class *ir_sc = NULL; struct ctf_field_class_int *int_fc; if (sc->is_translated) { - ir_sc = bt_trace_borrow_stream_class_by_id( - ir_trace, sc->id); + ir_sc = bt_trace_class_borrow_stream_class_by_id(ir_tc, sc->id); BT_ASSERT(ir_sc); goto end; } - ir_sc = bt_stream_class_create_with_id(ir_trace, sc->id); + ir_sc = bt_stream_class_create_with_id(ir_tc, sc->id); BT_ASSERT(ir_sc); bt_object_put_ref(ir_sc); @@ -564,7 +563,7 @@ end: } static inline -int ctf_trace_class_to_ir(struct bt_trace *ir_trace, +int ctf_trace_class_to_ir(struct bt_trace_class *ir_tc, struct ctf_trace_class *tc) { int ret = 0; @@ -579,22 +578,15 @@ int ctf_trace_class_to_ir(struct bt_trace *ir_trace, tc->packet_header_fc, tc, NULL, NULL); if (ir_fc) { - ret = bt_trace_set_packet_header_field_class( - ir_trace, ir_fc); + ret = bt_trace_class_set_packet_header_field_class( + ir_tc, ir_fc); BT_ASSERT(ret == 0); bt_object_put_ref(ir_fc); } } - if (tc->name->len > 0) { - ret = bt_trace_set_name(ir_trace, tc->name->str); - if (ret) { - goto end; - } - } - if (tc->is_uuid_set) { - bt_trace_set_uuid(ir_trace, tc->uuid); + bt_trace_class_set_uuid(ir_tc, tc->uuid); } for (i = 0; i < tc->env_entries->len; i++) { @@ -603,13 +595,13 @@ int ctf_trace_class_to_ir(struct bt_trace *ir_trace, switch (env_entry->type) { case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT: - ret = bt_trace_set_environment_entry_integer( - ir_trace, env_entry->name->str, + ret = bt_trace_class_set_environment_entry_integer( + ir_tc, env_entry->name->str, env_entry->value.i); break; case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR: - ret = bt_trace_set_environment_entry_string( - ir_trace, env_entry->name->str, + ret = bt_trace_class_set_environment_entry_string( + ir_tc, env_entry->name->str, env_entry->value.str->str); break; default: @@ -621,23 +613,23 @@ int ctf_trace_class_to_ir(struct bt_trace *ir_trace, } } - bt_trace_set_assigns_automatic_stream_class_id(ir_trace, + bt_trace_class_set_assigns_automatic_stream_class_id(ir_tc, BT_FALSE); tc->is_translated = true; - tc->ir_tc = ir_trace; + tc->ir_tc = ir_tc; end: return ret; } BT_HIDDEN -int ctf_trace_class_translate(struct bt_trace *ir_trace, +int ctf_trace_class_translate(struct bt_trace_class *ir_tc, struct ctf_trace_class *tc) { int ret = 0; uint64_t i; - ret = ctf_trace_class_to_ir(ir_trace, tc); + ret = ctf_trace_class_to_ir(ir_tc, tc); if (ret) { goto end; } @@ -647,7 +639,7 @@ int ctf_trace_class_translate(struct bt_trace *ir_trace, struct ctf_stream_class *sc = tc->stream_classes->pdata[i]; struct bt_stream_class *ir_sc; - ir_sc = ctf_stream_class_to_ir(sc, ir_trace, tc); + ir_sc = ctf_stream_class_to_ir(sc, ir_tc, tc); if (!ir_sc) { ret = -1; goto end; diff --git a/plugins/ctf/common/metadata/ctf-meta-visitors.h b/plugins/ctf/common/metadata/ctf-meta-visitors.h index caeddf32..9d3bd234 100644 --- a/plugins/ctf/common/metadata/ctf-meta-visitors.h +++ b/plugins/ctf/common/metadata/ctf-meta-visitors.h @@ -24,7 +24,7 @@ BT_HIDDEN int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc); BT_HIDDEN -int ctf_trace_class_translate(struct bt_trace *ir_trace, +int ctf_trace_class_translate(struct bt_trace_class *ir_tc, struct ctf_trace_class *tc); BT_HIDDEN diff --git a/plugins/ctf/common/metadata/ctf-meta.h b/plugins/ctf/common/metadata/ctf-meta.h index 4c9aacf4..76e24d42 100644 --- a/plugins/ctf/common/metadata/ctf-meta.h +++ b/plugins/ctf/common/metadata/ctf-meta.h @@ -246,7 +246,6 @@ struct ctf_trace_class_env_entry { }; struct ctf_trace_class { - GString *name; unsigned int major; unsigned int minor; uint8_t uuid[16]; @@ -270,7 +269,7 @@ struct ctf_trace_class { bool is_translated; /* Weak, set during translation */ - struct bt_trace *ir_tc; + struct bt_trace_class *ir_tc; }; static inline @@ -1450,9 +1449,7 @@ struct ctf_trace_class *ctf_trace_class_create(void) struct ctf_trace_class *tc = g_new0(struct ctf_trace_class, 1); BT_ASSERT(tc); - tc->name = g_string_new(NULL); tc->default_byte_order = -1; - BT_ASSERT(tc->name); tc->clock_classes = g_ptr_array_new_with_free_func( (GDestroyNotify) bt_object_put_ref); BT_ASSERT(tc->clock_classes); @@ -1471,10 +1468,6 @@ void ctf_trace_class_destroy(struct ctf_trace_class *tc) return; } - if (tc->name) { - g_string_free(tc->name, TRUE); - } - ctf_field_class_destroy(tc->packet_header_fc); if (tc->clock_classes) { diff --git a/plugins/ctf/common/metadata/decoder.c b/plugins/ctf/common/metadata/decoder.c index 38733ae3..4b4e634d 100644 --- a/plugins/ctf/common/metadata/decoder.c +++ b/plugins/ctf/common/metadata/decoder.c @@ -348,8 +348,7 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf( BT_HIDDEN struct ctf_metadata_decoder *ctf_metadata_decoder_create( - const struct ctf_metadata_decoder_config *config, - const char *name) + const struct ctf_metadata_decoder_config *config) { struct ctf_metadata_decoder *mdec = g_new0(struct ctf_metadata_decoder, 1); @@ -364,9 +363,8 @@ struct ctf_metadata_decoder *ctf_metadata_decoder_create( BT_LOGD("Creating CTF metadata decoder: " "clock-class-offset-s=%" PRId64 ", " - "clock-class-offset-ns=%" PRId64 ", name=\"%s\"", - config->clock_class_offset_s, config->clock_class_offset_ns, - name); + "clock-class-offset-ns=%" PRId64, + config->clock_class_offset_s, config->clock_class_offset_ns); if (!mdec) { BT_LOGE_STR("Failed to allocate one CTF metadata decoder."); @@ -374,7 +372,7 @@ struct ctf_metadata_decoder *ctf_metadata_decoder_create( } mdec->config = *config; - mdec->visitor = ctf_visitor_generate_ir_create(config, name); + mdec->visitor = ctf_visitor_generate_ir_create(config); if (!mdec->visitor) { BT_LOGE("Failed to create a CTF IR metadata AST visitor: " "mdec-addr=%p", mdec); @@ -385,10 +383,9 @@ struct ctf_metadata_decoder *ctf_metadata_decoder_create( BT_LOGD("Creating CTF metadata decoder: " "clock-class-offset-s=%" PRId64 ", " - "clock-class-offset-ns=%" PRId64 ", " - "name=\"%s\", addr=%p", + "clock-class-offset-ns=%" PRId64 ", addr=%p", config->clock_class_offset_s, config->clock_class_offset_ns, - name, mdec); + mdec); end: return mdec; @@ -556,10 +553,10 @@ end: } BT_HIDDEN -struct bt_trace *ctf_metadata_decoder_get_ir_trace( +struct bt_trace_class *ctf_metadata_decoder_get_ir_trace_class( struct ctf_metadata_decoder *mdec) { - return ctf_visitor_generate_ir_get_ir_trace(mdec->visitor); + return ctf_visitor_generate_ir_get_ir_trace_class(mdec->visitor); } BT_HIDDEN diff --git a/plugins/ctf/common/metadata/decoder.h b/plugins/ctf/common/metadata/decoder.h index 51d3a185..56b262dd 100644 --- a/plugins/ctf/common/metadata/decoder.h +++ b/plugins/ctf/common/metadata/decoder.h @@ -39,15 +39,13 @@ struct ctf_metadata_decoder_config { }; /* - * Creates a CTF metadata decoder. `name` is this decoder's trace's - * name. + * Creates a CTF metadata decoder. * * Returns `NULL` on error. */ BT_HIDDEN struct ctf_metadata_decoder *ctf_metadata_decoder_create( - const struct ctf_metadata_decoder_config *config, - const char *name); + const struct ctf_metadata_decoder_config *config); /* * Destroys a CTF metadata decoder that you created with @@ -64,7 +62,7 @@ void ctf_metadata_decoder_destroy( * until the end of this file stream. If it finds new information (new * event class, new stream class, or new clock class), it appends this * information to the decoder's trace object (as returned by - * ctf_metadata_decoder_get_ir_trace()), or it creates this trace. + * ctf_metadata_decoder_get_ir_trace_class()), or it creates this trace. * * The metadata can be packetized or not. * @@ -89,7 +87,7 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_decode( struct ctf_metadata_decoder *metadata_decoder, FILE *fp); BT_HIDDEN -struct bt_trace *ctf_metadata_decoder_get_ir_trace( +struct bt_trace_class *ctf_metadata_decoder_get_ir_trace_class( struct ctf_metadata_decoder *mdec); BT_HIDDEN diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index d746b27e..e57d0b30 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -193,8 +193,8 @@ struct ctx_decl_scope { * Visitor context (private). */ struct ctx { - /* Trace IR trace being filled (owned by this) */ - struct bt_trace *trace; + /* Trace IR trace class being filled (owned by this) */ + struct bt_trace_class *trace_class; /* CTF meta trace being filled (owned by this) */ struct ctf_trace_class *ctf_tc; @@ -208,9 +208,6 @@ struct ctx { /* True if this is an LTTng trace */ bool is_lttng; - /* Eventual name suffix of the trace to set (owned by this) */ - char *trace_class_name_suffix; - /* Config passed by the user */ struct ctf_metadata_decoder_config decoder_config; }; @@ -554,16 +551,12 @@ void ctx_destroy(struct ctx *ctx) scope = parent_scope; } - bt_object_put_ref(ctx->trace); + bt_object_put_ref(ctx->trace_class); if (ctx->ctf_tc) { ctf_trace_class_destroy(ctx->ctf_tc); } - if (ctx->trace_class_name_suffix) { - free(ctx->trace_class_name_suffix); - } - g_free(ctx); end: @@ -577,8 +570,8 @@ end: * @returns New visitor context, or NULL on error */ static -struct ctx *ctx_create(const struct ctf_metadata_decoder_config *decoder_config, - const char *trace_class_name_suffix) +struct ctx *ctx_create( + const struct ctf_metadata_decoder_config *decoder_config) { struct ctx *ctx = NULL; @@ -590,9 +583,9 @@ struct ctx *ctx_create(const struct ctf_metadata_decoder_config *decoder_config, goto error; } - ctx->trace = bt_trace_create(); - if (!ctx->trace) { - BT_LOGE_STR("Cannot create empty trace."); + ctx->trace_class = bt_trace_class_create(); + if (!ctx->trace_class) { + BT_LOGE_STR("Cannot create empty trace class."); goto error; } @@ -609,14 +602,6 @@ struct ctx *ctx_create(const struct ctf_metadata_decoder_config *decoder_config, goto error; } - if (trace_class_name_suffix) { - ctx->trace_class_name_suffix = strdup(trace_class_name_suffix); - if (!ctx->trace_class_name_suffix) { - BT_LOGE_STR("Failed to copy string."); - goto error; - } - } - ctx->decoder_config = *decoder_config; goto end; @@ -4815,64 +4800,14 @@ end: return ret; } -static -int try_set_trace_class_name(struct ctx *ctx) -{ - GString *name = NULL; - int ret = 0; - struct ctf_trace_class_env_entry *env_entry; - - if (ctx->ctf_tc->name->len > 0) { - /* Already set */ - goto end; - } - - name = g_string_new(NULL); - if (!name) { - BT_LOGE_STR("Failed to allocate a GString."); - ret = -1; - goto end; - } - - /* - * Check if we have a trace environment string value named `hostname`. - * If so, use it as the trace name's prefix. - */ - env_entry = ctf_trace_class_borrow_env_entry_by_name(ctx->ctf_tc, - "hostname"); - if (env_entry && - env_entry->type == CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR) { - g_string_append(name, env_entry->value.str->str); - - if (ctx->trace_class_name_suffix) { - g_string_append_c(name, G_DIR_SEPARATOR); - } - } - - if (ctx->trace_class_name_suffix) { - g_string_append(name, ctx->trace_class_name_suffix); - } - - g_string_assign(ctx->ctf_tc->name, name->str); - goto end; - -end: - if (name) { - g_string_free(name, TRUE); - } - - return ret; -} - BT_HIDDEN struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create( - const struct ctf_metadata_decoder_config *decoder_config, - const char *name) + const struct ctf_metadata_decoder_config *decoder_config) { struct ctx *ctx = NULL; /* Create visitor's context */ - ctx = ctx_create(decoder_config, name); + ctx = ctx_create(decoder_config); if (!ctx) { BT_LOGE_STR("Cannot create visitor's context."); goto error; @@ -4895,15 +4830,15 @@ void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor) } BT_HIDDEN -struct bt_trace *ctf_visitor_generate_ir_get_ir_trace( +struct bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class( struct ctf_visitor_generate_ir *visitor) { struct ctx *ctx = (void *) visitor; BT_ASSERT(ctx); - BT_ASSERT(ctx->trace); - bt_object_get_ref(ctx->trace); - return ctx->trace; + BT_ASSERT(ctx->trace_class); + bt_object_get_ref(ctx->trace_class); + return ctx->trace_class; } BT_HIDDEN @@ -5086,13 +5021,6 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, goto end; } - /* Set trace's name, if not already done */ - ret = try_set_trace_class_name(ctx); - if (ret) { - ret = -EINVAL; - goto end; - } - /* Update trace class meanings */ ret = ctf_trace_class_update_meanings(ctx->ctf_tc); if (ret) { @@ -5136,7 +5064,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } /* Copy new CTF metadata -> new IR metadata */ - ret = ctf_trace_class_translate(ctx->trace, ctx->ctf_tc); + ret = ctf_trace_class_translate(ctx->trace_class, ctx->ctf_tc); if (ret) { ret = -EINVAL; goto end; diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 2c9efd63..a8028b33 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -661,7 +661,7 @@ enum bt_notif_iter_status read_packet_header_begin_state( goto end; } - /* Packet header class is common to the whole trace. */ + /* Packet header class is common to the whole trace class. */ packet_header_fc = notit->meta.tc->packet_header_fc; if (!packet_header_fc) { notit->state = STATE_AFTER_TRACE_PACKET_HEADER; @@ -672,8 +672,8 @@ enum bt_notif_iter_status read_packet_header_begin_state( if (packet_header_fc->in_ir) { /* - * Create free packet header field from trace. This - * field is going to be moved to the packet once we + * Create free packet header field from trace class. + * This field is going to be moved to the packet once we * create it. We cannot create the packet now because: * * 1. A packet is created from a stream. @@ -685,7 +685,7 @@ enum bt_notif_iter_status read_packet_header_begin_state( bt_packet_header_field_create( notit->meta.tc->ir_tc); if (!notit->packet_header_field) { - BT_LOGE_STR("Cannot create packet header field wrapper from trace."); + BT_LOGE_STR("Cannot create packet header field wrapper from trace class."); ret = BT_NOTIF_ITER_STATUS_ERROR; goto end; } @@ -700,20 +700,17 @@ enum bt_notif_iter_status read_packet_header_begin_state( notit->cur_event_class_id = -1; notit->cur_data_stream_id = -1; BT_LOGV("Decoding packet header field:" - "notit-addr=%p, trace-addr=%p, trace-name=\"%s\", fc-addr=%p", - notit, notit->meta.tc, - notit->meta.tc->name->str, packet_header_fc); + "notit-addr=%p, trace-class-addr=%p, fc-addr=%p", + notit, notit->meta.tc, packet_header_fc); ret = read_dscope_begin_state(notit, packet_header_fc, STATE_AFTER_TRACE_PACKET_HEADER, STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE, notit->dscopes.trace_packet_header); if (ret < 0) { BT_LOGW("Cannot decode packet header field: " - "notit-addr=%p, trace-addr=%p, " - "trace-name=\"%s\", fc-addr=%p", - notit, notit->meta.tc, - notit->meta.tc->name->str, - packet_header_fc); + "notit-addr=%p, trace-class-addr=%p, " + "fc-addr=%p", + notit, notit->meta.tc, packet_header_fc); } end: @@ -742,8 +739,7 @@ enum bt_notif_iter_status set_current_stream_class(struct bt_notif_iter *notit) if (notit->meta.tc->stream_classes->len != 1) { BT_LOGW("Need exactly one stream class since there's " "no stream class ID field: " - "notit-addr=%p, trace-name=\"%s\"", - notit, notit->meta.tc->name->str); + "notit-addr=%p", notit); status = BT_NOTIF_ITER_STATUS_ERROR; goto end; } @@ -755,11 +751,10 @@ enum bt_notif_iter_status set_current_stream_class(struct bt_notif_iter *notit) new_stream_class = ctf_trace_class_borrow_stream_class_by_id( notit->meta.tc, notit->cur_stream_class_id); if (!new_stream_class) { - BT_LOGW("No stream class with ID of stream class ID to use in trace: " + BT_LOGW("No stream class with ID of stream class ID to use in trace class: " "notit-addr=%p, stream-class-id=%" PRIu64 ", " - "trace-addr=%p, trace-name=\"%s\"", - notit, notit->cur_stream_class_id, notit->meta.tc, - notit->meta.tc->name->str); + "trace-class-addr=%p", + notit, notit->cur_stream_class_id, notit->meta.tc); status = BT_NOTIF_ITER_STATUS_ERROR; goto end; } @@ -771,13 +766,12 @@ enum bt_notif_iter_status set_current_stream_class(struct bt_notif_iter *notit) "prev-stream-class-id=%" PRId64 ", " "next-stream-class-addr=%p, " "next-stream-class-id=%" PRId64 ", " - "trace-addr=%p, trace-name=\"%s\"", + "trace-addr=%p", notit, notit->meta.sc, notit->meta.sc->id, new_stream_class, new_stream_class->id, - notit->meta.tc, - notit->meta.tc->name->str); + notit->meta.tc); status = BT_NOTIF_ITER_STATUS_ERROR; goto end; } @@ -1099,7 +1093,7 @@ enum bt_notif_iter_status read_event_header_begin_state( bt_event_header_field_create( notit->meta.sc->ir_sc); if (!notit->event_header_field) { - BT_LOGE_STR("Cannot create event header field wrapper from trace."); + BT_LOGE_STR("Cannot create event header field wrapper from trace class."); status = BT_NOTIF_ITER_STATUS_ERROR; goto end; } @@ -1157,8 +1151,7 @@ enum bt_notif_iter_status set_current_event_class(struct bt_notif_iter *notit) if (notit->meta.sc->event_classes->len != 1) { BT_LOGW("Need exactly one event class since there's " "no event class ID field: " - "notit-addr=%p, trace-name=\"%s\"", - notit, notit->meta.tc->name->str); + "notit-addr=%p", notit); status = BT_NOTIF_ITER_STATUS_ERROR; goto end; } @@ -1173,9 +1166,9 @@ enum bt_notif_iter_status set_current_event_class(struct bt_notif_iter *notit) BT_LOGW("No event class with ID of event class ID to use in stream class: " "notit-addr=%p, stream-class-id=%" PRIu64 ", " "event-class-id=%" PRIu64 ", " - "trace-addr=%p, trace-name=\"%s\"", + "trace-class-addr=%p", notit, notit->meta.sc->id, notit->cur_event_class_id, - notit->meta.tc, notit->meta.tc->name->str); + notit->meta.tc); status = BT_NOTIF_ITER_STATUS_ERROR; goto end; } @@ -2471,8 +2464,8 @@ struct bt_notif_iter *bt_notif_iter_create(struct ctf_trace_class *tc, BT_ASSERT(medops.request_bytes); BT_ASSERT(medops.borrow_stream); BT_LOGD("Creating CTF plugin notification iterator: " - "trace-addr=%p, trace-name=\"%s\", max-request-size=%zu, " - "data=%p", tc, tc->name->str, max_request_sz, data); + "trace-addr=%p, max-request-size=%zu, " + "data=%p", tc, max_request_sz, data); notit = g_new0(struct bt_notif_iter, 1); if (!notit) { BT_LOGE_STR("Failed to allocate one CTF plugin notification iterator."); @@ -2499,10 +2492,9 @@ struct bt_notif_iter *bt_notif_iter_create(struct ctf_trace_class *tc, bt_notif_iter_reset(notit); BT_LOGD("Created CTF plugin notification iterator: " - "trace-addr=%p, trace-name=\"%s\", max-request-size=%zu, " + "trace-addr=%p, max-request-size=%zu, " "data=%p, notit-addr=%p", - tc, tc->name->str, max_request_sz, data, - notit); + tc, max_request_sz, data, notit); notit->cur_packet_offset = 0; end: diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index 3ace7653..8de14bdc 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -322,6 +322,8 @@ void ctf_fs_trace_destroy(struct ctf_fs_trace *ctf_fs_trace) g_ptr_array_free(ctf_fs_trace->ds_file_groups, TRUE); } + BT_OBJECT_PUT_REF_AND_RESET(ctf_fs_trace->trace); + if (ctf_fs_trace->path) { g_string_free(ctf_fs_trace->path, TRUE); } @@ -861,12 +863,14 @@ int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) /* No stream ID: use 0 */ ds_file_group->stream = bt_stream_create_with_id( ds_file_group->stream_class, + ctf_fs_trace->trace, ctf_fs_trace->next_stream_id); ctf_fs_trace->next_stream_id++; } else { /* Specific stream ID */ ds_file_group->stream = bt_stream_create_with_id( ds_file_group->stream_class, + ctf_fs_trace->trace, (uint64_t) ds_file_group->stream_id); } @@ -909,6 +913,54 @@ end: return ret; } +static +int set_trace_name(struct bt_trace *trace, const char *name_suffix) +{ + int ret = 0; + const struct bt_trace_class *tc = bt_trace_borrow_class_const(trace); + const struct bt_value *val; + GString *name; + + name = g_string_new(NULL); + if (!name) { + BT_LOGE_STR("Failed to allocate a GString."); + ret = -1; + goto end; + } + + /* + * Check if we have a trace environment string value named `hostname`. + * If so, use it as the trace name's prefix. + */ + val = bt_trace_class_borrow_environment_entry_value_by_name_const( + tc, "hostname"); + if (val && bt_value_is_string(val)) { + g_string_append(name, bt_value_string_get(val)); + + if (name_suffix) { + g_string_append_c(name, G_DIR_SEPARATOR); + } + } + + if (name_suffix) { + g_string_append(name, name_suffix); + } + + ret = bt_trace_set_name(trace, name->str); + if (ret) { + goto end; + } + + goto end; + +end: + if (name) { + g_string_free(name, TRUE); + } + + return ret; +} + BT_HIDDEN struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, struct ctf_fs_metadata_config *metadata_config) @@ -943,7 +995,18 @@ struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, goto error; } - ret = ctf_fs_metadata_set_trace(ctf_fs_trace, metadata_config); + ret = ctf_fs_metadata_set_trace_class(ctf_fs_trace, metadata_config); + if (ret) { + goto error; + } + + ctf_fs_trace->trace = + bt_trace_create(ctf_fs_trace->metadata->trace_class); + if (!ctf_fs_trace->trace) { + goto error; + } + + ret = set_trace_name(ctf_fs_trace->trace, name); if (ret) { goto error; } @@ -958,7 +1021,7 @@ struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, * trace needs. There won't be any more. Therefore it is safe to * make this trace static. */ - (void) bt_trace_make_static(ctf_fs_trace->metadata->trace); + (void) bt_trace_make_static(ctf_fs_trace->trace); goto end; diff --git a/plugins/ctf/fs-src/fs.h b/plugins/ctf/fs-src/fs.h index 83cf3a9c..3542f58a 100644 --- a/plugins/ctf/fs-src/fs.h +++ b/plugins/ctf/fs-src/fs.h @@ -53,7 +53,7 @@ struct ctf_fs_metadata { struct ctf_metadata_decoder *decoder; /* Owned by this */ - struct bt_trace *trace; + struct bt_trace_class *trace_class; /* Weak (owned by `decoder` above) */ struct ctf_trace_class *tc; @@ -85,6 +85,9 @@ struct ctf_fs_trace { /* Owned by this */ struct ctf_fs_metadata *metadata; + /* Owned by this */ + struct bt_trace *trace; + /* Array of struct ctf_fs_ds_file_group *, owned by this */ GPtrArray *ds_file_groups; diff --git a/plugins/ctf/fs-src/metadata.c b/plugins/ctf/fs-src/metadata.c index 35482944..48d416c8 100644 --- a/plugins/ctf/fs-src/metadata.c +++ b/plugins/ctf/fs-src/metadata.c @@ -86,7 +86,7 @@ end: return file; } -int ctf_fs_metadata_set_trace(struct ctf_fs_trace *ctf_fs_trace, +int ctf_fs_metadata_set_trace_class(struct ctf_fs_trace *ctf_fs_trace, struct ctf_fs_metadata_config *config) { int ret = 0; @@ -104,8 +104,7 @@ int ctf_fs_metadata_set_trace(struct ctf_fs_trace *ctf_fs_trace, } ctf_fs_trace->metadata->decoder = ctf_metadata_decoder_create( - config ? &decoder_config : NULL, - ctf_fs_trace->name->str); + config ? &decoder_config : NULL); if (!ctf_fs_trace->metadata->decoder) { BT_LOGE("Cannot create metadata decoder object"); ret = -1; @@ -119,9 +118,10 @@ int ctf_fs_metadata_set_trace(struct ctf_fs_trace *ctf_fs_trace, goto end; } - ctf_fs_trace->metadata->trace = ctf_metadata_decoder_get_ir_trace( - ctf_fs_trace->metadata->decoder); - BT_ASSERT(ctf_fs_trace->metadata->trace); + ctf_fs_trace->metadata->trace_class = + ctf_metadata_decoder_get_ir_trace_class( + ctf_fs_trace->metadata->decoder); + BT_ASSERT(ctf_fs_trace->metadata->trace_class); ctf_fs_trace->metadata->tc = ctf_metadata_decoder_borrow_ctf_trace_class( ctf_fs_trace->metadata->decoder); @@ -144,8 +144,8 @@ void ctf_fs_metadata_fini(struct ctf_fs_metadata *metadata) free(metadata->text); } - if (metadata->trace) { - BT_OBJECT_PUT_REF_AND_RESET(metadata->trace); + if (metadata->trace_class) { + BT_OBJECT_PUT_REF_AND_RESET(metadata->trace_class); } if (metadata->decoder) { diff --git a/plugins/ctf/fs-src/metadata.h b/plugins/ctf/fs-src/metadata.h index 496a5ca9..6e936e40 100644 --- a/plugins/ctf/fs-src/metadata.h +++ b/plugins/ctf/fs-src/metadata.h @@ -45,7 +45,7 @@ BT_HIDDEN void ctf_fs_metadata_fini(struct ctf_fs_metadata *metadata); BT_HIDDEN -int ctf_fs_metadata_set_trace(struct ctf_fs_trace *ctf_fs_trace, +int ctf_fs_metadata_set_trace_class(struct ctf_fs_trace *ctf_fs_trace, struct ctf_fs_metadata_config *config); BT_HIDDEN diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index cb2414f0..0f5b1599 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -68,9 +68,10 @@ struct dmesg_component { bt_bool no_timestamp; } params; - struct bt_trace *trace; + struct bt_trace_class *trace_class; struct bt_stream_class *stream_class; struct bt_event_class *event_class; + struct bt_trace *trace; struct bt_stream *stream; struct bt_packet *packet; struct bt_clock_class *clock_class; @@ -117,38 +118,16 @@ static int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) { struct bt_field_class *fc = NULL; - const char *trace_name = NULL; - gchar *basename = NULL; int ret = 0; - dmesg_comp->trace = bt_trace_create(); - if (!dmesg_comp->trace) { - BT_LOGE_STR("Cannot create an empty trace object."); + dmesg_comp->trace_class = bt_trace_class_create(); + if (!dmesg_comp->trace_class) { + BT_LOGE_STR("Cannot create an empty trace class object."); goto error; } - if (dmesg_comp->params.read_from_stdin) { - trace_name = "STDIN"; - } else { - basename = g_path_get_basename(dmesg_comp->params.path->str); - BT_ASSERT(basename); - - if (strcmp(basename, G_DIR_SEPARATOR_S) != 0 && - strcmp(basename, ".") != 0) { - trace_name = basename; - } - } - - if (trace_name) { - ret = bt_trace_set_name(dmesg_comp->trace, trace_name); - if (ret) { - BT_LOGE("Cannot set trace's name: name=\"%s\"", trace_name); - goto error; - } - } - dmesg_comp->stream_class = bt_stream_class_create( - dmesg_comp->trace); + dmesg_comp->trace_class); if (!dmesg_comp->stream_class) { BT_LOGE_STR("Cannot create a stream class object."); goto error; @@ -201,11 +180,6 @@ error: end: bt_object_put_ref(fc); - - if (basename) { - g_free(basename); - } - return ret; } @@ -264,11 +238,41 @@ end: } static -int create_packet_and_stream(struct dmesg_component *dmesg_comp) +int create_packet_and_stream_and_trace(struct dmesg_component *dmesg_comp) { int ret = 0; + const char *trace_name; + gchar *basename = NULL; + + dmesg_comp->trace = bt_trace_create(dmesg_comp->trace_class); + if (!dmesg_comp->trace) { + BT_LOGE_STR("Cannot create trace object."); + goto error; + } - dmesg_comp->stream = bt_stream_create(dmesg_comp->stream_class); + if (dmesg_comp->params.read_from_stdin) { + trace_name = "STDIN"; + } else { + basename = g_path_get_basename(dmesg_comp->params.path->str); + BT_ASSERT(basename); + + if (strcmp(basename, G_DIR_SEPARATOR_S) != 0 && + strcmp(basename, ".") != 0) { + trace_name = basename; + } + } + + if (trace_name) { + ret = bt_trace_set_name(dmesg_comp->trace, trace_name); + if (ret) { + BT_LOGE("Cannot set trace's name: name=\"%s\"", + trace_name); + goto error; + } + } + + dmesg_comp->stream = bt_stream_create(dmesg_comp->stream_class, + dmesg_comp->trace); if (!dmesg_comp->stream) { BT_LOGE_STR("Cannot create stream object."); goto error; @@ -292,6 +296,10 @@ error: ret = -1; end: + if (basename) { + g_free(basename); + } + return ret; } @@ -313,7 +321,7 @@ int try_create_meta_stream_packet(struct dmesg_component *dmesg_comp, goto error; } - ret = create_packet_and_stream(dmesg_comp); + ret = create_packet_and_stream_and_trace(dmesg_comp); if (ret) { BT_LOGE("Cannot create packet and stream objects: " "dmesg-comp-addr=%p", dmesg_comp); diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index 92de1909..46e3236d 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -222,7 +222,6 @@ int print_event_timestamp(struct pretty_component *pretty, int ret = 0; const struct bt_stream *stream = NULL; const struct bt_stream_class *stream_class = NULL; - const struct bt_trace *trace = NULL; const struct bt_clock_value *clock_value = NULL; enum bt_clock_value_status cv_status; @@ -237,11 +236,6 @@ int print_event_timestamp(struct pretty_component *pretty, ret = -1; goto end; } - trace = bt_stream_class_borrow_trace_const(stream_class); - if (!trace) { - ret = -1; - goto end; - } cv_status = bt_event_borrow_default_clock_value_const(event, &clock_value); @@ -320,25 +314,19 @@ int print_event_header(struct pretty_component *pretty, int ret = 0; const struct bt_event_class *event_class = NULL; const struct bt_stream_class *stream_class = NULL; - const struct bt_trace *trace_class = NULL; + const struct bt_trace_class *trace_class = NULL; + const struct bt_packet *packet = NULL; + const struct bt_stream *stream = NULL; + const struct bt_trace *trace = NULL; int dom_print = 0; enum bt_property_availability prop_avail; event_class = bt_event_borrow_class_const(event); - if (!event_class) { - ret = -1; - goto end; - } stream_class = bt_event_class_borrow_stream_class_const(event_class); - if (!stream_class) { - ret = -1; - goto end; - } - trace_class = bt_stream_class_borrow_trace_const(stream_class); - if (!trace_class) { - ret = -1; - goto end; - } + trace_class = bt_stream_class_borrow_trace_class_const(stream_class); + packet = bt_event_borrow_packet_const(event); + stream = bt_packet_borrow_stream_const(packet); + trace = bt_stream_borrow_trace_const(stream); ret = print_event_timestamp(pretty, event, &pretty->start_line); if (ret) { goto end; @@ -346,7 +334,7 @@ int print_event_header(struct pretty_component *pretty, if (pretty->options.print_trace_field) { const char *name; - name = bt_trace_get_name(trace_class); + name = bt_trace_get_name(trace); if (name) { if (!pretty->start_line) { g_string_append(pretty->string, ", "); @@ -365,7 +353,7 @@ int print_event_header(struct pretty_component *pretty, if (pretty->options.print_trace_hostname_field) { const struct bt_value *hostname_str; - hostname_str = bt_trace_borrow_environment_entry_value_by_name_const( + hostname_str = bt_trace_class_borrow_environment_entry_value_by_name_const( trace_class, "hostname"); if (hostname_str) { const char *str; @@ -384,7 +372,7 @@ int print_event_header(struct pretty_component *pretty, if (pretty->options.print_trace_domain_field) { const struct bt_value *domain_str; - domain_str = bt_trace_borrow_environment_entry_value_by_name_const( + domain_str = bt_trace_class_borrow_environment_entry_value_by_name_const( trace_class, "domain"); if (domain_str) { const char *str; @@ -405,7 +393,7 @@ int print_event_header(struct pretty_component *pretty, if (pretty->options.print_trace_procname_field) { const struct bt_value *procname_str; - procname_str = bt_trace_borrow_environment_entry_value_by_name_const( + procname_str = bt_trace_class_borrow_environment_entry_value_by_name_const( trace_class, "procname"); if (procname_str) { const char *str; @@ -426,7 +414,7 @@ int print_event_header(struct pretty_component *pretty, if (pretty->options.print_trace_vpid_field) { const struct bt_value *vpid_value; - vpid_value = bt_trace_borrow_environment_entry_value_by_name_const( + vpid_value = bt_trace_class_borrow_environment_entry_value_by_name_const( trace_class, "vpid"); if (vpid_value) { int64_t value; diff --git a/tests/lib/test_bt_notification_iterator.c b/tests/lib/test_bt_notification_iterator.c index 82f7dfb7..5455b960 100644 --- a/tests/lib/test_bt_notification_iterator.c +++ b/tests/lib/test_bt_notification_iterator.c @@ -63,12 +63,6 @@ static struct bt_packet *src_stream1_packet1; static struct bt_packet *src_stream1_packet2; static struct bt_packet *src_stream2_packet1; static struct bt_packet *src_stream2_packet2; -static const struct bt_stream *pub_src_stream1; -static const struct bt_stream *pub_src_stream2; -static const struct bt_packet *pub_src_stream1_packet1; -static const struct bt_packet *pub_src_stream1_packet2; -static const struct bt_packet *pub_src_stream2_packet1; -static const struct bt_packet *pub_src_stream2_packet2; enum { SEQ_END = -1, @@ -247,37 +241,34 @@ bool compare_test_events(const struct test_event *expected_events) static void init_static_data(void) { + struct bt_trace_class *trace_class; struct bt_trace *trace; /* Test events */ test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event)); BT_ASSERT(test_events); - /* Metadata */ - trace = bt_trace_create(); + /* Metadata, streams, and packets*/ + trace_class = bt_trace_class_create(); BT_ASSERT(trace); - src_stream_class = bt_stream_class_create(trace); + src_stream_class = bt_stream_class_create(trace_class); BT_ASSERT(src_stream_class); src_event_class = bt_event_class_create(src_stream_class); BT_ASSERT(src_event_class); - src_stream1 = bt_stream_create(src_stream_class); + trace = bt_trace_create(trace_class); + BT_ASSERT(trace); + src_stream1 = bt_stream_create(src_stream_class, trace); BT_ASSERT(src_stream1); - pub_src_stream1 = src_stream1; - src_stream2 = bt_stream_create(src_stream_class); + src_stream2 = bt_stream_create(src_stream_class, trace); BT_ASSERT(src_stream2); - pub_src_stream2 = src_stream2; src_stream1_packet1 = bt_packet_create(src_stream1); BT_ASSERT(src_stream1_packet1); - pub_src_stream1_packet1 = src_stream1_packet1; src_stream1_packet2 = bt_packet_create(src_stream1); BT_ASSERT(src_stream1_packet2); - pub_src_stream1_packet2 = src_stream1_packet2; src_stream2_packet1 = bt_packet_create(src_stream2); BT_ASSERT(src_stream2_packet1); - pub_src_stream2_packet1 = src_stream2_packet1; src_stream2_packet2 = bt_packet_create(src_stream2); BT_ASSERT(src_stream2_packet2); - pub_src_stream2_packet2 = src_stream2_packet2; if (debug) { fprintf(stderr, ":: stream 1: %p\n", src_stream1); @@ -289,6 +280,7 @@ void init_static_data(void) } bt_object_put_ref(trace); + bt_object_put_ref(trace_class); } static @@ -780,22 +772,22 @@ static void test_no_auto_notifs(void) { const struct test_event expected_test_events[] = { - { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = pub_src_stream1, .packet = NULL, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = pub_src_stream2, .packet = NULL, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = pub_src_stream2, .packet = pub_src_stream2_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream2, .packet = pub_src_stream2_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = pub_src_stream2, .packet = pub_src_stream2_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = pub_src_stream1, .packet = pub_src_stream1_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = pub_src_stream2, .packet = NULL, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = pub_src_stream1, .packet = pub_src_stream1_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = pub_src_stream1, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream2, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, { .type = TEST_EV_TYPE_END, }, { .type = TEST_EV_TYPE_SENTINEL, }, }; @@ -808,22 +800,22 @@ static void test_output_port_notification_iterator(void) { const struct test_event expected_test_events[] = { - { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = pub_src_stream1, .packet = NULL, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = pub_src_stream2, .packet = NULL, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = pub_src_stream2, .packet = pub_src_stream2_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream2, .packet = pub_src_stream2_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = pub_src_stream1, .packet = pub_src_stream1_packet1, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = pub_src_stream2, .packet = pub_src_stream2_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = pub_src_stream1, .packet = pub_src_stream1_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = pub_src_stream1, .packet = pub_src_stream1_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = pub_src_stream2, .packet = NULL, }, - { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = pub_src_stream1, .packet = pub_src_stream1_packet2, }, - { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = pub_src_stream1, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream2, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, { .type = TEST_EV_TYPE_END, }, { .type = TEST_EV_TYPE_SENTINEL, }, }; diff --git a/tests/lib/test_trace_ir_ref.c b/tests/lib/test_trace_ir_ref.c index 44fd5246..9f9da406 100644 --- a/tests/lib/test_trace_ir_ref.c +++ b/tests/lib/test_trace_ir_ref.c @@ -29,7 +29,7 @@ #define NR_TESTS 37 struct user { - struct bt_trace *tc; + struct bt_trace_class *tc; struct bt_stream_class *sc; struct bt_event_class *ec; struct bt_stream *stream; @@ -230,13 +230,13 @@ static void set_stream_class_field_classes( bt_object_put_ref(event_header_type); } -static void create_sc1(struct bt_trace *trace) +static void create_sc1(struct bt_trace_class *trace_class) { int ret; struct bt_event_class *ec1 = NULL, *ec2 = NULL; struct bt_stream_class *sc1 = NULL, *ret_stream = NULL; - sc1 = bt_stream_class_create(trace); + sc1 = bt_stream_class_create(trace_class); BT_ASSERT(sc1); ret = bt_stream_class_set_name(sc1, "sc1"); BT_ASSERT(ret == 0); @@ -254,13 +254,13 @@ static void create_sc1(struct bt_trace *trace) BT_OBJECT_PUT_REF_AND_RESET(sc1); } -static void create_sc2(struct bt_trace *trace) +static void create_sc2(struct bt_trace_class *trace_class) { int ret; struct bt_event_class *ec3 = NULL; struct bt_stream_class *sc2 = NULL, *ret_stream = NULL; - sc2 = bt_stream_class_create(trace); + sc2 = bt_stream_class_create(trace_class); BT_ASSERT(sc2); ret = bt_stream_class_set_name(sc2, "sc2"); BT_ASSERT(ret == 0); @@ -272,7 +272,7 @@ static void create_sc2(struct bt_trace *trace) BT_OBJECT_PUT_REF_AND_RESET(sc2); } -static void set_trace_packet_header(struct bt_trace *trace) +static void set_trace_packet_header(struct bt_trace_class *trace_class) { struct bt_field_class *packet_header_type; struct bt_field_class *fc; @@ -287,18 +287,18 @@ static void set_trace_packet_header(struct bt_trace *trace) "stream_id", fc); BT_ASSERT(ret == 0); bt_object_put_ref(fc); - ret = bt_trace_set_packet_header_field_class(trace, + ret = bt_trace_class_set_packet_header_field_class(trace_class, packet_header_type); BT_ASSERT(ret == 0); bt_object_put_ref(packet_header_type); } -static struct bt_trace *create_tc1(void) +static struct bt_trace_class *create_tc1(void) { - struct bt_trace *tc1 = NULL; + struct bt_trace_class *tc1 = NULL; - tc1 = bt_trace_create(); + tc1 = bt_trace_class_create(); BT_ASSERT(tc1); set_trace_packet_header(tc1); create_sc1(tc1); @@ -306,8 +306,8 @@ static struct bt_trace *create_tc1(void) return tc1; } -static void init_weak_refs(struct bt_trace *tc, - struct bt_trace **tc1, +static void init_weak_refs(struct bt_trace_class *tc, + struct bt_trace_class **tc1, struct bt_stream_class **sc1, struct bt_stream_class **sc2, struct bt_event_class **ec1, @@ -315,8 +315,8 @@ static void init_weak_refs(struct bt_trace *tc, struct bt_event_class **ec3) { *tc1 = tc; - *sc1 = bt_trace_borrow_stream_class_by_index(tc, 0); - *sc2 = bt_trace_borrow_stream_class_by_index(tc, 1); + *sc1 = bt_trace_class_borrow_stream_class_by_index(tc, 0); + *sc2 = bt_trace_class_borrow_stream_class_by_index(tc, 1); *ec1 = bt_stream_class_borrow_event_class_by_index(*sc1, 0); *ec2 = bt_stream_class_borrow_event_class_by_index(*sc1, 1); *ec3 = bt_stream_class_borrow_event_class_by_index(*sc2, 0); @@ -331,7 +331,7 @@ static void test_example_scenario(void) * of expected reference counts without affecting them by taking * "real" references to the objects. */ - struct bt_trace *tc1 = NULL, *weak_tc1 = NULL; + struct bt_trace_class *tc1 = NULL, *weak_tc1 = NULL; struct bt_stream_class *weak_sc1 = NULL, *weak_sc2 = NULL; struct bt_event_class *weak_ec1 = NULL, *weak_ec2 = NULL, *weak_ec3 = NULL; @@ -360,7 +360,7 @@ static void test_example_scenario(void) "TC1 reference count is 1"); /* User A acquires a reference to SC2 from TC1. */ - user_a.sc = bt_trace_borrow_stream_class_by_index( + user_a.sc = bt_trace_class_borrow_stream_class_by_index( user_a.tc, 1); bt_object_get_ref(user_a.sc); ok(user_a.sc, "User A acquires SC2 from TC1"); -- 2.34.1