Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / text / details / details.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #ifndef BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H
8 #define BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H
9
10 #include <glib.h>
11 #include <babeltrace2/babeltrace.h>
12 #include <stdbool.h>
13
14 /*
15 * This structure contains a hash table which maps trace IR stream class
16 * and event class addresses to whether or not they have been printed
17 * already during the lifetime of the component.
18 *
19 * It is safe to keep the addresses (weak references) in this hash table
20 * as long as the trace class to which the structure is associated
21 * exists because it's not possible to remove stream classes from a
22 * trace class and event classes from a stream class.
23 */
24 struct details_trace_class_meta {
25 /*
26 * Stream class or event class address (`const void *`) ->
27 * `guint` (as a pointer)
28 *
29 * This acts as a set in fact; we don't care about the values,
30 * but we put 1 so that we can use g_hash_table_lookup() to know
31 * whether or not the hash table contains a given key
32 * (g_hash_table_lookup() returns `NULL` when not found, but
33 * also when the value is `NULL`).
34 */
35 GHashTable *objects;
36
37 /*
38 * Trace class destruction listener ID (`UINT64_C(-1)` if
39 * there's no listener ID.
40 */
41 bt_listener_id tc_destruction_listener_id;
42 };
43
44 /*
45 * An entry of the `traces` hash table of a
46 * `struct details_comp` structure.
47 */
48 struct details_trace {
49 /* Unique ID of this trace within the lifetime of the component */
50 uint64_t unique_id;
51
52 /*
53 * Trace destruction listener ID (`UINT64_C(-1)` if there's no
54 * listener ID.
55 */
56 bt_listener_id trace_destruction_listener_id;
57 };
58
59 /* A `sink.text.details` component */
60 struct details_comp {
61 bt_logging_level log_level;
62 bt_self_component *self_comp;
63
64 /* Component's configuration */
65 struct {
66 /* Write data objects */
67 bool with_data;
68
69 /* Write metadata objects */
70 bool with_meta;
71
72 /*
73 * Compact mode: each line is a single message, and
74 * there are no extended message properties and
75 * event/packet fields. `with_meta` can still be true in
76 * compact mode, printing the full metadata objects, but
77 * making the messages compact.
78 */
79 bool compact;
80
81 /* Colorize output */
82 bool with_color;
83
84 /* Write message's time */
85 bool with_time;
86
87 /* Write trace's name */
88 bool with_trace_name;
89
90 /* Write stream class's name */
91 bool with_stream_class_name;
92
93 /* Write stream's name */
94 bool with_stream_name;
95
96 /* Write UUID */
97 bool with_uuid;
98 } cfg;
99
100 /*
101 * `const bt_trace_class *` (weak) ->
102 * `struct details_trace_class_meta *` (owned by this)
103 *
104 * The key (trace class object) is weak. An entry is added, if
105 * `cfg.with_meta` above is true, when first encountering a
106 * trace class. An entry is removed when a trace class is
107 * destroyed or when the component is finalized.
108 */
109 GHashTable *meta;
110
111 /*
112 * `const bt_trace *` (weak) ->
113 * `struct details_trace *` (owner by this)
114 *
115 * This hash table associates a trace object to a unique ID
116 * within the lifetime of this component. This is used to easily
117 * follow the messages of a given trace/stream when reading the
118 * text output of the component. We cannot use the actual stream
119 * ID properties for this because many streams can share the
120 * same ID (with different stream classes or different traces).
121 *
122 * When adding an entry, the unique ID to use is
123 * `next_unique_trace_id`.
124 *
125 * An entry is added when first encountering a trace. An entry
126 * is removed when a trace is destroyed or when the component is
127 * finalized.
128 */
129 GHashTable *traces;
130 uint32_t next_unique_trace_id;
131
132 /* Upstream message iterator */
133 bt_message_iterator *msg_iter;
134
135 /*
136 * True if this component printed something. This is used to
137 * prepend a newline to the next message string instead of
138 * appending it so that the last printed message is not followed
139 * with an empty line.
140 */
141 bool printed_something;
142
143 /* Current message's output buffer */
144 GString *str;
145 };
146
147 BT_HIDDEN
148 bt_component_class_initialize_method_status details_init(
149 bt_self_component_sink *component,
150 bt_self_component_sink_configuration *config,
151 const bt_value *params, void *init_method_data);
152
153 BT_HIDDEN
154 void details_finalize(bt_self_component_sink *component);
155
156 BT_HIDDEN
157 bt_component_class_sink_graph_is_configured_method_status details_graph_is_configured(
158 bt_self_component_sink *comp);
159
160 BT_HIDDEN
161 bt_component_class_sink_consume_method_status details_consume(bt_self_component_sink *component);
162
163 BT_HIDDEN
164 void details_destroy_details_trace_class_meta(
165 struct details_trace_class_meta *details_trace_class_meta);
166
167 BT_HIDDEN
168 struct details_trace_class_meta *details_create_details_trace_class_meta(void);
169
170 #endif /* BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H */
This page took 0.033106 seconds and 4 git commands to generate.