Commit | Line | Data |
---|---|---|
7a278c8e | 1 | /* |
2e339de1 | 2 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
f504043c | 3 | * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
7a278c8e 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 | ||
1e3400b8 FD |
26 | #define BT_LOG_TAG "PLUGIN-TEXT-PRETTY-SINK" |
27 | #include "logging.h" | |
28 | ||
71c5da58 | 29 | #include <babeltrace2/babeltrace.h> |
57952005 MJ |
30 | #include "compat/compiler.h" |
31 | #include "common/common.h" | |
bfd20a42 | 32 | #include <stdio.h> |
39cfa40f | 33 | #include <stdbool.h> |
bac67f0f | 34 | #include <glib.h> |
57952005 | 35 | #include "common/assert.h" |
6405967d | 36 | |
3228cc1d PP |
37 | #include "pretty.h" |
38 | ||
b7c70610 MJ |
39 | GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN]; |
40 | ||
6e1bc0df MD |
41 | static |
42 | const char *plugin_options[] = { | |
ad96d936 | 43 | "color", |
a0ad501b | 44 | "path", |
6e1bc0df MD |
45 | "no-delta", |
46 | "clock-cycles", | |
47 | "clock-seconds", | |
48 | "clock-date", | |
49 | "clock-gmt", | |
a263021c | 50 | "verbose", |
6e1bc0df MD |
51 | "name-default", /* show/hide */ |
52 | "name-payload", | |
53 | "name-context", | |
54 | "name-scope", | |
55 | "name-header", | |
56 | "field-default", /* show/hide */ | |
57 | "field-trace", | |
58 | "field-trace:hostname", | |
59 | "field-trace:domain", | |
60 | "field-trace:procname", | |
61 | "field-trace:vpid", | |
62 | "field-loglevel", | |
63 | "field-emf", | |
60535549 | 64 | "field-callsite", |
6e1bc0df MD |
65 | }; |
66 | ||
1043fdea PP |
67 | static |
68 | const char * const in_port_name = "in"; | |
69 | ||
bfd20a42 | 70 | static |
3228cc1d | 71 | void destroy_pretty_data(struct pretty_component *pretty) |
bac67f0f | 72 | { |
b09a5592 | 73 | bt_self_component_port_input_message_iterator_put_ref(pretty->iterator); |
5280f742 PP |
74 | |
75 | if (pretty->string) { | |
76 | (void) g_string_free(pretty->string, TRUE); | |
77 | } | |
78 | ||
79 | if (pretty->tmp_string) { | |
80 | (void) g_string_free(pretty->tmp_string, TRUE); | |
81 | } | |
82 | ||
3228cc1d | 83 | if (pretty->out != stdout) { |
77986bad JD |
84 | int ret; |
85 | ||
3228cc1d | 86 | ret = fclose(pretty->out); |
77986bad JD |
87 | if (ret) { |
88 | perror("close output file"); | |
89 | } | |
90 | } | |
3228cc1d | 91 | g_free(pretty->options.output_path); |
3228cc1d | 92 | g_free(pretty); |
bac67f0f JG |
93 | } |
94 | ||
b25bd455 | 95 | static |
3228cc1d | 96 | struct pretty_component *create_pretty(void) |
bac67f0f | 97 | { |
3228cc1d | 98 | struct pretty_component *pretty; |
541b0a11 | 99 | |
3228cc1d PP |
100 | pretty = g_new0(struct pretty_component, 1); |
101 | if (!pretty) { | |
541b0a11 JG |
102 | goto end; |
103 | } | |
3228cc1d PP |
104 | pretty->string = g_string_new(""); |
105 | if (!pretty->string) { | |
6a18b281 MD |
106 | goto error; |
107 | } | |
5280f742 PP |
108 | pretty->tmp_string = g_string_new(""); |
109 | if (!pretty->tmp_string) { | |
110 | goto error; | |
111 | } | |
541b0a11 | 112 | end: |
3228cc1d | 113 | return pretty; |
6a18b281 MD |
114 | |
115 | error: | |
3228cc1d | 116 | g_free(pretty); |
6a18b281 | 117 | return NULL; |
bac67f0f JG |
118 | } |
119 | ||
3228cc1d | 120 | BT_HIDDEN |
8eee8ea2 | 121 | void pretty_finalize(bt_self_component_sink *comp) |
b25bd455 | 122 | { |
834e9996 PP |
123 | destroy_pretty_data( |
124 | bt_self_component_get_data( | |
bb61965b | 125 | bt_self_component_sink_as_self_component(comp))); |
b25bd455 JG |
126 | } |
127 | ||
bac67f0f | 128 | static |
ee78f405 | 129 | bt_self_component_status handle_message( |
834e9996 | 130 | struct pretty_component *pretty, |
b09a5592 | 131 | const bt_message *message) |
4c1456f0 | 132 | { |
ee78f405 | 133 | bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; |
541b0a11 | 134 | |
8b45963b | 135 | BT_ASSERT(pretty); |
541b0a11 | 136 | |
b09a5592 | 137 | switch (bt_message_get_type(message)) { |
b09a5592 PP |
138 | case BT_MESSAGE_TYPE_EVENT: |
139 | if (pretty_print_event(pretty, message)) { | |
834e9996 PP |
140 | ret = BT_SELF_COMPONENT_STATUS_ERROR; |
141 | } | |
7cdc2bab | 142 | break; |
40bf6fd0 | 143 | case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: |
1e3400b8 | 144 | BT_LOGD_STR("Message iterator inactivity message."); |
7cdc2bab | 145 | break; |
22dfa677 PP |
146 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: |
147 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: | |
148 | if (pretty_print_discarded_items(pretty, message)) { | |
149 | ret = BT_SELF_COMPONENT_STATUS_ERROR; | |
150 | } | |
151 | break; | |
7cdc2bab | 152 | default: |
6ff151ad | 153 | break; |
78586d8a | 154 | } |
b5e978f4 | 155 | |
541b0a11 | 156 | return ret; |
4c1456f0 | 157 | } |
bac67f0f | 158 | |
3228cc1d | 159 | BT_HIDDEN |
1043fdea PP |
160 | bt_self_component_status pretty_graph_is_configured( |
161 | bt_self_component_sink *comp) | |
75e1829b | 162 | { |
ee78f405 | 163 | bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; |
3228cc1d | 164 | struct pretty_component *pretty; |
75e1829b | 165 | |
834e9996 | 166 | pretty = bt_self_component_get_data( |
bb61965b | 167 | bt_self_component_sink_as_self_component(comp)); |
8b45963b | 168 | BT_ASSERT(pretty); |
834e9996 | 169 | BT_ASSERT(!pretty->iterator); |
b09a5592 | 170 | pretty->iterator = bt_self_component_port_input_message_iterator_create( |
1043fdea PP |
171 | bt_self_component_sink_borrow_input_port_by_name(comp, |
172 | in_port_name)); | |
834e9996 PP |
173 | if (!pretty->iterator) { |
174 | status = BT_SELF_COMPONENT_STATUS_NOMEM; | |
75e1829b | 175 | } |
72b913fb | 176 | |
634f394c | 177 | return status; |
75e1829b JG |
178 | } |
179 | ||
3228cc1d | 180 | BT_HIDDEN |
ee78f405 | 181 | bt_self_component_status pretty_consume( |
8eee8ea2 | 182 | bt_self_component_sink *comp) |
fec2a9f2 | 183 | { |
ee78f405 | 184 | bt_self_component_status ret; |
b09a5592 PP |
185 | bt_message_array_const msgs; |
186 | bt_self_component_port_input_message_iterator *it; | |
834e9996 | 187 | struct pretty_component *pretty = bt_self_component_get_data( |
bb61965b | 188 | bt_self_component_sink_as_self_component(comp)); |
ee78f405 | 189 | bt_message_iterator_status it_ret; |
3fd7b79d PP |
190 | uint64_t count = 0; |
191 | uint64_t i = 0; | |
fec2a9f2 | 192 | |
834e9996 | 193 | it = pretty->iterator; |
b09a5592 PP |
194 | it_ret = bt_self_component_port_input_message_iterator_next(it, |
195 | &msgs, &count); | |
0d8b4d8e | 196 | |
41a2b7ae | 197 | switch (it_ret) { |
b09a5592 | 198 | case BT_MESSAGE_ITERATOR_STATUS_OK: |
834e9996 | 199 | break; |
b09a5592 | 200 | case BT_MESSAGE_ITERATOR_STATUS_NOMEM: |
834e9996 | 201 | ret = BT_SELF_COMPONENT_STATUS_NOMEM; |
41a2b7ae | 202 | goto end; |
b09a5592 | 203 | case BT_MESSAGE_ITERATOR_STATUS_AGAIN: |
834e9996 PP |
204 | ret = BT_SELF_COMPONENT_STATUS_AGAIN; |
205 | goto end; | |
b09a5592 | 206 | case BT_MESSAGE_ITERATOR_STATUS_END: |
834e9996 | 207 | ret = BT_SELF_COMPONENT_STATUS_END; |
b09a5592 | 208 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET( |
8c6884d9 | 209 | pretty->iterator); |
dfa6653c | 210 | goto end; |
dfa6653c | 211 | default: |
834e9996 | 212 | ret = BT_SELF_COMPONENT_STATUS_ERROR; |
dfa6653c | 213 | goto end; |
fec2a9f2 JG |
214 | } |
215 | ||
b09a5592 | 216 | BT_ASSERT(it_ret == BT_MESSAGE_ITERATOR_STATUS_OK); |
3fd7b79d PP |
217 | |
218 | for (i = 0; i < count; i++) { | |
b09a5592 | 219 | ret = handle_message(pretty, msgs[i]); |
3fd7b79d PP |
220 | if (ret) { |
221 | goto end; | |
222 | } | |
223 | ||
b09a5592 | 224 | bt_message_put_ref(msgs[i]); |
3fd7b79d | 225 | } |
dfa6653c | 226 | |
fec2a9f2 | 227 | end: |
3fd7b79d | 228 | for (; i < count; i++) { |
b09a5592 | 229 | bt_message_put_ref(msgs[i]); |
3fd7b79d PP |
230 | } |
231 | ||
fec2a9f2 JG |
232 | return ret; |
233 | } | |
234 | ||
6e1bc0df | 235 | static |
8eee8ea2 | 236 | int add_params_to_map(bt_value *plugin_opt_map) |
6e1bc0df | 237 | { |
834e9996 | 238 | int ret = 0; |
6e1bc0df MD |
239 | unsigned int i; |
240 | ||
241 | for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) { | |
242 | const char *key = plugin_options[i]; | |
ee78f405 | 243 | bt_value_status status; |
6e1bc0df | 244 | |
ce141536 | 245 | status = bt_value_map_insert_entry(plugin_opt_map, key, |
17582c6d | 246 | bt_value_null); |
6e1bc0df MD |
247 | switch (status) { |
248 | case BT_VALUE_STATUS_OK: | |
249 | break; | |
250 | default: | |
834e9996 | 251 | ret = -1; |
6e1bc0df MD |
252 | goto end; |
253 | } | |
254 | } | |
255 | end: | |
256 | return ret; | |
257 | } | |
258 | ||
259 | static | |
8eee8ea2 | 260 | bt_bool check_param_exists(const char *key, const bt_value *object, |
ce141536 | 261 | void *data) |
6e1bc0df | 262 | { |
3228cc1d | 263 | struct pretty_component *pretty = data; |
6e1bc0df | 264 | |
ce141536 PP |
265 | if (!bt_value_map_has_entry(pretty->plugin_opt_map, |
266 | key)) { | |
3228cc1d PP |
267 | fprintf(pretty->err, |
268 | "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); | |
6e1bc0df | 269 | } |
c55a9f58 | 270 | return BT_TRUE; |
6e1bc0df MD |
271 | } |
272 | ||
273 | static | |
8eee8ea2 | 274 | void apply_one_string(const char *key, const bt_value *params, char **option) |
6e1bc0df | 275 | { |
8eee8ea2 | 276 | const bt_value *value = NULL; |
6e1bc0df MD |
277 | const char *str; |
278 | ||
ce141536 | 279 | value = bt_value_map_borrow_entry_value_const(params, key); |
6e1bc0df MD |
280 | if (!value) { |
281 | goto end; | |
282 | } | |
283 | if (bt_value_is_null(value)) { | |
284 | goto end; | |
285 | } | |
b5cdc106 | 286 | str = bt_value_string_get(value); |
6e1bc0df | 287 | *option = g_strdup(str); |
b5cdc106 | 288 | |
6e1bc0df | 289 | end: |
834e9996 | 290 | return; |
6e1bc0df MD |
291 | } |
292 | ||
293 | static | |
8eee8ea2 | 294 | void apply_one_bool(const char *key, const bt_value *params, bool *option, |
6e1bc0df MD |
295 | bool *found) |
296 | { | |
8eee8ea2 | 297 | const bt_value *value = NULL; |
c55a9f58 | 298 | bt_bool bool_val; |
6e1bc0df | 299 | |
ce141536 | 300 | value = bt_value_map_borrow_entry_value_const(params, key); |
6e1bc0df MD |
301 | if (!value) { |
302 | goto end; | |
303 | } | |
b5cdc106 | 304 | bool_val = bt_value_bool_get(value); |
c55a9f58 | 305 | *option = (bool) bool_val; |
6e1bc0df MD |
306 | if (found) { |
307 | *found = true; | |
308 | } | |
f78d5dd1 | 309 | |
6e1bc0df | 310 | end: |
834e9996 | 311 | return; |
6e1bc0df MD |
312 | } |
313 | ||
ad96d936 | 314 | static |
3228cc1d | 315 | void warn_wrong_color_param(struct pretty_component *pretty) |
ad96d936 | 316 | { |
3228cc1d | 317 | fprintf(pretty->err, |
ad96d936 PP |
318 | "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n"); |
319 | } | |
320 | ||
77986bad | 321 | static |
834e9996 | 322 | int open_output_file(struct pretty_component *pretty) |
77986bad | 323 | { |
834e9996 | 324 | int ret = 0; |
77986bad | 325 | |
3228cc1d | 326 | if (!pretty->options.output_path) { |
77986bad JD |
327 | goto end; |
328 | } | |
329 | ||
3228cc1d PP |
330 | pretty->out = fopen(pretty->options.output_path, "w"); |
331 | if (!pretty->out) { | |
77986bad JD |
332 | goto error; |
333 | } | |
334 | ||
335 | goto end; | |
336 | ||
337 | error: | |
834e9996 PP |
338 | ret = -1; |
339 | ||
77986bad JD |
340 | end: |
341 | return ret; | |
342 | } | |
343 | ||
6e1bc0df | 344 | static |
8eee8ea2 | 345 | int apply_params(struct pretty_component *pretty, const bt_value *params) |
6e1bc0df | 346 | { |
834e9996 | 347 | int ret = 0; |
ee78f405 | 348 | bt_value_status status; |
6e1bc0df MD |
349 | bool value, found; |
350 | char *str = NULL; | |
351 | ||
ce141536 | 352 | pretty->plugin_opt_map = bt_value_map_create(); |
3228cc1d | 353 | if (!pretty->plugin_opt_map) { |
834e9996 | 354 | ret = -1; |
6e1bc0df MD |
355 | goto end; |
356 | } | |
3228cc1d | 357 | ret = add_params_to_map(pretty->plugin_opt_map); |
834e9996 | 358 | if (ret) { |
6e1bc0df MD |
359 | goto end; |
360 | } | |
361 | /* Report unknown parameters. */ | |
ce141536 PP |
362 | status = bt_value_map_foreach_entry_const(params, |
363 | check_param_exists, pretty); | |
6e1bc0df MD |
364 | switch (status) { |
365 | case BT_VALUE_STATUS_OK: | |
366 | break; | |
367 | default: | |
834e9996 | 368 | ret = -1; |
6e1bc0df MD |
369 | goto end; |
370 | } | |
371 | /* Known parameters. */ | |
3228cc1d | 372 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
44514773 | 373 | if (bt_value_map_has_entry(params, "color")) { |
8eee8ea2 | 374 | const bt_value *color_value; |
ad96d936 PP |
375 | const char *color; |
376 | ||
ce141536 PP |
377 | color_value = bt_value_map_borrow_entry_value_const(params, |
378 | "color"); | |
ad96d936 PP |
379 | if (!color_value) { |
380 | goto end; | |
381 | } | |
382 | ||
b5cdc106 PP |
383 | color = bt_value_string_get(color_value); |
384 | ||
385 | if (strcmp(color, "never") == 0) { | |
386 | pretty->options.color = PRETTY_COLOR_OPT_NEVER; | |
387 | } else if (strcmp(color, "auto") == 0) { | |
388 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; | |
389 | } else if (strcmp(color, "always") == 0) { | |
390 | pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; | |
ad96d936 | 391 | } else { |
b5cdc106 | 392 | warn_wrong_color_param(pretty); |
ad96d936 | 393 | } |
ad96d936 PP |
394 | } |
395 | ||
834e9996 | 396 | apply_one_string("path", params, &pretty->options.output_path); |
3228cc1d | 397 | ret = open_output_file(pretty); |
834e9996 | 398 | if (ret) { |
77986bad JD |
399 | goto end; |
400 | } | |
6e1bc0df | 401 | |
6e1bc0df | 402 | value = false; /* Default. */ |
834e9996 | 403 | apply_one_bool("no-delta", params, &value, NULL); |
3228cc1d | 404 | pretty->options.print_delta_field = !value; /* Reverse logic. */ |
6e1bc0df MD |
405 | |
406 | value = false; /* Default. */ | |
834e9996 | 407 | apply_one_bool("clock-cycles", params, &value, NULL); |
3228cc1d | 408 | pretty->options.print_timestamp_cycles = value; |
6e1bc0df MD |
409 | |
410 | value = false; /* Default. */ | |
834e9996 | 411 | apply_one_bool("clock-seconds", params, &value, NULL); |
3228cc1d | 412 | pretty->options.clock_seconds = value; |
6e1bc0df MD |
413 | |
414 | value = false; /* Default. */ | |
834e9996 | 415 | apply_one_bool("clock-date", params, &value, NULL); |
3228cc1d | 416 | pretty->options.clock_date = value; |
6e1bc0df MD |
417 | |
418 | value = false; /* Default. */ | |
834e9996 | 419 | apply_one_bool("clock-gmt", params, &value, NULL); |
3228cc1d | 420 | pretty->options.clock_gmt = value; |
6e1bc0df | 421 | |
a263021c | 422 | value = false; /* Default. */ |
834e9996 | 423 | apply_one_bool("verbose", params, &value, NULL); |
3228cc1d | 424 | pretty->options.verbose = value; |
a263021c | 425 | |
6e1bc0df | 426 | /* Names. */ |
834e9996 | 427 | apply_one_string("name-default", params, &str); |
6e1bc0df | 428 | if (!str) { |
3228cc1d | 429 | pretty->options.name_default = PRETTY_DEFAULT_UNSET; |
6e1bc0df | 430 | } else if (!strcmp(str, "show")) { |
3228cc1d | 431 | pretty->options.name_default = PRETTY_DEFAULT_SHOW; |
6e1bc0df | 432 | } else if (!strcmp(str, "hide")) { |
3228cc1d | 433 | pretty->options.name_default = PRETTY_DEFAULT_HIDE; |
6e1bc0df | 434 | } else { |
834e9996 | 435 | ret = -1; |
6e1bc0df MD |
436 | goto end; |
437 | } | |
438 | g_free(str); | |
439 | str = NULL; | |
440 | ||
3228cc1d PP |
441 | switch (pretty->options.name_default) { |
442 | case PRETTY_DEFAULT_UNSET: | |
443 | pretty->options.print_payload_field_names = true; | |
444 | pretty->options.print_context_field_names = true; | |
445 | pretty->options.print_header_field_names = false; | |
446 | pretty->options.print_scope_field_names = false; | |
6e1bc0df | 447 | break; |
3228cc1d PP |
448 | case PRETTY_DEFAULT_SHOW: |
449 | pretty->options.print_payload_field_names = true; | |
450 | pretty->options.print_context_field_names = true; | |
451 | pretty->options.print_header_field_names = true; | |
452 | pretty->options.print_scope_field_names = true; | |
6e1bc0df | 453 | break; |
3228cc1d PP |
454 | case PRETTY_DEFAULT_HIDE: |
455 | pretty->options.print_payload_field_names = false; | |
456 | pretty->options.print_context_field_names = false; | |
457 | pretty->options.print_header_field_names = false; | |
458 | pretty->options.print_scope_field_names = false; | |
6e1bc0df MD |
459 | break; |
460 | default: | |
834e9996 | 461 | ret = -1; |
6e1bc0df MD |
462 | goto end; |
463 | } | |
464 | ||
465 | value = false; | |
466 | found = false; | |
834e9996 | 467 | apply_one_bool("name-payload", params, &value, &found); |
6e1bc0df | 468 | if (found) { |
3228cc1d | 469 | pretty->options.print_payload_field_names = value; |
6e1bc0df MD |
470 | } |
471 | ||
472 | value = false; | |
473 | found = false; | |
834e9996 | 474 | apply_one_bool("name-context", params, &value, &found); |
6e1bc0df | 475 | if (found) { |
3228cc1d | 476 | pretty->options.print_context_field_names = value; |
6e1bc0df MD |
477 | } |
478 | ||
479 | value = false; | |
480 | found = false; | |
834e9996 | 481 | apply_one_bool("name-header", params, &value, &found); |
6e1bc0df | 482 | if (found) { |
3228cc1d | 483 | pretty->options.print_header_field_names = value; |
6e1bc0df MD |
484 | } |
485 | ||
486 | value = false; | |
487 | found = false; | |
834e9996 | 488 | apply_one_bool("name-scope", params, &value, &found); |
6e1bc0df | 489 | if (found) { |
3228cc1d | 490 | pretty->options.print_scope_field_names = value; |
6e1bc0df MD |
491 | } |
492 | ||
493 | /* Fields. */ | |
834e9996 | 494 | apply_one_string("field-default", params, &str); |
6e1bc0df | 495 | if (!str) { |
3228cc1d | 496 | pretty->options.field_default = PRETTY_DEFAULT_UNSET; |
6e1bc0df | 497 | } else if (!strcmp(str, "show")) { |
3228cc1d | 498 | pretty->options.field_default = PRETTY_DEFAULT_SHOW; |
6e1bc0df | 499 | } else if (!strcmp(str, "hide")) { |
3228cc1d | 500 | pretty->options.field_default = PRETTY_DEFAULT_HIDE; |
6e1bc0df | 501 | } else { |
834e9996 | 502 | ret = -1; |
6e1bc0df MD |
503 | goto end; |
504 | } | |
505 | g_free(str); | |
506 | str = NULL; | |
507 | ||
3228cc1d PP |
508 | switch (pretty->options.field_default) { |
509 | case PRETTY_DEFAULT_UNSET: | |
510 | pretty->options.print_trace_field = false; | |
511 | pretty->options.print_trace_hostname_field = true; | |
512 | pretty->options.print_trace_domain_field = false; | |
513 | pretty->options.print_trace_procname_field = true; | |
514 | pretty->options.print_trace_vpid_field = true; | |
515 | pretty->options.print_loglevel_field = false; | |
516 | pretty->options.print_emf_field = false; | |
517 | pretty->options.print_callsite_field = false; | |
6e1bc0df | 518 | break; |
3228cc1d PP |
519 | case PRETTY_DEFAULT_SHOW: |
520 | pretty->options.print_trace_field = true; | |
521 | pretty->options.print_trace_hostname_field = true; | |
522 | pretty->options.print_trace_domain_field = true; | |
523 | pretty->options.print_trace_procname_field = true; | |
524 | pretty->options.print_trace_vpid_field = true; | |
525 | pretty->options.print_loglevel_field = true; | |
526 | pretty->options.print_emf_field = true; | |
527 | pretty->options.print_callsite_field = true; | |
6e1bc0df | 528 | break; |
3228cc1d PP |
529 | case PRETTY_DEFAULT_HIDE: |
530 | pretty->options.print_trace_field = false; | |
531 | pretty->options.print_trace_hostname_field = false; | |
532 | pretty->options.print_trace_domain_field = false; | |
533 | pretty->options.print_trace_procname_field = false; | |
534 | pretty->options.print_trace_vpid_field = false; | |
535 | pretty->options.print_loglevel_field = false; | |
536 | pretty->options.print_emf_field = false; | |
537 | pretty->options.print_callsite_field = false; | |
6e1bc0df MD |
538 | break; |
539 | default: | |
834e9996 | 540 | ret = -1; |
6e1bc0df MD |
541 | goto end; |
542 | } | |
543 | ||
544 | value = false; | |
545 | found = false; | |
834e9996 | 546 | apply_one_bool("field-trace", params, &value, &found); |
6e1bc0df | 547 | if (found) { |
3228cc1d | 548 | pretty->options.print_trace_field = value; |
6e1bc0df MD |
549 | } |
550 | ||
551 | value = false; | |
552 | found = false; | |
834e9996 | 553 | apply_one_bool("field-trace:hostname", params, &value, &found); |
6e1bc0df | 554 | if (found) { |
3228cc1d | 555 | pretty->options.print_trace_hostname_field = value; |
6e1bc0df MD |
556 | } |
557 | ||
558 | value = false; | |
559 | found = false; | |
834e9996 | 560 | apply_one_bool("field-trace:domain", params, &value, &found); |
6e1bc0df | 561 | if (found) { |
3228cc1d | 562 | pretty->options.print_trace_domain_field = value; |
6e1bc0df MD |
563 | } |
564 | ||
565 | value = false; | |
566 | found = false; | |
834e9996 | 567 | apply_one_bool("field-trace:procname", params, &value, &found); |
6e1bc0df | 568 | if (found) { |
3228cc1d | 569 | pretty->options.print_trace_procname_field = value; |
6e1bc0df MD |
570 | } |
571 | ||
572 | value = false; | |
573 | found = false; | |
834e9996 | 574 | apply_one_bool("field-trace:vpid", params, &value, &found); |
6e1bc0df | 575 | if (found) { |
3228cc1d | 576 | pretty->options.print_trace_vpid_field = value; |
6e1bc0df MD |
577 | } |
578 | ||
579 | value = false; | |
580 | found = false; | |
834e9996 | 581 | apply_one_bool("field-loglevel", params, &value, &found); |
6e1bc0df | 582 | if (found) { |
3228cc1d | 583 | pretty->options.print_loglevel_field = value; |
6e1bc0df MD |
584 | } |
585 | ||
586 | value = false; | |
587 | found = false; | |
834e9996 | 588 | apply_one_bool("field-emf", params, &value, &found); |
6e1bc0df | 589 | if (found) { |
3228cc1d | 590 | pretty->options.print_emf_field = value; |
6e1bc0df MD |
591 | } |
592 | ||
593 | value = false; | |
594 | found = false; | |
834e9996 | 595 | apply_one_bool("field-callsite", params, &value, &found); |
6e1bc0df | 596 | if (found) { |
3228cc1d | 597 | pretty->options.print_callsite_field = value; |
6e1bc0df MD |
598 | } |
599 | ||
6e1bc0df | 600 | end: |
8c6884d9 | 601 | bt_value_put_ref(pretty->plugin_opt_map); |
3228cc1d | 602 | pretty->plugin_opt_map = NULL; |
6e1bc0df MD |
603 | g_free(str); |
604 | return ret; | |
605 | } | |
606 | ||
ad96d936 | 607 | static |
3228cc1d | 608 | void set_use_colors(struct pretty_component *pretty) |
ad96d936 | 609 | { |
3228cc1d PP |
610 | switch (pretty->options.color) { |
611 | case PRETTY_COLOR_OPT_ALWAYS: | |
612 | pretty->use_colors = true; | |
ad96d936 | 613 | break; |
3228cc1d PP |
614 | case PRETTY_COLOR_OPT_AUTO: |
615 | pretty->use_colors = pretty->out == stdout && | |
ad96d936 PP |
616 | bt_common_colors_supported(); |
617 | break; | |
3228cc1d PP |
618 | case PRETTY_COLOR_OPT_NEVER: |
619 | pretty->use_colors = false; | |
ad96d936 PP |
620 | break; |
621 | } | |
622 | } | |
623 | ||
2b4c4a7c JD |
624 | static |
625 | void init_stream_packet_context_quarks(void) | |
626 | { | |
627 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = | |
628 | g_quark_from_string("timestamp_begin"); | |
629 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = | |
630 | g_quark_from_string("timestamp_begin"); | |
631 | stream_packet_context_quarks[Q_TIMESTAMP_END] = | |
632 | g_quark_from_string("timestamp_end"); | |
633 | stream_packet_context_quarks[Q_EVENTS_DISCARDED] = | |
634 | g_quark_from_string("events_discarded"); | |
635 | stream_packet_context_quarks[Q_CONTENT_SIZE] = | |
636 | g_quark_from_string("content_size"); | |
637 | stream_packet_context_quarks[Q_PACKET_SIZE] = | |
638 | g_quark_from_string("packet_size"); | |
639 | stream_packet_context_quarks[Q_PACKET_SEQ_NUM] = | |
640 | g_quark_from_string("packet_seq_num"); | |
641 | } | |
642 | ||
3228cc1d | 643 | BT_HIDDEN |
ee78f405 | 644 | bt_self_component_status pretty_init( |
8eee8ea2 PP |
645 | bt_self_component_sink *comp, |
646 | const bt_value *params, | |
f807570c | 647 | __attribute__((unused)) void *init_method_data) |
bac67f0f | 648 | { |
ee78f405 | 649 | bt_self_component_status ret; |
3228cc1d | 650 | struct pretty_component *pretty = create_pretty(); |
bac67f0f | 651 | |
3228cc1d | 652 | if (!pretty) { |
834e9996 | 653 | ret = BT_SELF_COMPONENT_STATUS_NOMEM; |
bac67f0f JG |
654 | goto end; |
655 | } | |
656 | ||
1043fdea PP |
657 | ret = bt_self_component_sink_add_input_port(comp, in_port_name, |
658 | NULL, NULL); | |
834e9996 | 659 | if (ret != BT_SELF_COMPONENT_STATUS_OK) { |
b9d103be PP |
660 | goto end; |
661 | } | |
662 | ||
3228cc1d PP |
663 | pretty->out = stdout; |
664 | pretty->err = stderr; | |
6e1bc0df | 665 | |
3228cc1d PP |
666 | pretty->delta_cycles = -1ULL; |
667 | pretty->last_cycles_timestamp = -1ULL; | |
3af83b5a | 668 | |
3228cc1d PP |
669 | pretty->delta_real_timestamp = -1ULL; |
670 | pretty->last_real_timestamp = -1ULL; | |
3af83b5a | 671 | |
834e9996 PP |
672 | if (apply_params(pretty, params)) { |
673 | ret = BT_SELF_COMPONENT_STATUS_ERROR; | |
6e1bc0df MD |
674 | goto error; |
675 | } | |
676 | ||
3228cc1d | 677 | set_use_colors(pretty); |
834e9996 | 678 | bt_self_component_set_data( |
bb61965b | 679 | bt_self_component_sink_as_self_component(comp), pretty); |
2b4c4a7c JD |
680 | init_stream_packet_context_quarks(); |
681 | ||
bac67f0f JG |
682 | end: |
683 | return ret; | |
834e9996 | 684 | |
bac67f0f | 685 | error: |
3228cc1d | 686 | destroy_pretty_data(pretty); |
bac67f0f JG |
687 | return ret; |
688 | } |