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