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