Commit | Line | Data |
---|---|---|
55478183 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
55478183 | 3 | * |
0235b0db | 4 | * Copyright 2019 Philippe Proulx <pproulx@efficios.com> |
55478183 PP |
5 | */ |
6 | ||
0235b0db MJ |
7 | #ifndef BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H |
8 | #define BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H | |
9 | ||
55478183 PP |
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 | */ | |
2054a0d1 | 41 | bt_listener_id tc_destruction_listener_id; |
55478183 PP |
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 | */ | |
2054a0d1 | 56 | bt_listener_id trace_destruction_listener_id; |
55478183 PP |
57 | }; |
58 | ||
59 | /* A `sink.text.details` component */ | |
60 | struct details_comp { | |
6c868a3a | 61 | bt_logging_level log_level; |
d400b9e6 | 62 | bt_self_component *self_comp; |
4a2156a5 | 63 | uint64_t mip_version; |
6c868a3a | 64 | |
55478183 PP |
65 | /* Component's configuration */ |
66 | struct { | |
cc413248 PP |
67 | /* Write data objects */ |
68 | bool with_data; | |
69 | ||
55478183 PP |
70 | /* Write metadata objects */ |
71 | bool with_meta; | |
72 | ||
73 | /* | |
74 | * Compact mode: each line is a single message, and | |
75 | * there are no extended message properties and | |
76 | * event/packet fields. `with_meta` can still be true in | |
77 | * compact mode, printing the full metadata objects, but | |
78 | * making the messages compact. | |
79 | */ | |
80 | bool compact; | |
81 | ||
82 | /* Colorize output */ | |
83 | bool with_color; | |
84 | ||
85 | /* Write message's time */ | |
86 | bool with_time; | |
87 | ||
55478183 PP |
88 | /* Write trace's name */ |
89 | bool with_trace_name; | |
90 | ||
6563da7a SM |
91 | /* Write stream class's namespace */ |
92 | bool with_stream_class_ns; | |
93 | ||
55478183 PP |
94 | /* Write stream class's name */ |
95 | bool with_stream_class_name; | |
96 | ||
97 | /* Write stream's name */ | |
98 | bool with_stream_name; | |
99 | ||
100 | /* Write UUID */ | |
101 | bool with_uuid; | |
c0177597 PP |
102 | |
103 | /* Write UID */ | |
104 | bool with_uid; | |
55478183 PP |
105 | } cfg; |
106 | ||
107 | /* | |
108 | * `const bt_trace_class *` (weak) -> | |
109 | * `struct details_trace_class_meta *` (owned by this) | |
110 | * | |
111 | * The key (trace class object) is weak. An entry is added, if | |
112 | * `cfg.with_meta` above is true, when first encountering a | |
113 | * trace class. An entry is removed when a trace class is | |
114 | * destroyed or when the component is finalized. | |
115 | */ | |
116 | GHashTable *meta; | |
117 | ||
118 | /* | |
119 | * `const bt_trace *` (weak) -> | |
120 | * `struct details_trace *` (owner by this) | |
121 | * | |
122 | * This hash table associates a trace object to a unique ID | |
123 | * within the lifetime of this component. This is used to easily | |
124 | * follow the messages of a given trace/stream when reading the | |
125 | * text output of the component. We cannot use the actual stream | |
126 | * ID properties for this because many streams can share the | |
127 | * same ID (with different stream classes or different traces). | |
128 | * | |
129 | * When adding an entry, the unique ID to use is | |
130 | * `next_unique_trace_id`. | |
131 | * | |
132 | * An entry is added when first encountering a trace. An entry | |
133 | * is removed when a trace is destroyed or when the component is | |
134 | * finalized. | |
135 | */ | |
136 | GHashTable *traces; | |
137 | uint32_t next_unique_trace_id; | |
138 | ||
139 | /* Upstream message iterator */ | |
9a2c8b8e | 140 | bt_message_iterator *msg_iter; |
55478183 PP |
141 | |
142 | /* | |
143 | * True if this component printed something. This is used to | |
144 | * prepend a newline to the next message string instead of | |
145 | * appending it so that the last printed message is not followed | |
146 | * with an empty line. | |
147 | */ | |
148 | bool printed_something; | |
149 | ||
150 | /* Current message's output buffer */ | |
151 | GString *str; | |
152 | }; | |
153 | ||
497c1e20 SM |
154 | bt_component_class_get_supported_mip_versions_method_status |
155 | details_supported_mip_versions(bt_self_component_class_sink *self_component_class, | |
156 | const bt_value *params, void *initialize_method_data, | |
157 | bt_logging_level logging_level, | |
158 | bt_integer_range_set_unsigned *supported_versions); | |
159 | ||
21a9f056 | 160 | bt_component_class_initialize_method_status details_init( |
55478183 | 161 | bt_self_component_sink *component, |
59225a3e | 162 | bt_self_component_sink_configuration *config, |
55478183 PP |
163 | const bt_value *params, void *init_method_data); |
164 | ||
55478183 PP |
165 | void details_finalize(bt_self_component_sink *component); |
166 | ||
d24d5663 | 167 | bt_component_class_sink_graph_is_configured_method_status details_graph_is_configured( |
55478183 PP |
168 | bt_self_component_sink *comp); |
169 | ||
d24d5663 | 170 | bt_component_class_sink_consume_method_status details_consume(bt_self_component_sink *component); |
55478183 | 171 | |
55478183 PP |
172 | void details_destroy_details_trace_class_meta( |
173 | struct details_trace_class_meta *details_trace_class_meta); | |
174 | ||
55478183 PP |
175 | struct details_trace_class_meta *details_create_details_trace_class_meta(void); |
176 | ||
177 | #endif /* BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H */ |