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