Commit | Line | Data |
---|---|---|
af9a82eb | 1 | /* |
af9a82eb | 2 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
f504043c | 3 | * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
af9a82eb JG |
4 | * |
5 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 | * SOFTWARE. | |
24 | */ | |
25 | ||
3fadfbc0 | 26 | #include <babeltrace2/babeltrace.h> |
578e048b MJ |
27 | #include "compat/bitfield.h" |
28 | #include "common/common.h" | |
6162e6b7 | 29 | #include "common/uuid.h" |
578e048b MJ |
30 | #include "compat/time.h" |
31 | #include "common/assert.h" | |
6a18b281 | 32 | #include <inttypes.h> |
93a4161c | 33 | #include <ctype.h> |
c4f23e30 | 34 | #include <stdbool.h> |
91d81473 | 35 | #include <string.h> |
3228cc1d | 36 | #include "pretty.h" |
af9a82eb | 37 | |
1556a1af JG |
38 | #define NSEC_PER_SEC 1000000000LL |
39 | ||
04609487 PP |
40 | static char color_name[32]; |
41 | static char color_field_name[32]; | |
42 | static char color_rst[32]; | |
43 | static char color_string_value[32]; | |
44 | static char color_number_value[32]; | |
45 | static char color_enum_mapping_name[32]; | |
46 | static char color_unknown[32]; | |
47 | static char color_event_name[32]; | |
48 | static char color_timestamp[32]; | |
ad96d936 | 49 | |
af9a82eb JG |
50 | struct timestamp { |
51 | int64_t real_timestamp; /* Relative to UNIX epoch. */ | |
605e1019 | 52 | uint64_t clock_snapshot; /* In cycles. */ |
af9a82eb JG |
53 | }; |
54 | ||
6a18b281 | 55 | static |
d94d92ac | 56 | int print_field(struct pretty_component *pretty, |
2f84c7be | 57 | const bt_field *field, bool print_names); |
6a18b281 | 58 | |
ad96d936 | 59 | static |
3228cc1d | 60 | void print_name_equal(struct pretty_component *pretty, const char *name) |
ad96d936 | 61 | { |
3228cc1d | 62 | if (pretty->use_colors) { |
04609487 | 63 | bt_common_g_string_append(pretty->string, color_name); |
dd61c4ed | 64 | bt_common_g_string_append(pretty->string, name); |
04609487 | 65 | bt_common_g_string_append(pretty->string, color_rst); |
ad96d936 | 66 | } else { |
dd61c4ed | 67 | bt_common_g_string_append(pretty->string, name); |
ad96d936 | 68 | } |
dd61c4ed | 69 | bt_common_g_string_append(pretty->string, " = "); |
ad96d936 PP |
70 | } |
71 | ||
72 | static | |
3228cc1d | 73 | void print_field_name_equal(struct pretty_component *pretty, const char *name) |
ad96d936 | 74 | { |
3228cc1d | 75 | if (pretty->use_colors) { |
04609487 | 76 | bt_common_g_string_append(pretty->string, color_field_name); |
dd61c4ed | 77 | bt_common_g_string_append(pretty->string, name); |
04609487 | 78 | bt_common_g_string_append(pretty->string, color_rst); |
ad96d936 | 79 | } else { |
dd61c4ed MD |
80 | bt_common_g_string_append(pretty->string, name); |
81 | } | |
82 | bt_common_g_string_append(pretty->string, " = "); | |
ad96d936 PP |
83 | } |
84 | ||
af9a82eb | 85 | static |
3228cc1d | 86 | void print_timestamp_cycles(struct pretty_component *pretty, |
9c202476 | 87 | const bt_clock_snapshot *clock_snapshot, bool update_last) |
af9a82eb | 88 | { |
1556a1af | 89 | uint64_t cycles; |
1556a1af | 90 | |
605e1019 | 91 | cycles = bt_clock_snapshot_get_value(clock_snapshot); |
f354b1e1 | 92 | bt_common_g_string_append_printf(pretty->string, "%020" PRIu64, cycles); |
3af83b5a | 93 | |
9c202476 PP |
94 | if (update_last) { |
95 | if (pretty->last_cycles_timestamp != -1ULL) { | |
96 | pretty->delta_cycles = cycles - pretty->last_cycles_timestamp; | |
97 | } | |
2c091c04 | 98 | |
9c202476 PP |
99 | pretty->last_cycles_timestamp = cycles; |
100 | } | |
af9a82eb JG |
101 | } |
102 | ||
103 | static | |
3228cc1d | 104 | void print_timestamp_wall(struct pretty_component *pretty, |
9c202476 | 105 | const bt_clock_snapshot *clock_snapshot, bool update_last) |
af9a82eb | 106 | { |
1556a1af | 107 | int ret; |
1556a1af JG |
108 | int64_t ts_nsec = 0; /* add configurable offset */ |
109 | int64_t ts_sec = 0; /* add configurable offset */ | |
110 | uint64_t ts_sec_abs, ts_nsec_abs; | |
111 | bool is_negative; | |
af9a82eb | 112 | |
605e1019 | 113 | if (!clock_snapshot) { |
dd61c4ed | 114 | bt_common_g_string_append(pretty->string, "??:??:??.?????????"); |
1556a1af JG |
115 | return; |
116 | } | |
117 | ||
605e1019 | 118 | ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &ts_nsec); |
1556a1af | 119 | if (ret) { |
5280f742 | 120 | // TODO: log, this is unexpected |
dd61c4ed | 121 | bt_common_g_string_append(pretty->string, "Error"); |
1556a1af JG |
122 | return; |
123 | } | |
124 | ||
9c202476 PP |
125 | if (update_last) { |
126 | if (pretty->last_real_timestamp != -1ULL) { | |
127 | pretty->delta_real_timestamp = ts_nsec - pretty->last_real_timestamp; | |
128 | } | |
129 | ||
130 | pretty->last_real_timestamp = ts_nsec; | |
3af83b5a | 131 | } |
3af83b5a | 132 | |
1556a1af JG |
133 | ts_sec += ts_nsec / NSEC_PER_SEC; |
134 | ts_nsec = ts_nsec % NSEC_PER_SEC; | |
5280f742 | 135 | |
1556a1af JG |
136 | if (ts_sec >= 0 && ts_nsec >= 0) { |
137 | is_negative = false; | |
138 | ts_sec_abs = ts_sec; | |
139 | ts_nsec_abs = ts_nsec; | |
140 | } else if (ts_sec > 0 && ts_nsec < 0) { | |
141 | is_negative = false; | |
142 | ts_sec_abs = ts_sec - 1; | |
143 | ts_nsec_abs = NSEC_PER_SEC + ts_nsec; | |
144 | } else if (ts_sec == 0 && ts_nsec < 0) { | |
145 | is_negative = true; | |
146 | ts_sec_abs = ts_sec; | |
147 | ts_nsec_abs = -ts_nsec; | |
148 | } else if (ts_sec < 0 && ts_nsec > 0) { | |
149 | is_negative = true; | |
150 | ts_sec_abs = -(ts_sec + 1); | |
151 | ts_nsec_abs = NSEC_PER_SEC - ts_nsec; | |
152 | } else if (ts_sec < 0 && ts_nsec == 0) { | |
153 | is_negative = true; | |
154 | ts_sec_abs = -ts_sec; | |
155 | ts_nsec_abs = ts_nsec; | |
156 | } else { /* (ts_sec < 0 && ts_nsec < 0) */ | |
157 | is_negative = true; | |
158 | ts_sec_abs = -ts_sec; | |
159 | ts_nsec_abs = -ts_nsec; | |
160 | } | |
161 | ||
3228cc1d | 162 | if (!pretty->options.clock_seconds) { |
1556a1af JG |
163 | struct tm tm; |
164 | time_t time_s = (time_t) ts_sec_abs; | |
165 | ||
18adbd19 | 166 | if (is_negative && !pretty->negative_timestamp_warning_done) { |
5280f742 | 167 | // TODO: log instead |
1556a1af | 168 | fprintf(stderr, "[warning] Fallback to [sec.ns] to print negative time value. Use --clock-seconds.\n"); |
18adbd19 | 169 | pretty->negative_timestamp_warning_done = true; |
1556a1af JG |
170 | goto seconds; |
171 | } | |
172 | ||
3228cc1d | 173 | if (!pretty->options.clock_gmt) { |
1556a1af JG |
174 | struct tm *res; |
175 | ||
58a2480d | 176 | res = bt_localtime_r(&time_s, &tm); |
1556a1af | 177 | if (!res) { |
5280f742 | 178 | // TODO: log instead |
1556a1af JG |
179 | fprintf(stderr, "[warning] Unable to get localtime.\n"); |
180 | goto seconds; | |
181 | } | |
182 | } else { | |
183 | struct tm *res; | |
184 | ||
58a2480d | 185 | res = bt_gmtime_r(&time_s, &tm); |
1556a1af | 186 | if (!res) { |
5280f742 | 187 | // TODO: log instead |
1556a1af JG |
188 | fprintf(stderr, "[warning] Unable to get gmtime.\n"); |
189 | goto seconds; | |
190 | } | |
191 | } | |
3228cc1d | 192 | if (pretty->options.clock_date) { |
1556a1af JG |
193 | char timestr[26]; |
194 | size_t res; | |
195 | ||
196 | /* Print date and time */ | |
197 | res = strftime(timestr, sizeof(timestr), | |
4d2a94f1 | 198 | "%Y-%m-%d ", &tm); |
1556a1af | 199 | if (!res) { |
5280f742 | 200 | // TODO: log instead |
1556a1af JG |
201 | fprintf(stderr, "[warning] Unable to print ascii time.\n"); |
202 | goto seconds; | |
203 | } | |
5280f742 | 204 | |
dd61c4ed | 205 | bt_common_g_string_append(pretty->string, timestr); |
1556a1af | 206 | } |
5280f742 | 207 | |
1556a1af | 208 | /* Print time in HH:MM:SS.ns */ |
f354b1e1 | 209 | bt_common_g_string_append_printf(pretty->string, |
5280f742 PP |
210 | "%02d:%02d:%02d.%09" PRIu64, tm.tm_hour, tm.tm_min, |
211 | tm.tm_sec, ts_nsec_abs); | |
1556a1af JG |
212 | goto end; |
213 | } | |
214 | seconds: | |
f354b1e1 | 215 | bt_common_g_string_append_printf(pretty->string, "%s%" PRId64 ".%09" PRIu64, |
5280f742 | 216 | is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs); |
1556a1af JG |
217 | end: |
218 | return; | |
af9a82eb JG |
219 | } |
220 | ||
221 | static | |
d94d92ac | 222 | int print_event_timestamp(struct pretty_component *pretty, |
2c091c04 | 223 | const bt_message *event_msg, bool *start_line) |
af9a82eb | 224 | { |
3228cc1d | 225 | bool print_names = pretty->options.print_header_field_names; |
d94d92ac | 226 | int ret = 0; |
605e1019 | 227 | const bt_clock_snapshot *clock_snapshot = NULL; |
af9a82eb | 228 | |
81c25620 PP |
229 | if (!bt_message_event_borrow_stream_class_default_clock_class_const( |
230 | event_msg)) { | |
2c091c04 | 231 | /* No default clock class: skip the timestamp without an error */ |
f504043c MD |
232 | goto end; |
233 | } | |
d9f65f09 | 234 | |
0cbc2c33 | 235 | clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(event_msg); |
af9a82eb | 236 | |
ad96d936 | 237 | if (print_names) { |
3228cc1d | 238 | print_name_equal(pretty, "timestamp"); |
ad96d936 | 239 | } else { |
dd61c4ed | 240 | bt_common_g_string_append(pretty->string, "["); |
ad96d936 | 241 | } |
3228cc1d | 242 | if (pretty->use_colors) { |
04609487 | 243 | bt_common_g_string_append(pretty->string, color_timestamp); |
ad96d936 | 244 | } |
3228cc1d | 245 | if (pretty->options.print_timestamp_cycles) { |
9c202476 | 246 | print_timestamp_cycles(pretty, clock_snapshot, true); |
af9a82eb | 247 | } else { |
9c202476 | 248 | print_timestamp_wall(pretty, clock_snapshot, true); |
af9a82eb | 249 | } |
3228cc1d | 250 | if (pretty->use_colors) { |
04609487 | 251 | bt_common_g_string_append(pretty->string, color_rst); |
ad96d936 | 252 | } |
af9a82eb | 253 | |
c3c30b08 | 254 | if (!print_names) |
dd61c4ed | 255 | bt_common_g_string_append(pretty->string, "] "); |
c3c30b08 | 256 | |
3228cc1d | 257 | if (pretty->options.print_delta_field) { |
ad96d936 | 258 | if (print_names) { |
dd61c4ed | 259 | bt_common_g_string_append(pretty->string, ", "); |
3228cc1d | 260 | print_name_equal(pretty, "delta"); |
ad96d936 | 261 | } else { |
dd61c4ed | 262 | bt_common_g_string_append(pretty->string, "("); |
ad96d936 | 263 | } |
3228cc1d PP |
264 | if (pretty->options.print_timestamp_cycles) { |
265 | if (pretty->delta_cycles == -1ULL) { | |
dd61c4ed | 266 | bt_common_g_string_append(pretty->string, |
c6a871e9 | 267 | "+??????????\?\?"); /* Not a trigraph. */ |
3af83b5a | 268 | } else { |
f354b1e1 | 269 | bt_common_g_string_append_printf(pretty->string, |
5280f742 | 270 | "+%012" PRIu64, pretty->delta_cycles); |
3af83b5a MD |
271 | } |
272 | } else { | |
3228cc1d | 273 | if (pretty->delta_real_timestamp != -1ULL) { |
3af83b5a | 274 | uint64_t delta_sec, delta_nsec, delta; |
f504043c | 275 | |
3228cc1d | 276 | delta = pretty->delta_real_timestamp; |
3af83b5a MD |
277 | delta_sec = delta / NSEC_PER_SEC; |
278 | delta_nsec = delta % NSEC_PER_SEC; | |
f354b1e1 | 279 | bt_common_g_string_append_printf(pretty->string, |
5280f742 | 280 | "+%" PRIu64 ".%09" PRIu64, |
3af83b5a MD |
281 | delta_sec, delta_nsec); |
282 | } else { | |
dd61c4ed | 283 | bt_common_g_string_append(pretty->string, "+?.?????????"); |
3af83b5a MD |
284 | } |
285 | } | |
286 | if (!print_names) { | |
dd61c4ed | 287 | bt_common_g_string_append(pretty->string, ") "); |
3af83b5a MD |
288 | } |
289 | } | |
290 | *start_line = !print_names; | |
f504043c | 291 | |
af9a82eb | 292 | end: |
af9a82eb JG |
293 | return ret; |
294 | } | |
295 | ||
6a18b281 | 296 | static |
d94d92ac | 297 | int print_event_header(struct pretty_component *pretty, |
2c091c04 | 298 | const bt_message *event_msg) |
af9a82eb | 299 | { |
3228cc1d | 300 | bool print_names = pretty->options.print_header_field_names; |
d94d92ac | 301 | int ret = 0; |
b19ff26f | 302 | const bt_event_class *event_class = NULL; |
b19ff26f PP |
303 | const bt_stream *stream = NULL; |
304 | const bt_trace *trace = NULL; | |
2c091c04 | 305 | const bt_event *event = bt_message_event_borrow_event_const(event_msg); |
64925bba | 306 | const char *ev_name; |
60535549 | 307 | int dom_print = 0; |
4cdfc5e8 | 308 | bt_property_availability prop_avail; |
af9a82eb | 309 | |
40f4ba76 | 310 | event_class = bt_event_borrow_class_const(event); |
26fc5aed | 311 | stream = bt_event_borrow_stream_const(event); |
862ca4ed | 312 | trace = bt_stream_borrow_trace_const(stream); |
2c091c04 | 313 | ret = print_event_timestamp(pretty, event_msg, &pretty->start_line); |
d94d92ac | 314 | if (ret) { |
af9a82eb JG |
315 | goto end; |
316 | } | |
3228cc1d | 317 | if (pretty->options.print_trace_field) { |
c3c30b08 MD |
318 | const char *name; |
319 | ||
862ca4ed | 320 | name = bt_trace_get_name(trace); |
c3c30b08 | 321 | if (name) { |
3228cc1d | 322 | if (!pretty->start_line) { |
dd61c4ed | 323 | bt_common_g_string_append(pretty->string, ", "); |
c3c30b08 | 324 | } |
c3c30b08 | 325 | if (print_names) { |
3228cc1d | 326 | print_name_equal(pretty, "trace"); |
c3c30b08 | 327 | } |
5280f742 | 328 | |
dd61c4ed | 329 | bt_common_g_string_append(pretty->string, name); |
5280f742 | 330 | |
22b7fdc6 | 331 | if (print_names) { |
dd61c4ed | 332 | bt_common_g_string_append(pretty->string, ", "); |
60535549 | 333 | } |
c3c30b08 MD |
334 | } |
335 | } | |
3228cc1d | 336 | if (pretty->options.print_trace_hostname_field) { |
b19ff26f | 337 | const bt_value *hostname_str; |
c3c30b08 | 338 | |
335a2da5 PP |
339 | hostname_str = bt_trace_borrow_environment_entry_value_by_name_const( |
340 | trace, "hostname"); | |
c3c30b08 MD |
341 | if (hostname_str) { |
342 | const char *str; | |
343 | ||
3228cc1d | 344 | if (!pretty->start_line) { |
dd61c4ed | 345 | bt_common_g_string_append(pretty->string, ", "); |
c3c30b08 | 346 | } |
c3c30b08 | 347 | if (print_names) { |
3228cc1d | 348 | print_name_equal(pretty, "trace:hostname"); |
c3c30b08 | 349 | } |
601b0d3c | 350 | str = bt_value_string_get(hostname_str); |
dd61c4ed | 351 | bt_common_g_string_append(pretty->string, str); |
60535549 | 352 | dom_print = 1; |
c3c30b08 MD |
353 | } |
354 | } | |
3228cc1d | 355 | if (pretty->options.print_trace_domain_field) { |
b19ff26f | 356 | const bt_value *domain_str; |
c3c30b08 | 357 | |
335a2da5 PP |
358 | domain_str = bt_trace_borrow_environment_entry_value_by_name_const( |
359 | trace, "domain"); | |
c3c30b08 MD |
360 | if (domain_str) { |
361 | const char *str; | |
362 | ||
3228cc1d | 363 | if (!pretty->start_line) { |
dd61c4ed | 364 | bt_common_g_string_append(pretty->string, ", "); |
c3c30b08 | 365 | } |
c3c30b08 | 366 | if (print_names) { |
3228cc1d | 367 | print_name_equal(pretty, "trace:domain"); |
60535549 | 368 | } else if (dom_print) { |
dd61c4ed | 369 | bt_common_g_string_append(pretty->string, ":"); |
c3c30b08 | 370 | } |
601b0d3c | 371 | str = bt_value_string_get(domain_str); |
dd61c4ed | 372 | bt_common_g_string_append(pretty->string, str); |
60535549 | 373 | dom_print = 1; |
c3c30b08 MD |
374 | } |
375 | } | |
3228cc1d | 376 | if (pretty->options.print_trace_procname_field) { |
b19ff26f | 377 | const bt_value *procname_str; |
c3c30b08 | 378 | |
335a2da5 PP |
379 | procname_str = bt_trace_borrow_environment_entry_value_by_name_const( |
380 | trace, "procname"); | |
c3c30b08 MD |
381 | if (procname_str) { |
382 | const char *str; | |
383 | ||
3228cc1d | 384 | if (!pretty->start_line) { |
dd61c4ed | 385 | bt_common_g_string_append(pretty->string, ", "); |
c3c30b08 | 386 | } |
c3c30b08 | 387 | if (print_names) { |
3228cc1d | 388 | print_name_equal(pretty, "trace:procname"); |
60535549 | 389 | } else if (dom_print) { |
dd61c4ed | 390 | bt_common_g_string_append(pretty->string, ":"); |
c3c30b08 | 391 | } |
601b0d3c | 392 | str = bt_value_string_get(procname_str); |
dd61c4ed | 393 | bt_common_g_string_append(pretty->string, str); |
60535549 | 394 | dom_print = 1; |
c3c30b08 MD |
395 | } |
396 | } | |
3228cc1d | 397 | if (pretty->options.print_trace_vpid_field) { |
b19ff26f | 398 | const bt_value *vpid_value; |
c3c30b08 | 399 | |
335a2da5 PP |
400 | vpid_value = bt_trace_borrow_environment_entry_value_by_name_const( |
401 | trace, "vpid"); | |
c3c30b08 MD |
402 | if (vpid_value) { |
403 | int64_t value; | |
404 | ||
3228cc1d | 405 | if (!pretty->start_line) { |
dd61c4ed | 406 | bt_common_g_string_append(pretty->string, ", "); |
c3c30b08 | 407 | } |
c3c30b08 | 408 | if (print_names) { |
3228cc1d | 409 | print_name_equal(pretty, "trace:vpid"); |
60535549 | 410 | } else if (dom_print) { |
dd61c4ed | 411 | bt_common_g_string_append(pretty->string, ":"); |
c3c30b08 | 412 | } |
9c08c816 | 413 | value = bt_value_integer_signed_get(vpid_value); |
f354b1e1 | 414 | bt_common_g_string_append_printf(pretty->string, |
601b0d3c | 415 | "(%" PRId64 ")", value); |
60535549 | 416 | dom_print = 1; |
c3c30b08 MD |
417 | } |
418 | } | |
3228cc1d | 419 | if (pretty->options.print_loglevel_field) { |
cf76ce92 | 420 | static const char *log_level_names[] = { |
50842bdc PP |
421 | [ BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY ] = "TRACE_EMERG", |
422 | [ BT_EVENT_CLASS_LOG_LEVEL_ALERT ] = "TRACE_ALERT", | |
423 | [ BT_EVENT_CLASS_LOG_LEVEL_CRITICAL ] = "TRACE_CRIT", | |
424 | [ BT_EVENT_CLASS_LOG_LEVEL_ERROR ] = "TRACE_ERR", | |
425 | [ BT_EVENT_CLASS_LOG_LEVEL_WARNING ] = "TRACE_WARNING", | |
426 | [ BT_EVENT_CLASS_LOG_LEVEL_NOTICE ] = "TRACE_NOTICE", | |
427 | [ BT_EVENT_CLASS_LOG_LEVEL_INFO ] = "TRACE_INFO", | |
428 | [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM ] = "TRACE_DEBUG_SYSTEM", | |
429 | [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM ] = "TRACE_DEBUG_PROGRAM", | |
430 | [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS ] = "TRACE_DEBUG_PROCESS", | |
431 | [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE ] = "TRACE_DEBUG_MODULE", | |
432 | [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT ] = "TRACE_DEBUG_UNIT", | |
433 | [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION ] = "TRACE_DEBUG_FUNCTION", | |
434 | [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE ] = "TRACE_DEBUG_LINE", | |
435 | [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG ] = "TRACE_DEBUG", | |
cf76ce92 | 436 | }; |
4cdfc5e8 | 437 | bt_event_class_log_level log_level; |
cf76ce92 PP |
438 | const char *log_level_str = NULL; |
439 | ||
44c440bc PP |
440 | prop_avail = bt_event_class_get_log_level(event_class, |
441 | &log_level); | |
442 | if (prop_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) { | |
cf76ce92 | 443 | log_level_str = log_level_names[log_level]; |
98b15851 | 444 | BT_ASSERT_DBG(log_level_str); |
c3c30b08 | 445 | |
3228cc1d | 446 | if (!pretty->start_line) { |
dd61c4ed | 447 | bt_common_g_string_append(pretty->string, ", "); |
c3c30b08 | 448 | } |
c3c30b08 | 449 | if (print_names) { |
3228cc1d | 450 | print_name_equal(pretty, "loglevel"); |
60535549 | 451 | } else if (dom_print) { |
dd61c4ed | 452 | bt_common_g_string_append(pretty->string, ":"); |
c3c30b08 | 453 | } |
cf76ce92 | 454 | |
dd61c4ed | 455 | bt_common_g_string_append(pretty->string, log_level_str); |
f354b1e1 | 456 | bt_common_g_string_append_printf( |
cf76ce92 | 457 | pretty->string, " (%d)", (int) log_level); |
60535549 | 458 | dom_print = 1; |
c3c30b08 MD |
459 | } |
460 | } | |
3228cc1d | 461 | if (pretty->options.print_emf_field) { |
cf76ce92 | 462 | const char *uri_str; |
c3c30b08 | 463 | |
50842bdc | 464 | uri_str = bt_event_class_get_emf_uri(event_class); |
c3c30b08 | 465 | if (uri_str) { |
3228cc1d | 466 | if (!pretty->start_line) { |
dd61c4ed | 467 | bt_common_g_string_append(pretty->string, ", "); |
c3c30b08 | 468 | } |
c3c30b08 | 469 | if (print_names) { |
3228cc1d | 470 | print_name_equal(pretty, "model.emf.uri"); |
60535549 | 471 | } else if (dom_print) { |
dd61c4ed | 472 | bt_common_g_string_append(pretty->string, ":"); |
c3c30b08 | 473 | } |
c3c30b08 | 474 | |
dd61c4ed | 475 | bt_common_g_string_append(pretty->string, uri_str); |
60535549 | 476 | dom_print = 1; |
c3c30b08 MD |
477 | } |
478 | } | |
60535549 | 479 | if (dom_print && !print_names) { |
dd61c4ed | 480 | bt_common_g_string_append(pretty->string, " "); |
60535549 | 481 | } |
3228cc1d | 482 | if (!pretty->start_line) { |
dd61c4ed | 483 | bt_common_g_string_append(pretty->string, ", "); |
c3c30b08 | 484 | } |
3228cc1d | 485 | pretty->start_line = true; |
6a18b281 | 486 | if (print_names) { |
3228cc1d | 487 | print_name_equal(pretty, "name"); |
ad96d936 | 488 | } |
64925bba | 489 | ev_name = bt_event_class_get_name(event_class); |
3228cc1d | 490 | if (pretty->use_colors) { |
64925bba | 491 | if (ev_name) { |
dd61c4ed | 492 | bt_common_g_string_append(pretty->string, |
04609487 | 493 | color_event_name); |
64925bba | 494 | } else { |
dd61c4ed | 495 | bt_common_g_string_append(pretty->string, |
04609487 | 496 | color_unknown); |
64925bba PP |
497 | } |
498 | } | |
499 | if (ev_name) { | |
dd61c4ed | 500 | bt_common_g_string_append(pretty->string, ev_name); |
64925bba | 501 | } else { |
dd61c4ed | 502 | bt_common_g_string_append(pretty->string, "<unknown>"); |
6a18b281 | 503 | } |
3228cc1d | 504 | if (pretty->use_colors) { |
04609487 | 505 | bt_common_g_string_append(pretty->string, color_rst); |
ad96d936 | 506 | } |
60535549 | 507 | if (!print_names) { |
dd61c4ed | 508 | bt_common_g_string_append(pretty->string, ": "); |
60535549 | 509 | } else { |
dd61c4ed | 510 | bt_common_g_string_append(pretty->string, ", "); |
60535549 | 511 | } |
a82e90e8 | 512 | |
af9a82eb | 513 | end: |
6a18b281 MD |
514 | return ret; |
515 | } | |
516 | ||
517 | static | |
d94d92ac | 518 | int print_integer(struct pretty_component *pretty, |
b19ff26f | 519 | const bt_field *field) |
6a18b281 | 520 | { |
d94d92ac | 521 | int ret = 0; |
4cdfc5e8 | 522 | bt_field_class_integer_preferred_display_base base; |
b19ff26f | 523 | const bt_field_class *int_fc; |
6a18b281 MD |
524 | union { |
525 | uint64_t u; | |
526 | int64_t s; | |
527 | } v; | |
ad96d936 | 528 | bool rst_color = false; |
4cdfc5e8 | 529 | bt_field_class_type ft_type; |
6a18b281 | 530 | |
40f4ba76 | 531 | int_fc = bt_field_borrow_class_const(field); |
98b15851 | 532 | BT_ASSERT_DBG(int_fc); |
864cad70 | 533 | ft_type = bt_field_get_class_type(field); |
ebdb6693 PP |
534 | if (bt_field_class_type_is(ft_type, |
535 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) { | |
9c08c816 | 536 | v.u = bt_field_integer_unsigned_get_value(field); |
6a18b281 | 537 | } else { |
9c08c816 | 538 | v.s = bt_field_integer_signed_get_value(field); |
6a18b281 MD |
539 | } |
540 | ||
3228cc1d | 541 | if (pretty->use_colors) { |
04609487 | 542 | bt_common_g_string_append(pretty->string, color_number_value); |
ad96d936 PP |
543 | rst_color = true; |
544 | } | |
545 | ||
5cd6d0e5 | 546 | base = bt_field_class_integer_get_preferred_display_base(int_fc); |
6a18b281 | 547 | switch (base) { |
5cd6d0e5 | 548 | case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY: |
6a18b281 MD |
549 | { |
550 | int bitnr, len; | |
551 | ||
5cd6d0e5 | 552 | len = bt_field_class_integer_get_field_value_range(int_fc); |
dd61c4ed | 553 | bt_common_g_string_append(pretty->string, "0b"); |
7f140ae8 | 554 | _bt_safe_lshift(v.u, 64 - len); |
6a18b281 | 555 | for (bitnr = 0; bitnr < len; bitnr++) { |
242ed509 MD |
556 | bt_common_g_string_append_c(pretty->string, |
557 | (v.u & (1ULL << 63)) ? '1' : '0'); | |
7f140ae8 | 558 | _bt_safe_lshift(v.u, 1); |
6a18b281 MD |
559 | } |
560 | break; | |
561 | } | |
5cd6d0e5 | 562 | case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL: |
6a18b281 | 563 | { |
ebdb6693 PP |
564 | if (bt_field_class_type_is(ft_type, |
565 | BT_FIELD_CLASS_TYPE_SIGNED_INTEGER)) { | |
6a18b281 MD |
566 | int len; |
567 | ||
5cd6d0e5 PP |
568 | len = bt_field_class_integer_get_field_value_range( |
569 | int_fc); | |
6a18b281 MD |
570 | if (len < 64) { |
571 | size_t rounded_len; | |
572 | ||
98b15851 | 573 | BT_ASSERT_DBG(len != 0); |
6a18b281 MD |
574 | /* Round length to the nearest 3-bit */ |
575 | rounded_len = (((len - 1) / 3) + 1) * 3; | |
576 | v.u &= ((uint64_t) 1 << rounded_len) - 1; | |
577 | } | |
578 | } | |
579 | ||
f354b1e1 | 580 | bt_common_g_string_append_printf(pretty->string, "0%" PRIo64, v.u); |
6a18b281 MD |
581 | break; |
582 | } | |
5cd6d0e5 | 583 | case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL: |
ebdb6693 PP |
584 | if (bt_field_class_type_is(ft_type, |
585 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) { | |
f354b1e1 | 586 | bt_common_g_string_append_printf(pretty->string, "%" PRIu64, v.u); |
6a18b281 | 587 | } else { |
f354b1e1 | 588 | bt_common_g_string_append_printf(pretty->string, "%" PRId64, v.s); |
6a18b281 MD |
589 | } |
590 | break; | |
5cd6d0e5 | 591 | case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL: |
6a18b281 MD |
592 | { |
593 | int len; | |
594 | ||
5cd6d0e5 | 595 | len = bt_field_class_integer_get_field_value_range(int_fc); |
6a18b281 MD |
596 | if (len < 64) { |
597 | /* Round length to the nearest nibble */ | |
598 | uint8_t rounded_len = ((len + 3) & ~0x3); | |
599 | ||
600 | v.u &= ((uint64_t) 1 << rounded_len) - 1; | |
601 | } | |
602 | ||
f354b1e1 | 603 | bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64, v.u); |
6a18b281 MD |
604 | break; |
605 | } | |
606 | default: | |
d94d92ac | 607 | ret = -1; |
6a18b281 MD |
608 | goto end; |
609 | } | |
610 | end: | |
ad96d936 | 611 | if (rst_color) { |
04609487 | 612 | bt_common_g_string_append(pretty->string, color_rst); |
ad96d936 | 613 | } |
6a18b281 MD |
614 | return ret; |
615 | } | |
616 | ||
93a4161c | 617 | static |
3228cc1d | 618 | void print_escape_string(struct pretty_component *pretty, const char *str) |
93a4161c JD |
619 | { |
620 | int i; | |
621 | ||
dd61c4ed | 622 | bt_common_g_string_append_c(pretty->string, '"'); |
5280f742 | 623 | |
93a4161c JD |
624 | for (i = 0; i < strlen(str); i++) { |
625 | /* Escape sequences not recognized by iscntrl(). */ | |
626 | switch (str[i]) { | |
627 | case '\\': | |
dd61c4ed | 628 | bt_common_g_string_append(pretty->string, "\\\\"); |
93a4161c JD |
629 | continue; |
630 | case '\'': | |
dd61c4ed | 631 | bt_common_g_string_append(pretty->string, "\\\'"); |
93a4161c JD |
632 | continue; |
633 | case '\"': | |
dd61c4ed | 634 | bt_common_g_string_append(pretty->string, "\\\""); |
93a4161c JD |
635 | continue; |
636 | case '\?': | |
dd61c4ed | 637 | bt_common_g_string_append(pretty->string, "\\\?"); |
93a4161c JD |
638 | continue; |
639 | } | |
640 | ||
641 | /* Standard characters. */ | |
642 | if (!iscntrl(str[i])) { | |
dd61c4ed | 643 | bt_common_g_string_append_c(pretty->string, str[i]); |
93a4161c JD |
644 | continue; |
645 | } | |
646 | ||
647 | switch (str[i]) { | |
648 | case '\0': | |
dd61c4ed | 649 | bt_common_g_string_append(pretty->string, "\\0"); |
93a4161c JD |
650 | break; |
651 | case '\a': | |
dd61c4ed | 652 | bt_common_g_string_append(pretty->string, "\\a"); |
93a4161c JD |
653 | break; |
654 | case '\b': | |
dd61c4ed | 655 | bt_common_g_string_append(pretty->string, "\\b"); |
93a4161c JD |
656 | break; |
657 | case '\e': | |
dd61c4ed | 658 | bt_common_g_string_append(pretty->string, "\\e"); |
93a4161c JD |
659 | break; |
660 | case '\f': | |
dd61c4ed | 661 | bt_common_g_string_append(pretty->string, "\\f"); |
93a4161c JD |
662 | break; |
663 | case '\n': | |
dd61c4ed | 664 | bt_common_g_string_append(pretty->string, "\\n"); |
93a4161c JD |
665 | break; |
666 | case '\r': | |
dd61c4ed | 667 | bt_common_g_string_append(pretty->string, "\\r"); |
93a4161c JD |
668 | break; |
669 | case '\t': | |
dd61c4ed | 670 | bt_common_g_string_append(pretty->string, "\\t"); |
93a4161c JD |
671 | break; |
672 | case '\v': | |
dd61c4ed | 673 | bt_common_g_string_append(pretty->string, "\\v"); |
93a4161c JD |
674 | break; |
675 | default: | |
676 | /* Unhandled control-sequence, print as hex. */ | |
f354b1e1 | 677 | bt_common_g_string_append_printf(pretty->string, "\\x%02x", str[i]); |
93a4161c JD |
678 | break; |
679 | } | |
680 | } | |
5280f742 | 681 | |
dd61c4ed | 682 | bt_common_g_string_append_c(pretty->string, '"'); |
93a4161c JD |
683 | } |
684 | ||
6a18b281 | 685 | static |
d94d92ac | 686 | int print_enum(struct pretty_component *pretty, |
b19ff26f | 687 | const bt_field *field) |
6a18b281 | 688 | { |
d94d92ac | 689 | int ret = 0; |
5cd6d0e5 | 690 | bt_field_class_enumeration_mapping_label_array label_array; |
44c440bc PP |
691 | uint64_t label_count; |
692 | uint64_t i; | |
96e8f959 | 693 | |
864cad70 PP |
694 | switch (bt_field_get_class_type(field)) { |
695 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: | |
9c08c816 | 696 | ret = bt_field_enumeration_unsigned_get_mapping_labels(field, |
44c440bc PP |
697 | &label_array, &label_count); |
698 | break; | |
864cad70 | 699 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: |
9c08c816 | 700 | ret = bt_field_enumeration_signed_get_mapping_labels(field, |
44c440bc PP |
701 | &label_array, &label_count); |
702 | break; | |
703 | default: | |
498e7994 | 704 | bt_common_abort(); |
96e8f959 | 705 | } |
44c440bc PP |
706 | |
707 | if (ret) { | |
d94d92ac | 708 | ret = -1; |
96e8f959 MD |
709 | goto end; |
710 | } | |
44c440bc | 711 | |
dd61c4ed | 712 | bt_common_g_string_append(pretty->string, "( "); |
44c440bc | 713 | if (label_count == 0) { |
83ef3205 | 714 | if (pretty->use_colors) { |
04609487 | 715 | bt_common_g_string_append(pretty->string, color_unknown); |
83ef3205 | 716 | } |
dd61c4ed | 717 | bt_common_g_string_append(pretty->string, "<unknown>"); |
83ef3205 | 718 | if (pretty->use_colors) { |
04609487 | 719 | bt_common_g_string_append(pretty->string, color_rst); |
83ef3205 MD |
720 | } |
721 | goto skip_loop; | |
96e8f959 | 722 | } |
44c440bc PP |
723 | for (i = 0; i < label_count; i++) { |
724 | const char *mapping_name = label_array[i]; | |
96e8f959 | 725 | |
55c68a1a | 726 | if (i != 0) { |
dd61c4ed | 727 | bt_common_g_string_append(pretty->string, ", "); |
44c440bc | 728 | } |
3228cc1d | 729 | if (pretty->use_colors) { |
04609487 | 730 | bt_common_g_string_append(pretty->string, color_enum_mapping_name); |
ad96d936 | 731 | } |
3228cc1d PP |
732 | print_escape_string(pretty, mapping_name); |
733 | if (pretty->use_colors) { | |
04609487 | 734 | bt_common_g_string_append(pretty->string, color_rst); |
ad96d936 | 735 | } |
96e8f959 | 736 | } |
83ef3205 | 737 | skip_loop: |
dd61c4ed | 738 | bt_common_g_string_append(pretty->string, " : container = "); |
312c056a | 739 | ret = print_integer(pretty, field); |
d94d92ac | 740 | if (ret != 0) { |
6a18b281 MD |
741 | goto end; |
742 | } | |
dd61c4ed | 743 | bt_common_g_string_append(pretty->string, " )"); |
6a18b281 | 744 | end: |
6a18b281 MD |
745 | return ret; |
746 | } | |
747 | ||
748 | static | |
d94d92ac | 749 | int print_struct_field(struct pretty_component *pretty, |
b19ff26f PP |
750 | const bt_field *_struct, |
751 | const bt_field_class *struct_class, | |
2f84c7be | 752 | uint64_t i, bool print_names, uint64_t *nr_printed_fields) |
6a18b281 | 753 | { |
d94d92ac | 754 | int ret = 0; |
6a18b281 | 755 | const char *field_name; |
b19ff26f | 756 | const bt_field *field = NULL; |
1e6fd1d7 | 757 | const bt_field_class_structure_member *member; |
6a18b281 | 758 | |
40f4ba76 | 759 | field = bt_field_structure_borrow_member_field_by_index_const(_struct, i); |
6a18b281 | 760 | if (!field) { |
d94d92ac | 761 | ret = -1; |
6a18b281 MD |
762 | goto end; |
763 | } | |
44c440bc | 764 | |
1e6fd1d7 PP |
765 | member = bt_field_class_structure_borrow_member_by_index_const( |
766 | struct_class, i); | |
767 | field_name = bt_field_class_structure_member_get_name(member); | |
6a18b281 | 768 | |
2b4c4a7c | 769 | if (*nr_printed_fields > 0) { |
dd61c4ed | 770 | bt_common_g_string_append(pretty->string, ", "); |
6a18b281 | 771 | } else { |
dd61c4ed | 772 | bt_common_g_string_append(pretty->string, " "); |
6a18b281 MD |
773 | } |
774 | if (print_names) { | |
6acddae3 | 775 | print_field_name_equal(pretty, field_name); |
6a18b281 | 776 | } |
2f84c7be | 777 | ret = print_field(pretty, field, print_names); |
2b4c4a7c | 778 | *nr_printed_fields += 1; |
a82e90e8 | 779 | |
6a18b281 | 780 | end: |
6a18b281 MD |
781 | return ret; |
782 | } | |
783 | ||
784 | static | |
d94d92ac | 785 | int print_struct(struct pretty_component *pretty, |
2f84c7be | 786 | const bt_field *_struct, bool print_names) |
6a18b281 | 787 | { |
d94d92ac | 788 | int ret = 0; |
b19ff26f | 789 | const bt_field_class *struct_class = NULL; |
44c440bc | 790 | uint64_t nr_fields, i, nr_printed_fields; |
6a18b281 | 791 | |
40f4ba76 | 792 | struct_class = bt_field_borrow_class_const(_struct); |
5cd6d0e5 | 793 | nr_fields = bt_field_class_structure_get_member_count(struct_class); |
53dc85fa | 794 | |
dd61c4ed | 795 | bt_common_g_string_append(pretty->string, "{"); |
3228cc1d | 796 | pretty->depth++; |
2b4c4a7c | 797 | nr_printed_fields = 0; |
6a18b281 | 798 | for (i = 0; i < nr_fields; i++) { |
5cd6d0e5 | 799 | ret = print_struct_field(pretty, _struct, struct_class, i, |
2f84c7be | 800 | print_names, &nr_printed_fields); |
d94d92ac | 801 | if (ret != 0) { |
6a18b281 MD |
802 | goto end; |
803 | } | |
804 | } | |
3228cc1d | 805 | pretty->depth--; |
dd61c4ed | 806 | bt_common_g_string_append(pretty->string, " }"); |
a82e90e8 | 807 | |
6a18b281 | 808 | end: |
6a18b281 MD |
809 | return ret; |
810 | } | |
811 | ||
812 | static | |
d94d92ac | 813 | int print_array_field(struct pretty_component *pretty, |
b19ff26f | 814 | const bt_field *array, uint64_t i, bool print_names) |
6a18b281 | 815 | { |
b19ff26f | 816 | const bt_field *field = NULL; |
6a18b281 | 817 | |
44c440bc | 818 | if (i != 0) { |
dd61c4ed | 819 | bt_common_g_string_append(pretty->string, ", "); |
44c440bc | 820 | } else { |
dd61c4ed | 821 | bt_common_g_string_append(pretty->string, " "); |
6a18b281 | 822 | } |
44c440bc | 823 | if (print_names) { |
f354b1e1 | 824 | bt_common_g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); |
6a18b281 | 825 | } |
a82e90e8 | 826 | |
40f4ba76 | 827 | field = bt_field_array_borrow_element_field_by_index_const(array, i); |
98b15851 | 828 | BT_ASSERT_DBG(field); |
2f84c7be | 829 | return print_field(pretty, field, print_names); |
6a18b281 MD |
830 | } |
831 | ||
832 | static | |
d94d92ac | 833 | int print_array(struct pretty_component *pretty, |
b19ff26f | 834 | const bt_field *array, bool print_names) |
6a18b281 | 835 | { |
d94d92ac | 836 | int ret = 0; |
44c440bc | 837 | uint64_t len; |
6a18b281 | 838 | uint64_t i; |
6a18b281 | 839 | |
44c440bc | 840 | len = bt_field_array_get_length(array); |
dd61c4ed | 841 | bt_common_g_string_append(pretty->string, "["); |
3228cc1d | 842 | pretty->depth++; |
6a18b281 | 843 | for (i = 0; i < len; i++) { |
44c440bc | 844 | ret = print_array_field(pretty, array, i, print_names); |
d94d92ac | 845 | if (ret != 0) { |
6a18b281 MD |
846 | goto end; |
847 | } | |
848 | } | |
3228cc1d | 849 | pretty->depth--; |
dd61c4ed | 850 | bt_common_g_string_append(pretty->string, " ]"); |
a82e90e8 | 851 | |
6a18b281 | 852 | end: |
6a18b281 MD |
853 | return ret; |
854 | } | |
855 | ||
856 | static | |
d94d92ac | 857 | int print_sequence_field(struct pretty_component *pretty, |
b19ff26f | 858 | const bt_field *seq, uint64_t i, bool print_names) |
6a18b281 | 859 | { |
b19ff26f | 860 | const bt_field *field = NULL; |
6a18b281 | 861 | |
44c440bc | 862 | if (i != 0) { |
dd61c4ed | 863 | bt_common_g_string_append(pretty->string, ", "); |
44c440bc | 864 | } else { |
dd61c4ed | 865 | bt_common_g_string_append(pretty->string, " "); |
6a18b281 | 866 | } |
44c440bc | 867 | if (print_names) { |
f354b1e1 | 868 | bt_common_g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); |
6a18b281 | 869 | } |
a82e90e8 | 870 | |
40f4ba76 | 871 | field = bt_field_array_borrow_element_field_by_index_const(seq, i); |
98b15851 | 872 | BT_ASSERT_DBG(field); |
2f84c7be | 873 | return print_field(pretty, field, print_names); |
6a18b281 MD |
874 | } |
875 | ||
876 | static | |
d94d92ac | 877 | int print_sequence(struct pretty_component *pretty, |
b19ff26f | 878 | const bt_field *seq, bool print_names) |
6a18b281 | 879 | { |
d94d92ac | 880 | int ret = 0; |
44c440bc | 881 | uint64_t len; |
6a18b281 | 882 | uint64_t i; |
6a18b281 | 883 | |
44c440bc | 884 | len = bt_field_array_get_length(seq); |
dd61c4ed | 885 | bt_common_g_string_append(pretty->string, "["); |
6a18b281 | 886 | |
3228cc1d | 887 | pretty->depth++; |
6a18b281 | 888 | for (i = 0; i < len; i++) { |
44c440bc | 889 | ret = print_sequence_field(pretty, seq, i, print_names); |
d94d92ac | 890 | if (ret != 0) { |
6a18b281 MD |
891 | goto end; |
892 | } | |
893 | } | |
3228cc1d | 894 | pretty->depth--; |
dd61c4ed | 895 | bt_common_g_string_append(pretty->string, " ]"); |
a82e90e8 | 896 | |
6a18b281 | 897 | end: |
6a18b281 MD |
898 | return ret; |
899 | } | |
900 | ||
51e61f06 PP |
901 | static |
902 | int print_option(struct pretty_component *pretty, | |
903 | const bt_field *option, bool print_names) | |
904 | { | |
905 | int ret = 0; | |
906 | const bt_field *field = NULL; | |
907 | ||
908 | field = bt_field_option_borrow_field_const(option); | |
909 | if (field) { | |
910 | bt_common_g_string_append(pretty->string, "{ "); | |
911 | pretty->depth++; | |
912 | if (print_names) { | |
913 | // TODO: find tag's name using field path | |
914 | // print_field_name_equal(pretty, tag_choice); | |
915 | } | |
916 | ret = print_field(pretty, field, print_names); | |
917 | if (ret != 0) { | |
918 | goto end; | |
919 | } | |
920 | pretty->depth--; | |
921 | bt_common_g_string_append(pretty->string, " }"); | |
922 | } else { | |
923 | bt_common_g_string_append(pretty->string, "<none>"); | |
924 | } | |
925 | ||
926 | end: | |
927 | return ret; | |
928 | } | |
929 | ||
6a18b281 | 930 | static |
d94d92ac | 931 | int print_variant(struct pretty_component *pretty, |
b19ff26f | 932 | const bt_field *variant, bool print_names) |
6a18b281 | 933 | { |
d94d92ac | 934 | int ret = 0; |
b19ff26f | 935 | const bt_field *field = NULL; |
6a18b281 | 936 | |
40f4ba76 | 937 | field = bt_field_variant_borrow_selected_option_field_const(variant); |
98b15851 | 938 | BT_ASSERT_DBG(field); |
dd61c4ed | 939 | bt_common_g_string_append(pretty->string, "{ "); |
3228cc1d | 940 | pretty->depth++; |
6a18b281 | 941 | if (print_names) { |
44c440bc PP |
942 | // TODO: find tag's name using field path |
943 | // print_field_name_equal(pretty, tag_choice); | |
6a18b281 | 944 | } |
2f84c7be | 945 | ret = print_field(pretty, field, print_names); |
d94d92ac | 946 | if (ret != 0) { |
6a18b281 MD |
947 | goto end; |
948 | } | |
3228cc1d | 949 | pretty->depth--; |
dd61c4ed | 950 | bt_common_g_string_append(pretty->string, " }"); |
a82e90e8 | 951 | |
6a18b281 | 952 | end: |
6a18b281 MD |
953 | return ret; |
954 | } | |
955 | ||
956 | static | |
d94d92ac | 957 | int print_field(struct pretty_component *pretty, |
2f84c7be | 958 | const bt_field *field, bool print_names) |
6a18b281 | 959 | { |
4cdfc5e8 | 960 | bt_field_class_type class_id; |
6a18b281 | 961 | |
864cad70 | 962 | class_id = bt_field_get_class_type(field); |
ebdb6693 | 963 | if (class_id == BT_FIELD_CLASS_TYPE_BOOL) { |
ff87f7c6 PP |
964 | bt_bool v; |
965 | const char *text; | |
966 | ||
967 | v = bt_field_bool_get_value(field); | |
968 | if (pretty->use_colors) { | |
04609487 | 969 | bt_common_g_string_append(pretty->string, color_number_value); |
ff87f7c6 PP |
970 | } |
971 | if (v) { | |
972 | text = "true"; | |
973 | } else { | |
974 | text = "false"; | |
975 | } | |
976 | bt_common_g_string_append(pretty->string, text); | |
977 | if (pretty->use_colors) { | |
04609487 | 978 | bt_common_g_string_append(pretty->string, color_rst); |
ff87f7c6 PP |
979 | } |
980 | return 0; | |
ebdb6693 | 981 | } else if (class_id == BT_FIELD_CLASS_TYPE_BIT_ARRAY) { |
6be72e6c PP |
982 | uint64_t v = bt_field_bit_array_get_value_as_integer(field); |
983 | ||
984 | if (pretty->use_colors) { | |
985 | bt_common_g_string_append(pretty->string, | |
04609487 | 986 | color_number_value); |
6be72e6c PP |
987 | } |
988 | bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64, | |
989 | v); | |
990 | if (pretty->use_colors) { | |
04609487 | 991 | bt_common_g_string_append(pretty->string, color_rst); |
6be72e6c PP |
992 | } |
993 | return 0; | |
ebdb6693 PP |
994 | } else if (bt_field_class_type_is(class_id, |
995 | BT_FIELD_CLASS_TYPE_ENUMERATION)) { | |
996 | return print_enum(pretty, field); | |
997 | } else if (bt_field_class_type_is(class_id, | |
998 | BT_FIELD_CLASS_TYPE_INTEGER)) { | |
3228cc1d | 999 | return print_integer(pretty, field); |
ebdb6693 PP |
1000 | } else if (bt_field_class_type_is(class_id, |
1001 | BT_FIELD_CLASS_TYPE_REAL)) { | |
6a18b281 MD |
1002 | double v; |
1003 | ||
fe4df857 | 1004 | if (class_id == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) { |
ebdb6693 | 1005 | v = bt_field_real_single_precision_get_value(field); |
fe4df857 FD |
1006 | } else { |
1007 | v = bt_field_real_double_precision_get_value(field); | |
1008 | } | |
1009 | ||
3228cc1d | 1010 | if (pretty->use_colors) { |
04609487 | 1011 | bt_common_g_string_append(pretty->string, color_number_value); |
ad96d936 | 1012 | } |
f354b1e1 | 1013 | bt_common_g_string_append_printf(pretty->string, "%g", v); |
3228cc1d | 1014 | if (pretty->use_colors) { |
04609487 | 1015 | bt_common_g_string_append(pretty->string, color_rst); |
ad96d936 | 1016 | } |
d94d92ac | 1017 | return 0; |
ebdb6693 | 1018 | } else if (class_id == BT_FIELD_CLASS_TYPE_STRING) { |
95a518bf JG |
1019 | const char *str; |
1020 | ||
50842bdc | 1021 | str = bt_field_string_get_value(field); |
95a518bf | 1022 | if (!str) { |
d94d92ac | 1023 | return -1; |
95a518bf JG |
1024 | } |
1025 | ||
3228cc1d | 1026 | if (pretty->use_colors) { |
04609487 | 1027 | bt_common_g_string_append(pretty->string, color_string_value); |
ad96d936 | 1028 | } |
95a518bf | 1029 | print_escape_string(pretty, str); |
3228cc1d | 1030 | if (pretty->use_colors) { |
04609487 | 1031 | bt_common_g_string_append(pretty->string, color_rst); |
ad96d936 | 1032 | } |
d94d92ac | 1033 | return 0; |
ebdb6693 | 1034 | } else if (class_id == BT_FIELD_CLASS_TYPE_STRUCTURE) { |
2f84c7be | 1035 | return print_struct(pretty, field, print_names); |
ebdb6693 PP |
1036 | } else if (bt_field_class_type_is(class_id, |
1037 | BT_FIELD_CLASS_TYPE_OPTION)) { | |
51e61f06 | 1038 | return print_option(pretty, field, print_names); |
ebdb6693 PP |
1039 | } else if (bt_field_class_type_is(class_id, |
1040 | BT_FIELD_CLASS_TYPE_VARIANT)) { | |
3228cc1d | 1041 | return print_variant(pretty, field, print_names); |
ebdb6693 | 1042 | } else if (class_id == BT_FIELD_CLASS_TYPE_STATIC_ARRAY) { |
3228cc1d | 1043 | return print_array(pretty, field, print_names); |
ebdb6693 PP |
1044 | } else if (bt_field_class_type_is(class_id, |
1045 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)) { | |
3228cc1d | 1046 | return print_sequence(pretty, field, print_names); |
ebdb6693 | 1047 | } else { |
5280f742 | 1048 | // TODO: log instead |
5cd6d0e5 | 1049 | fprintf(pretty->err, "[error] Unknown type id: %d\n", (int) class_id); |
d94d92ac | 1050 | return -1; |
6a18b281 MD |
1051 | } |
1052 | } | |
1053 | ||
1054 | static | |
d94d92ac | 1055 | int print_stream_packet_context(struct pretty_component *pretty, |
b19ff26f | 1056 | const bt_event *event) |
6a18b281 | 1057 | { |
d94d92ac | 1058 | int ret = 0; |
b19ff26f PP |
1059 | const bt_packet *packet = NULL; |
1060 | const bt_field *main_field = NULL; | |
6a18b281 | 1061 | |
40f4ba76 | 1062 | packet = bt_event_borrow_packet_const(event); |
6a18b281 | 1063 | if (!packet) { |
6a18b281 MD |
1064 | goto end; |
1065 | } | |
40f4ba76 | 1066 | main_field = bt_packet_borrow_context_field_const(packet); |
6a18b281 | 1067 | if (!main_field) { |
6a18b281 MD |
1068 | goto end; |
1069 | } | |
3228cc1d | 1070 | if (!pretty->start_line) { |
dd61c4ed | 1071 | bt_common_g_string_append(pretty->string, ", "); |
6e1bc0df | 1072 | } |
3228cc1d PP |
1073 | pretty->start_line = false; |
1074 | if (pretty->options.print_scope_field_names) { | |
1075 | print_name_equal(pretty, "stream.packet.context"); | |
6a18b281 | 1076 | } |
3228cc1d | 1077 | ret = print_field(pretty, main_field, |
2f84c7be | 1078 | pretty->options.print_context_field_names); |
a82e90e8 | 1079 | |
6a18b281 | 1080 | end: |
6a18b281 MD |
1081 | return ret; |
1082 | } | |
1083 | ||
6a18b281 | 1084 | static |
d94d92ac | 1085 | int print_stream_event_context(struct pretty_component *pretty, |
b19ff26f | 1086 | const bt_event *event) |
6a18b281 | 1087 | { |
d94d92ac | 1088 | int ret = 0; |
b19ff26f | 1089 | const bt_field *main_field = NULL; |
6a18b281 | 1090 | |
40f4ba76 | 1091 | main_field = bt_event_borrow_common_context_field_const(event); |
6a18b281 | 1092 | if (!main_field) { |
6a18b281 MD |
1093 | goto end; |
1094 | } | |
3228cc1d | 1095 | if (!pretty->start_line) { |
dd61c4ed | 1096 | bt_common_g_string_append(pretty->string, ", "); |
6e1bc0df | 1097 | } |
3228cc1d PP |
1098 | pretty->start_line = false; |
1099 | if (pretty->options.print_scope_field_names) { | |
1100 | print_name_equal(pretty, "stream.event.context"); | |
6a18b281 | 1101 | } |
3228cc1d | 1102 | ret = print_field(pretty, main_field, |
2f84c7be | 1103 | pretty->options.print_context_field_names); |
a82e90e8 | 1104 | |
6a18b281 | 1105 | end: |
6a18b281 MD |
1106 | return ret; |
1107 | } | |
1108 | ||
1109 | static | |
d94d92ac | 1110 | int print_event_context(struct pretty_component *pretty, |
b19ff26f | 1111 | const bt_event *event) |
6a18b281 | 1112 | { |
d94d92ac | 1113 | int ret = 0; |
b19ff26f | 1114 | const bt_field *main_field = NULL; |
6a18b281 | 1115 | |
40f4ba76 | 1116 | main_field = bt_event_borrow_specific_context_field_const(event); |
6a18b281 | 1117 | if (!main_field) { |
6a18b281 MD |
1118 | goto end; |
1119 | } | |
3228cc1d | 1120 | if (!pretty->start_line) { |
dd61c4ed | 1121 | bt_common_g_string_append(pretty->string, ", "); |
6e1bc0df | 1122 | } |
3228cc1d PP |
1123 | pretty->start_line = false; |
1124 | if (pretty->options.print_scope_field_names) { | |
1125 | print_name_equal(pretty, "event.context"); | |
6a18b281 | 1126 | } |
3228cc1d | 1127 | ret = print_field(pretty, main_field, |
2f84c7be | 1128 | pretty->options.print_context_field_names); |
a82e90e8 | 1129 | |
6a18b281 | 1130 | end: |
6a18b281 MD |
1131 | return ret; |
1132 | } | |
1133 | ||
1134 | static | |
d94d92ac | 1135 | int print_event_payload(struct pretty_component *pretty, |
b19ff26f | 1136 | const bt_event *event) |
6a18b281 | 1137 | { |
d94d92ac | 1138 | int ret = 0; |
b19ff26f | 1139 | const bt_field *main_field = NULL; |
6a18b281 | 1140 | |
40f4ba76 | 1141 | main_field = bt_event_borrow_payload_field_const(event); |
6a18b281 | 1142 | if (!main_field) { |
6a18b281 MD |
1143 | goto end; |
1144 | } | |
3228cc1d | 1145 | if (!pretty->start_line) { |
dd61c4ed | 1146 | bt_common_g_string_append(pretty->string, ", "); |
6e1bc0df | 1147 | } |
3228cc1d PP |
1148 | pretty->start_line = false; |
1149 | if (pretty->options.print_scope_field_names) { | |
1150 | print_name_equal(pretty, "event.fields"); | |
6a18b281 | 1151 | } |
3228cc1d | 1152 | ret = print_field(pretty, main_field, |
2f84c7be | 1153 | pretty->options.print_payload_field_names); |
a82e90e8 | 1154 | |
6a18b281 | 1155 | end: |
af9a82eb JG |
1156 | return ret; |
1157 | } | |
1158 | ||
08899d39 | 1159 | static |
0f6bea4e | 1160 | int flush_buf(FILE *stream, struct pretty_component *pretty) |
08899d39 PP |
1161 | { |
1162 | int ret = 0; | |
1163 | ||
1164 | if (pretty->string->len == 0) { | |
1165 | goto end; | |
1166 | } | |
1167 | ||
0f6bea4e | 1168 | if (fwrite(pretty->string->str, pretty->string->len, 1, stream) != 1) { |
08899d39 PP |
1169 | ret = -1; |
1170 | } | |
1171 | ||
1172 | end: | |
1173 | return ret; | |
1174 | } | |
1175 | ||
af9a82eb | 1176 | BT_HIDDEN |
d94d92ac | 1177 | int pretty_print_event(struct pretty_component *pretty, |
d6e69534 | 1178 | const bt_message *event_msg) |
af9a82eb | 1179 | { |
d94d92ac | 1180 | int ret; |
b19ff26f | 1181 | const bt_event *event = |
d6e69534 | 1182 | bt_message_event_borrow_event_const(event_msg); |
af9a82eb | 1183 | |
98b15851 | 1184 | BT_ASSERT_DBG(event); |
3228cc1d | 1185 | pretty->start_line = true; |
5280f742 | 1186 | g_string_assign(pretty->string, ""); |
2c091c04 | 1187 | ret = print_event_header(pretty, event_msg); |
d94d92ac | 1188 | if (ret != 0) { |
af9a82eb JG |
1189 | goto end; |
1190 | } | |
6a18b281 | 1191 | |
3228cc1d | 1192 | ret = print_stream_packet_context(pretty, event); |
d94d92ac | 1193 | if (ret != 0) { |
6a18b281 MD |
1194 | goto end; |
1195 | } | |
6a18b281 | 1196 | |
3228cc1d | 1197 | ret = print_stream_event_context(pretty, event); |
d94d92ac | 1198 | if (ret != 0) { |
6a18b281 MD |
1199 | goto end; |
1200 | } | |
6a18b281 | 1201 | |
3228cc1d | 1202 | ret = print_event_context(pretty, event); |
d94d92ac | 1203 | if (ret != 0) { |
6a18b281 MD |
1204 | goto end; |
1205 | } | |
6a18b281 | 1206 | |
3228cc1d | 1207 | ret = print_event_payload(pretty, event); |
d94d92ac | 1208 | if (ret != 0) { |
6a18b281 MD |
1209 | goto end; |
1210 | } | |
af9a82eb | 1211 | |
dd61c4ed | 1212 | bt_common_g_string_append_c(pretty->string, '\n'); |
0f6bea4e | 1213 | if (flush_buf(pretty->out, pretty)) { |
d94d92ac | 1214 | ret = -1; |
5280f742 PP |
1215 | goto end; |
1216 | } | |
1217 | ||
af9a82eb JG |
1218 | end: |
1219 | return ret; | |
1220 | } | |
0f6bea4e PP |
1221 | |
1222 | static | |
8e53bed4 PP |
1223 | int print_discarded_elements_msg(struct pretty_component *pretty, |
1224 | const bt_stream *stream, | |
1225 | const bt_clock_snapshot *begin_clock_snapshot, | |
1226 | const bt_clock_snapshot *end_clock_snapshot, | |
0f6bea4e PP |
1227 | uint64_t count, const char *elem_type) |
1228 | { | |
d94d92ac | 1229 | int ret = 0; |
b19ff26f PP |
1230 | const bt_stream_class *stream_class = NULL; |
1231 | const bt_trace *trace = NULL; | |
0f6bea4e PP |
1232 | const char *stream_name; |
1233 | const char *trace_name; | |
8e53bed4 | 1234 | bt_uuid trace_uuid; |
0f6bea4e PP |
1235 | int64_t stream_class_id; |
1236 | int64_t stream_id; | |
697f479d | 1237 | const char *init_msg; |
0f6bea4e PP |
1238 | |
1239 | /* Stream name */ | |
0f6bea4e | 1240 | stream_name = bt_stream_get_name(stream); |
8e53bed4 PP |
1241 | if (!stream_name) { |
1242 | stream_name = "(unknown)"; | |
1243 | } | |
0f6bea4e PP |
1244 | |
1245 | /* Stream class ID */ | |
40f4ba76 | 1246 | stream_class = bt_stream_borrow_class_const(stream); |
0f6bea4e PP |
1247 | BT_ASSERT(stream_class); |
1248 | stream_class_id = bt_stream_class_get_id(stream_class); | |
1249 | ||
1250 | /* Stream ID */ | |
1251 | stream_id = bt_stream_get_id(stream); | |
1252 | ||
1253 | /* Trace name */ | |
8e53bed4 | 1254 | trace = bt_stream_borrow_trace_const(stream); |
0f6bea4e PP |
1255 | BT_ASSERT(trace); |
1256 | trace_name = bt_trace_get_name(trace); | |
1257 | if (!trace_name) { | |
1258 | trace_name = "(unknown)"; | |
1259 | } | |
1260 | ||
1261 | /* Trace UUID */ | |
335a2da5 | 1262 | trace_uuid = bt_trace_get_uuid(trace); |
0f6bea4e PP |
1263 | |
1264 | /* Format message */ | |
1265 | g_string_assign(pretty->string, ""); | |
697f479d PP |
1266 | |
1267 | if (count == UINT64_C(-1)) { | |
1268 | init_msg = "Tracer may have discarded"; | |
1269 | } else { | |
1270 | init_msg = "Tracer discarded"; | |
1271 | } | |
1272 | ||
f354b1e1 | 1273 | bt_common_g_string_append_printf(pretty->string, |
697f479d | 1274 | "%s%sWARNING%s%s: %s ", |
0f6bea4e PP |
1275 | bt_common_color_fg_yellow(), |
1276 | bt_common_color_bold(), | |
1277 | bt_common_color_reset(), | |
697f479d | 1278 | bt_common_color_fg_yellow(), init_msg); |
8e53bed4 PP |
1279 | |
1280 | if (count == UINT64_C(-1)) { | |
f354b1e1 | 1281 | bt_common_g_string_append_printf(pretty->string, "%ss", elem_type); |
8e53bed4 | 1282 | } else { |
f354b1e1 | 1283 | bt_common_g_string_append_printf(pretty->string, |
8e53bed4 PP |
1284 | "%" PRIu64 " %s%s", count, elem_type, |
1285 | count == 1 ? "" : "s"); | |
1286 | } | |
0f6bea4e | 1287 | |
dd61c4ed | 1288 | bt_common_g_string_append_c(pretty->string, ' '); |
3f2f6b21 | 1289 | |
605e1019 | 1290 | if (begin_clock_snapshot && end_clock_snapshot) { |
dd61c4ed | 1291 | bt_common_g_string_append(pretty->string, "between ["); |
9c202476 | 1292 | print_timestamp_wall(pretty, begin_clock_snapshot, false); |
dd61c4ed | 1293 | bt_common_g_string_append(pretty->string, "] and ["); |
9c202476 | 1294 | print_timestamp_wall(pretty, end_clock_snapshot, false); |
dd61c4ed | 1295 | bt_common_g_string_append(pretty->string, "]"); |
0f6bea4e | 1296 | } else { |
dd61c4ed | 1297 | bt_common_g_string_append(pretty->string, "(unknown time range)"); |
0f6bea4e PP |
1298 | } |
1299 | ||
f354b1e1 | 1300 | bt_common_g_string_append_printf(pretty->string, " in trace \"%s\" ", trace_name); |
0f6bea4e PP |
1301 | |
1302 | if (trace_uuid) { | |
f354b1e1 | 1303 | bt_common_g_string_append_printf(pretty->string, |
6162e6b7 MJ |
1304 | "(UUID: " BT_UUID_FMT ") ", |
1305 | BT_UUID_FMT_VALUES(trace_uuid)); | |
0f6bea4e | 1306 | } else { |
dd61c4ed | 1307 | bt_common_g_string_append(pretty->string, "(no UUID) "); |
0f6bea4e PP |
1308 | } |
1309 | ||
f354b1e1 | 1310 | bt_common_g_string_append_printf(pretty->string, |
8e53bed4 | 1311 | "within stream \"%s\" (stream class ID: %" PRIu64 ", ", |
0f6bea4e PP |
1312 | stream_name, stream_class_id); |
1313 | ||
1314 | if (stream_id >= 0) { | |
f354b1e1 | 1315 | bt_common_g_string_append_printf(pretty->string, |
8e53bed4 | 1316 | "stream ID: %" PRIu64, stream_id); |
0f6bea4e | 1317 | } else { |
dd61c4ed | 1318 | bt_common_g_string_append(pretty->string, "no stream ID"); |
0f6bea4e PP |
1319 | } |
1320 | ||
f354b1e1 | 1321 | bt_common_g_string_append_printf(pretty->string, ").%s\n", |
0f6bea4e PP |
1322 | bt_common_color_reset()); |
1323 | ||
1324 | /* | |
1325 | * Print to standard error stream to remain backward compatible | |
1326 | * with Babeltrace 1. | |
1327 | */ | |
1328 | if (flush_buf(stderr, pretty)) { | |
d94d92ac | 1329 | ret = -1; |
0f6bea4e PP |
1330 | } |
1331 | ||
1332 | return ret; | |
1333 | } | |
1334 | ||
1335 | BT_HIDDEN | |
8e53bed4 PP |
1336 | int pretty_print_discarded_items(struct pretty_component *pretty, |
1337 | const bt_message *msg) | |
0f6bea4e | 1338 | { |
8e53bed4 PP |
1339 | const bt_clock_snapshot *begin = NULL; |
1340 | const bt_clock_snapshot *end = NULL; | |
1341 | const bt_stream *stream; | |
1342 | const bt_stream_class *stream_class; | |
1343 | uint64_t count = UINT64_C(-1); | |
1344 | const char *elem_type; | |
1345 | ||
1346 | switch (bt_message_get_type(msg)) { | |
1347 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: | |
1348 | stream = bt_message_discarded_events_borrow_stream_const(msg); | |
1349 | ||
1350 | if (bt_message_discarded_events_get_count(msg, &count) == | |
1351 | BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) { | |
1352 | count = UINT64_C(-1); | |
0f6bea4e | 1353 | } |
8e53bed4 PP |
1354 | |
1355 | elem_type = "event"; | |
1356 | break; | |
1357 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: | |
1358 | stream = bt_message_discarded_packets_borrow_stream_const(msg); | |
1359 | ||
1360 | if (bt_message_discarded_packets_get_count(msg, &count) == | |
1361 | BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) { | |
1362 | count = UINT64_C(-1); | |
1363 | } | |
1364 | ||
1365 | elem_type = "packet"; | |
1366 | break; | |
1367 | default: | |
498e7994 | 1368 | bt_common_abort(); |
0f6bea4e PP |
1369 | } |
1370 | ||
8e53bed4 PP |
1371 | BT_ASSERT(stream); |
1372 | stream_class = bt_stream_borrow_class_const(stream); | |
1373 | ||
2e90378a PP |
1374 | switch (bt_message_get_type(msg)) { |
1375 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: | |
1376 | if (bt_stream_class_discarded_events_have_default_clock_snapshots( | |
1377 | stream_class)) { | |
9b24b6aa | 1378 | begin = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const( |
0cbc2c33 | 1379 | msg); |
9b24b6aa | 1380 | end = bt_message_discarded_events_borrow_end_default_clock_snapshot_const( |
0cbc2c33 | 1381 | msg); |
2e90378a PP |
1382 | } |
1383 | ||
1384 | break; | |
1385 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: | |
1386 | if (bt_stream_class_discarded_packets_have_default_clock_snapshots( | |
1387 | stream_class)) { | |
9b24b6aa | 1388 | begin = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const( |
0cbc2c33 | 1389 | msg); |
9b24b6aa | 1390 | end = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const( |
0cbc2c33 | 1391 | msg); |
0f6bea4e | 1392 | } |
2e90378a PP |
1393 | |
1394 | break; | |
1395 | default: | |
498e7994 | 1396 | bt_common_abort(); |
0f6bea4e PP |
1397 | } |
1398 | ||
8e53bed4 PP |
1399 | print_discarded_elements_msg(pretty, stream, begin, end, |
1400 | count, elem_type); | |
44c440bc | 1401 | return 0; |
0f6bea4e | 1402 | } |
04609487 PP |
1403 | |
1404 | BT_HIDDEN | |
1405 | void pretty_print_init(void) | |
1406 | { | |
1407 | strcpy(color_name, bt_common_color_bold()); | |
1408 | strcpy(color_field_name, bt_common_color_fg_cyan()); | |
1409 | strcpy(color_rst, bt_common_color_reset()); | |
1410 | strcpy(color_string_value, bt_common_color_bold()); | |
1411 | strcpy(color_number_value, bt_common_color_bold()); | |
1412 | strcpy(color_enum_mapping_name, bt_common_color_bold()); | |
1413 | strcpy(color_unknown, bt_common_color_bold()); | |
1414 | strcat(color_unknown, bt_common_color_fg_bright_red()); | |
1415 | strcpy(color_event_name, bt_common_color_bold()); | |
1416 | strcat(color_event_name, bt_common_color_fg_bright_magenta()); | |
1417 | strcpy(color_timestamp, bt_common_color_bold()); | |
1418 | strcat(color_timestamp, bt_common_color_fg_bright_yellow()); | |
1419 | } |