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 | ||
0d2d7e51 FD |
26 | #define BT_LOG_TAG "PLUGIN-TEXT-PRETTY-SINK" |
27 | #include "logging.h" | |
28 | ||
9d408fca | 29 | #include <babeltrace/babeltrace.h> |
3d9990ac | 30 | #include <babeltrace/compiler-internal.h> |
ad96d936 | 31 | #include <babeltrace/common-internal.h> |
7d61fa8e | 32 | #include <plugins-common.h> |
bfd20a42 | 33 | #include <stdio.h> |
39cfa40f | 34 | #include <stdbool.h> |
bac67f0f | 35 | #include <glib.h> |
f6ccaed9 | 36 | #include <babeltrace/assert-internal.h> |
6405967d | 37 | |
3228cc1d PP |
38 | #include "pretty.h" |
39 | ||
61d6f9b1 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 | ||
5badd463 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 | { |
d6e69534 | 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 |
b19ff26f | 122 | void pretty_finalize(bt_self_component_sink *comp) |
b25bd455 | 123 | { |
d94d92ac PP |
124 | destroy_pretty_data( |
125 | bt_self_component_get_data( | |
707b7d35 | 126 | bt_self_component_sink_as_self_component(comp))); |
b25bd455 JG |
127 | } |
128 | ||
bac67f0f | 129 | static |
4cdfc5e8 | 130 | bt_self_component_status handle_message( |
d94d92ac | 131 | struct pretty_component *pretty, |
d6e69534 | 132 | const bt_message *message) |
4c1456f0 | 133 | { |
4cdfc5e8 | 134 | bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; |
541b0a11 | 135 | |
f6ccaed9 | 136 | BT_ASSERT(pretty); |
541b0a11 | 137 | |
d6e69534 | 138 | switch (bt_message_get_type(message)) { |
d6e69534 PP |
139 | case BT_MESSAGE_TYPE_EVENT: |
140 | if (pretty_print_event(pretty, message)) { | |
d94d92ac PP |
141 | ret = BT_SELF_COMPONENT_STATUS_ERROR; |
142 | } | |
7cdc2bab | 143 | break; |
b9fd9cbb | 144 | case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: |
0d2d7e51 | 145 | BT_LOGD_STR("Message iterator inactivity message."); |
7cdc2bab | 146 | break; |
8e53bed4 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: |
f42867e2 | 154 | break; |
78586d8a | 155 | } |
b5e978f4 | 156 | |
541b0a11 | 157 | return ret; |
4c1456f0 | 158 | } |
bac67f0f | 159 | |
3228cc1d | 160 | BT_HIDDEN |
5badd463 PP |
161 | bt_self_component_status pretty_graph_is_configured( |
162 | bt_self_component_sink *comp) | |
75e1829b | 163 | { |
4cdfc5e8 | 164 | bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; |
3228cc1d | 165 | struct pretty_component *pretty; |
75e1829b | 166 | |
d94d92ac | 167 | pretty = bt_self_component_get_data( |
707b7d35 | 168 | bt_self_component_sink_as_self_component(comp)); |
f6ccaed9 | 169 | BT_ASSERT(pretty); |
d94d92ac | 170 | BT_ASSERT(!pretty->iterator); |
d6e69534 | 171 | pretty->iterator = bt_self_component_port_input_message_iterator_create( |
5badd463 PP |
172 | bt_self_component_sink_borrow_input_port_by_name(comp, |
173 | in_port_name)); | |
d94d92ac PP |
174 | if (!pretty->iterator) { |
175 | status = BT_SELF_COMPONENT_STATUS_NOMEM; | |
75e1829b | 176 | } |
72b913fb | 177 | |
bf55043c | 178 | return status; |
75e1829b JG |
179 | } |
180 | ||
3228cc1d | 181 | BT_HIDDEN |
4cdfc5e8 | 182 | bt_self_component_status pretty_consume( |
b19ff26f | 183 | bt_self_component_sink *comp) |
fec2a9f2 | 184 | { |
4cdfc5e8 | 185 | bt_self_component_status ret; |
d6e69534 PP |
186 | bt_message_array_const msgs; |
187 | bt_self_component_port_input_message_iterator *it; | |
d94d92ac | 188 | struct pretty_component *pretty = bt_self_component_get_data( |
707b7d35 | 189 | bt_self_component_sink_as_self_component(comp)); |
4cdfc5e8 | 190 | bt_message_iterator_status it_ret; |
d4393e08 PP |
191 | uint64_t count = 0; |
192 | uint64_t i = 0; | |
fec2a9f2 | 193 | |
d94d92ac | 194 | it = pretty->iterator; |
d6e69534 PP |
195 | it_ret = bt_self_component_port_input_message_iterator_next(it, |
196 | &msgs, &count); | |
0d8b4d8e | 197 | |
41a2b7ae | 198 | switch (it_ret) { |
d6e69534 | 199 | case BT_MESSAGE_ITERATOR_STATUS_OK: |
d94d92ac | 200 | break; |
d6e69534 | 201 | case BT_MESSAGE_ITERATOR_STATUS_NOMEM: |
d94d92ac | 202 | ret = BT_SELF_COMPONENT_STATUS_NOMEM; |
41a2b7ae | 203 | goto end; |
d6e69534 | 204 | case BT_MESSAGE_ITERATOR_STATUS_AGAIN: |
d94d92ac PP |
205 | ret = BT_SELF_COMPONENT_STATUS_AGAIN; |
206 | goto end; | |
d6e69534 | 207 | case BT_MESSAGE_ITERATOR_STATUS_END: |
d94d92ac | 208 | ret = BT_SELF_COMPONENT_STATUS_END; |
d6e69534 | 209 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET( |
c5b9b441 | 210 | pretty->iterator); |
dfa6653c | 211 | goto end; |
dfa6653c | 212 | default: |
d94d92ac | 213 | ret = BT_SELF_COMPONENT_STATUS_ERROR; |
dfa6653c | 214 | goto end; |
fec2a9f2 JG |
215 | } |
216 | ||
d6e69534 | 217 | BT_ASSERT(it_ret == BT_MESSAGE_ITERATOR_STATUS_OK); |
d4393e08 PP |
218 | |
219 | for (i = 0; i < count; i++) { | |
d6e69534 | 220 | ret = handle_message(pretty, msgs[i]); |
d4393e08 PP |
221 | if (ret) { |
222 | goto end; | |
223 | } | |
224 | ||
d6e69534 | 225 | bt_message_put_ref(msgs[i]); |
d4393e08 | 226 | } |
dfa6653c | 227 | |
fec2a9f2 | 228 | end: |
d4393e08 | 229 | for (; i < count; i++) { |
d6e69534 | 230 | bt_message_put_ref(msgs[i]); |
d4393e08 PP |
231 | } |
232 | ||
fec2a9f2 JG |
233 | return ret; |
234 | } | |
235 | ||
6e1bc0df | 236 | static |
b19ff26f | 237 | int add_params_to_map(bt_value *plugin_opt_map) |
6e1bc0df | 238 | { |
d94d92ac | 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]; | |
4cdfc5e8 | 244 | bt_value_status status; |
6e1bc0df | 245 | |
05e21286 | 246 | status = bt_value_map_insert_entry(plugin_opt_map, key, |
da91b29a | 247 | bt_value_null); |
6e1bc0df MD |
248 | switch (status) { |
249 | case BT_VALUE_STATUS_OK: | |
250 | break; | |
251 | default: | |
d94d92ac | 252 | ret = -1; |
6e1bc0df MD |
253 | goto end; |
254 | } | |
255 | } | |
256 | end: | |
257 | return ret; | |
258 | } | |
259 | ||
260 | static | |
b19ff26f | 261 | bt_bool check_param_exists(const char *key, const bt_value *object, |
05e21286 | 262 | void *data) |
6e1bc0df | 263 | { |
3228cc1d | 264 | struct pretty_component *pretty = data; |
6e1bc0df | 265 | |
05e21286 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 | |
b19ff26f | 275 | void apply_one_string(const char *key, const bt_value *params, char **option) |
6e1bc0df | 276 | { |
b19ff26f | 277 | const bt_value *value = NULL; |
6e1bc0df MD |
278 | const char *str; |
279 | ||
05e21286 | 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 | } | |
601b0d3c | 287 | str = bt_value_string_get(value); |
6e1bc0df | 288 | *option = g_strdup(str); |
601b0d3c | 289 | |
6e1bc0df | 290 | end: |
d94d92ac | 291 | return; |
6e1bc0df MD |
292 | } |
293 | ||
294 | static | |
b19ff26f | 295 | void apply_one_bool(const char *key, const bt_value *params, bool *option, |
6e1bc0df MD |
296 | bool *found) |
297 | { | |
b19ff26f | 298 | const bt_value *value = NULL; |
c55a9f58 | 299 | bt_bool bool_val; |
6e1bc0df | 300 | |
05e21286 | 301 | value = bt_value_map_borrow_entry_value_const(params, key); |
6e1bc0df MD |
302 | if (!value) { |
303 | goto end; | |
304 | } | |
601b0d3c | 305 | bool_val = bt_value_bool_get(value); |
c55a9f58 | 306 | *option = (bool) bool_val; |
6e1bc0df MD |
307 | if (found) { |
308 | *found = true; | |
309 | } | |
a82e90e8 | 310 | |
6e1bc0df | 311 | end: |
d94d92ac | 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 |
d94d92ac | 323 | int open_output_file(struct pretty_component *pretty) |
77986bad | 324 | { |
d94d92ac | 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: | |
d94d92ac PP |
339 | ret = -1; |
340 | ||
77986bad JD |
341 | end: |
342 | return ret; | |
343 | } | |
344 | ||
6e1bc0df | 345 | static |
b19ff26f | 346 | int apply_params(struct pretty_component *pretty, const bt_value *params) |
6e1bc0df | 347 | { |
d94d92ac | 348 | int ret = 0; |
4cdfc5e8 | 349 | bt_value_status status; |
6e1bc0df MD |
350 | bool value, found; |
351 | char *str = NULL; | |
352 | ||
05e21286 | 353 | pretty->plugin_opt_map = bt_value_map_create(); |
3228cc1d | 354 | if (!pretty->plugin_opt_map) { |
d94d92ac | 355 | ret = -1; |
6e1bc0df MD |
356 | goto end; |
357 | } | |
3228cc1d | 358 | ret = add_params_to_map(pretty->plugin_opt_map); |
d94d92ac | 359 | if (ret) { |
6e1bc0df MD |
360 | goto end; |
361 | } | |
362 | /* Report unknown parameters. */ | |
05e21286 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: | |
d94d92ac | 369 | ret = -1; |
6e1bc0df MD |
370 | goto end; |
371 | } | |
372 | /* Known parameters. */ | |
3228cc1d | 373 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
07208d85 | 374 | if (bt_value_map_has_entry(params, "color")) { |
b19ff26f | 375 | const bt_value *color_value; |
ad96d936 PP |
376 | const char *color; |
377 | ||
05e21286 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 | ||
601b0d3c 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 { |
601b0d3c | 393 | warn_wrong_color_param(pretty); |
ad96d936 | 394 | } |
ad96d936 PP |
395 | } |
396 | ||
d94d92ac | 397 | apply_one_string("path", params, &pretty->options.output_path); |
3228cc1d | 398 | ret = open_output_file(pretty); |
d94d92ac | 399 | if (ret) { |
77986bad JD |
400 | goto end; |
401 | } | |
6e1bc0df | 402 | |
6e1bc0df | 403 | value = false; /* Default. */ |
d94d92ac | 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. */ | |
d94d92ac | 408 | apply_one_bool("clock-cycles", params, &value, NULL); |
3228cc1d | 409 | pretty->options.print_timestamp_cycles = value; |
6e1bc0df MD |
410 | |
411 | value = false; /* Default. */ | |
d94d92ac | 412 | apply_one_bool("clock-seconds", params, &value, NULL); |
3228cc1d | 413 | pretty->options.clock_seconds = value; |
6e1bc0df MD |
414 | |
415 | value = false; /* Default. */ | |
d94d92ac | 416 | apply_one_bool("clock-date", params, &value, NULL); |
3228cc1d | 417 | pretty->options.clock_date = value; |
6e1bc0df MD |
418 | |
419 | value = false; /* Default. */ | |
d94d92ac | 420 | apply_one_bool("clock-gmt", params, &value, NULL); |
3228cc1d | 421 | pretty->options.clock_gmt = value; |
6e1bc0df | 422 | |
a263021c | 423 | value = false; /* Default. */ |
d94d92ac | 424 | apply_one_bool("verbose", params, &value, NULL); |
3228cc1d | 425 | pretty->options.verbose = value; |
a263021c | 426 | |
6e1bc0df | 427 | /* Names. */ |
d94d92ac | 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 { |
d94d92ac | 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: | |
d94d92ac | 462 | ret = -1; |
6e1bc0df MD |
463 | goto end; |
464 | } | |
465 | ||
466 | value = false; | |
467 | found = false; | |
d94d92ac | 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; | |
d94d92ac | 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; | |
d94d92ac | 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; | |
d94d92ac | 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. */ | |
d94d92ac | 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 { |
d94d92ac | 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: | |
d94d92ac | 541 | ret = -1; |
6e1bc0df MD |
542 | goto end; |
543 | } | |
544 | ||
545 | value = false; | |
546 | found = false; | |
d94d92ac | 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; | |
d94d92ac | 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; | |
d94d92ac | 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; | |
d94d92ac | 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; | |
d94d92ac | 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; | |
d94d92ac | 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; | |
d94d92ac | 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; | |
d94d92ac | 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: |
c5b9b441 | 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 |
4cdfc5e8 | 645 | bt_self_component_status pretty_init( |
b19ff26f PP |
646 | bt_self_component_sink *comp, |
647 | const bt_value *params, | |
7d61fa8e | 648 | UNUSED_VAR void *init_method_data) |
bac67f0f | 649 | { |
4cdfc5e8 | 650 | bt_self_component_status ret; |
3228cc1d | 651 | struct pretty_component *pretty = create_pretty(); |
bac67f0f | 652 | |
3228cc1d | 653 | if (!pretty) { |
d94d92ac | 654 | ret = BT_SELF_COMPONENT_STATUS_NOMEM; |
bac67f0f JG |
655 | goto end; |
656 | } | |
657 | ||
5badd463 PP |
658 | ret = bt_self_component_sink_add_input_port(comp, in_port_name, |
659 | NULL, NULL); | |
d94d92ac | 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 | |
d94d92ac 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); |
d94d92ac | 679 | bt_self_component_set_data( |
707b7d35 | 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; | |
d94d92ac | 685 | |
bac67f0f | 686 | error: |
3228cc1d | 687 | destroy_pretty_data(pretty); |
bac67f0f JG |
688 | return ret; |
689 | } |