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