Commit | Line | Data |
---|---|---|
7a278c8e | 1 | /* |
3228cc1d | 2 | * pretty.c |
7a278c8e | 3 | * |
5dac767a | 4 | * Babeltrace CTF Text Output Plugin |
7a278c8e | 5 | * |
2e339de1 | 6 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
f504043c | 7 | * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
7a278c8e JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | */ | |
29 | ||
33b34c43 | 30 | #include <babeltrace/plugin/plugin-dev.h> |
b2e0c907 PP |
31 | #include <babeltrace/graph/component.h> |
32 | #include <babeltrace/graph/private-component.h> | |
33 | #include <babeltrace/graph/component-sink.h> | |
34 | #include <babeltrace/graph/port.h> | |
35 | #include <babeltrace/graph/private-port.h> | |
36 | #include <babeltrace/graph/connection.h> | |
37 | #include <babeltrace/graph/private-connection.h> | |
38 | #include <babeltrace/graph/notification.h> | |
39 | #include <babeltrace/graph/notification-iterator.h> | |
40 | #include <babeltrace/graph/notification-event.h> | |
6e1bc0df | 41 | #include <babeltrace/values.h> |
3d9990ac | 42 | #include <babeltrace/compiler-internal.h> |
ad96d936 | 43 | #include <babeltrace/common-internal.h> |
7d61fa8e | 44 | #include <plugins-common.h> |
bfd20a42 | 45 | #include <stdio.h> |
39cfa40f | 46 | #include <stdbool.h> |
bac67f0f | 47 | #include <glib.h> |
75e1829b | 48 | #include <assert.h> |
6405967d | 49 | |
3228cc1d PP |
50 | #include "pretty.h" |
51 | ||
6e1bc0df MD |
52 | static |
53 | const char *plugin_options[] = { | |
ad96d936 | 54 | "color", |
6e1bc0df | 55 | "output-path", |
6e1bc0df MD |
56 | "no-delta", |
57 | "clock-cycles", | |
58 | "clock-seconds", | |
59 | "clock-date", | |
60 | "clock-gmt", | |
a263021c | 61 | "verbose", |
6e1bc0df MD |
62 | "name-default", /* show/hide */ |
63 | "name-payload", | |
64 | "name-context", | |
65 | "name-scope", | |
66 | "name-header", | |
67 | "field-default", /* show/hide */ | |
68 | "field-trace", | |
69 | "field-trace:hostname", | |
70 | "field-trace:domain", | |
71 | "field-trace:procname", | |
72 | "field-trace:vpid", | |
73 | "field-loglevel", | |
74 | "field-emf", | |
60535549 | 75 | "field-callsite", |
6e1bc0df MD |
76 | }; |
77 | ||
bfd20a42 | 78 | static |
3228cc1d | 79 | void destroy_pretty_data(struct pretty_component *pretty) |
bac67f0f | 80 | { |
3228cc1d PP |
81 | bt_put(pretty->input_iterator); |
82 | (void) g_string_free(pretty->string, TRUE); | |
83 | if (pretty->out != stdout) { | |
77986bad JD |
84 | int ret; |
85 | ||
3228cc1d | 86 | ret = fclose(pretty->out); |
77986bad JD |
87 | if (ret) { |
88 | perror("close output file"); | |
89 | } | |
90 | } | |
3228cc1d | 91 | g_free(pretty->options.output_path); |
3228cc1d | 92 | g_free(pretty); |
bac67f0f JG |
93 | } |
94 | ||
b25bd455 | 95 | static |
3228cc1d | 96 | struct pretty_component *create_pretty(void) |
bac67f0f | 97 | { |
3228cc1d | 98 | struct pretty_component *pretty; |
541b0a11 | 99 | |
3228cc1d PP |
100 | pretty = g_new0(struct pretty_component, 1); |
101 | if (!pretty) { | |
541b0a11 JG |
102 | goto end; |
103 | } | |
3228cc1d PP |
104 | pretty->string = g_string_new(""); |
105 | if (!pretty->string) { | |
6a18b281 MD |
106 | goto error; |
107 | } | |
541b0a11 | 108 | end: |
3228cc1d | 109 | return pretty; |
6a18b281 MD |
110 | |
111 | error: | |
3228cc1d | 112 | g_free(pretty); |
6a18b281 | 113 | return NULL; |
bac67f0f JG |
114 | } |
115 | ||
3228cc1d PP |
116 | BT_HIDDEN |
117 | void pretty_finalize(struct bt_private_component *component) | |
b25bd455 | 118 | { |
890882ef | 119 | void *data = bt_private_component_get_user_data(component); |
b25bd455 | 120 | |
3228cc1d | 121 | destroy_pretty_data(data); |
b25bd455 JG |
122 | } |
123 | ||
bac67f0f | 124 | static |
3228cc1d | 125 | enum bt_component_status handle_notification(struct pretty_component *pretty, |
6e1bc0df | 126 | struct bt_notification *notification) |
4c1456f0 | 127 | { |
541b0a11 | 128 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
541b0a11 | 129 | |
3228cc1d | 130 | if (!pretty) { |
541b0a11 JG |
131 | ret = BT_COMPONENT_STATUS_ERROR; |
132 | goto end; | |
133 | } | |
134 | ||
78586d8a | 135 | switch (bt_notification_get_type(notification)) { |
ea0e619e | 136 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: |
78586d8a JG |
137 | break; |
138 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
78586d8a JG |
139 | break; |
140 | case BT_NOTIFICATION_TYPE_EVENT: | |
541b0a11 | 141 | { |
d9f65f09 | 142 | ret = pretty_print_event(pretty, notification); |
541b0a11 JG |
143 | if (ret != BT_COMPONENT_STATUS_OK) { |
144 | goto end; | |
145 | } | |
043e2020 | 146 | break; |
541b0a11 | 147 | } |
043e2020 | 148 | case BT_NOTIFICATION_TYPE_STREAM_END: |
78586d8a JG |
149 | break; |
150 | default: | |
151 | puts("Unhandled notification type"); | |
152 | } | |
541b0a11 JG |
153 | end: |
154 | return ret; | |
4c1456f0 | 155 | } |
bac67f0f | 156 | |
3228cc1d | 157 | BT_HIDDEN |
0d8b4d8e | 158 | void pretty_port_connected( |
890882ef | 159 | struct bt_private_component *component, |
8f4799f7 PP |
160 | struct bt_private_port *self_port, |
161 | struct bt_port *other_port) | |
75e1829b | 162 | { |
890882ef | 163 | struct bt_private_connection *connection; |
3228cc1d | 164 | struct pretty_component *pretty; |
75e1829b | 165 | |
3228cc1d PP |
166 | pretty = bt_private_component_get_user_data(component); |
167 | assert(pretty); | |
168 | assert(!pretty->input_iterator); | |
890882ef | 169 | connection = bt_private_port_get_private_connection(self_port); |
72b913fb | 170 | assert(connection); |
3228cc1d | 171 | pretty->input_iterator = |
890882ef | 172 | bt_private_connection_create_notification_iterator(connection); |
75e1829b | 173 | |
3228cc1d | 174 | if (!pretty->input_iterator) { |
0d8b4d8e | 175 | pretty->error = true; |
75e1829b | 176 | } |
72b913fb PP |
177 | |
178 | bt_put(connection); | |
75e1829b JG |
179 | } |
180 | ||
3228cc1d PP |
181 | BT_HIDDEN |
182 | enum bt_component_status pretty_consume(struct bt_private_component *component) | |
fec2a9f2 JG |
183 | { |
184 | enum bt_component_status ret; | |
185 | struct bt_notification *notification = NULL; | |
186 | struct bt_notification_iterator *it; | |
3228cc1d | 187 | struct pretty_component *pretty = |
890882ef | 188 | bt_private_component_get_user_data(component); |
41a2b7ae | 189 | enum bt_notification_iterator_status it_ret; |
fec2a9f2 | 190 | |
0d8b4d8e PP |
191 | if (unlikely(pretty->error)) { |
192 | ret = BT_COMPONENT_STATUS_ERROR; | |
193 | goto end; | |
194 | } | |
fec2a9f2 | 195 | |
0d8b4d8e | 196 | it = pretty->input_iterator; |
41a2b7ae | 197 | it_ret = bt_notification_iterator_next(it); |
0d8b4d8e | 198 | |
41a2b7ae PP |
199 | switch (it_ret) { |
200 | case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: | |
fec2a9f2 JG |
201 | ret = BT_COMPONENT_STATUS_ERROR; |
202 | goto end; | |
41a2b7ae PP |
203 | case BT_NOTIFICATION_ITERATOR_STATUS_END: |
204 | ret = BT_COMPONENT_STATUS_END; | |
3228cc1d | 205 | BT_PUT(pretty->input_iterator); |
41a2b7ae PP |
206 | goto end; |
207 | default: | |
208 | break; | |
fec2a9f2 JG |
209 | } |
210 | ||
41a2b7ae PP |
211 | notification = bt_notification_iterator_get_notification(it); |
212 | assert(notification); | |
3228cc1d | 213 | ret = handle_notification(pretty, notification); |
fec2a9f2 | 214 | end: |
fec2a9f2 JG |
215 | bt_put(notification); |
216 | return ret; | |
217 | } | |
218 | ||
6e1bc0df MD |
219 | static |
220 | enum bt_component_status add_params_to_map(struct bt_value *plugin_opt_map) | |
221 | { | |
222 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
223 | unsigned int i; | |
224 | ||
225 | for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) { | |
226 | const char *key = plugin_options[i]; | |
227 | enum bt_value_status status; | |
228 | ||
229 | status = bt_value_map_insert(plugin_opt_map, key, bt_value_null); | |
230 | switch (status) { | |
231 | case BT_VALUE_STATUS_OK: | |
232 | break; | |
233 | default: | |
234 | ret = BT_COMPONENT_STATUS_ERROR; | |
235 | goto end; | |
236 | } | |
237 | } | |
238 | end: | |
239 | return ret; | |
240 | } | |
241 | ||
242 | static | |
243 | bool check_param_exists(const char *key, struct bt_value *object, void *data) | |
244 | { | |
3228cc1d PP |
245 | struct pretty_component *pretty = data; |
246 | struct bt_value *plugin_opt_map = pretty->plugin_opt_map; | |
6e1bc0df MD |
247 | |
248 | if (!bt_value_map_get(plugin_opt_map, key)) { | |
3228cc1d PP |
249 | fprintf(pretty->err, |
250 | "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); | |
6e1bc0df MD |
251 | } |
252 | return true; | |
253 | } | |
254 | ||
255 | static | |
256 | enum bt_component_status apply_one_string(const char *key, | |
257 | struct bt_value *params, | |
258 | char **option) | |
259 | { | |
260 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
261 | struct bt_value *value = NULL; | |
262 | enum bt_value_status status; | |
263 | const char *str; | |
264 | ||
265 | value = bt_value_map_get(params, key); | |
266 | if (!value) { | |
267 | goto end; | |
268 | } | |
269 | if (bt_value_is_null(value)) { | |
270 | goto end; | |
271 | } | |
272 | status = bt_value_string_get(value, &str); | |
273 | switch (status) { | |
274 | case BT_VALUE_STATUS_OK: | |
275 | break; | |
276 | default: | |
277 | ret = BT_COMPONENT_STATUS_ERROR; | |
278 | goto end; | |
279 | } | |
280 | *option = g_strdup(str); | |
281 | end: | |
282 | bt_put(value); | |
283 | return ret; | |
284 | } | |
285 | ||
286 | static | |
287 | enum bt_component_status apply_one_bool(const char *key, | |
288 | struct bt_value *params, | |
289 | bool *option, | |
290 | bool *found) | |
291 | { | |
292 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
293 | struct bt_value *value = NULL; | |
294 | enum bt_value_status status; | |
295 | ||
296 | value = bt_value_map_get(params, key); | |
297 | if (!value) { | |
298 | goto end; | |
299 | } | |
300 | status = bt_value_bool_get(value, option); | |
301 | switch (status) { | |
302 | case BT_VALUE_STATUS_OK: | |
303 | break; | |
304 | default: | |
305 | ret = BT_COMPONENT_STATUS_ERROR; | |
306 | goto end; | |
307 | } | |
308 | if (found) { | |
309 | *found = true; | |
310 | } | |
311 | end: | |
312 | bt_put(value); | |
313 | return ret; | |
314 | } | |
315 | ||
ad96d936 | 316 | static |
3228cc1d | 317 | void warn_wrong_color_param(struct pretty_component *pretty) |
ad96d936 | 318 | { |
3228cc1d | 319 | fprintf(pretty->err, |
ad96d936 PP |
320 | "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n"); |
321 | } | |
322 | ||
77986bad | 323 | static |
3228cc1d | 324 | enum bt_component_status open_output_file(struct pretty_component *pretty) |
77986bad JD |
325 | { |
326 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
327 | ||
3228cc1d | 328 | if (!pretty->options.output_path) { |
77986bad JD |
329 | goto end; |
330 | } | |
331 | ||
3228cc1d PP |
332 | pretty->out = fopen(pretty->options.output_path, "w"); |
333 | if (!pretty->out) { | |
77986bad JD |
334 | goto error; |
335 | } | |
336 | ||
337 | goto end; | |
338 | ||
339 | error: | |
340 | ret = BT_COMPONENT_STATUS_ERROR; | |
341 | end: | |
342 | return ret; | |
343 | } | |
344 | ||
6e1bc0df | 345 | static |
3228cc1d | 346 | enum bt_component_status apply_params(struct pretty_component *pretty, |
6e1bc0df MD |
347 | struct bt_value *params) |
348 | { | |
349 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
350 | enum bt_value_status status; | |
351 | bool value, found; | |
352 | char *str = NULL; | |
353 | ||
3228cc1d PP |
354 | pretty->plugin_opt_map = bt_value_map_create(); |
355 | if (!pretty->plugin_opt_map) { | |
6e1bc0df MD |
356 | ret = BT_COMPONENT_STATUS_ERROR; |
357 | goto end; | |
358 | } | |
3228cc1d | 359 | ret = add_params_to_map(pretty->plugin_opt_map); |
6e1bc0df MD |
360 | if (ret != BT_COMPONENT_STATUS_OK) { |
361 | goto end; | |
362 | } | |
363 | /* Report unknown parameters. */ | |
3228cc1d | 364 | status = bt_value_map_foreach(params, check_param_exists, pretty); |
6e1bc0df MD |
365 | switch (status) { |
366 | case BT_VALUE_STATUS_OK: | |
367 | break; | |
368 | default: | |
369 | ret = BT_COMPONENT_STATUS_ERROR; | |
370 | goto end; | |
371 | } | |
372 | /* Known parameters. */ | |
3228cc1d | 373 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
ad96d936 PP |
374 | if (bt_value_map_has_key(params, "color")) { |
375 | struct bt_value *color_value; | |
376 | const char *color; | |
377 | ||
378 | color_value = bt_value_map_get(params, "color"); | |
379 | if (!color_value) { | |
380 | goto end; | |
381 | } | |
382 | ||
72b913fb PP |
383 | status = bt_value_string_get(color_value, &color); |
384 | if (status) { | |
3228cc1d | 385 | warn_wrong_color_param(pretty); |
ad96d936 PP |
386 | } else { |
387 | if (strcmp(color, "never") == 0) { | |
3228cc1d | 388 | pretty->options.color = PRETTY_COLOR_OPT_NEVER; |
ad96d936 | 389 | } else if (strcmp(color, "auto") == 0) { |
3228cc1d | 390 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
ad96d936 | 391 | } else if (strcmp(color, "always") == 0) { |
3228cc1d | 392 | pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; |
ad96d936 | 393 | } else { |
3228cc1d | 394 | warn_wrong_color_param(pretty); |
ad96d936 PP |
395 | } |
396 | } | |
397 | ||
398 | bt_put(color_value); | |
399 | } | |
400 | ||
6e1bc0df MD |
401 | ret = apply_one_string("output-path", |
402 | params, | |
3228cc1d | 403 | &pretty->options.output_path); |
6e1bc0df MD |
404 | if (ret != BT_COMPONENT_STATUS_OK) { |
405 | goto end; | |
406 | } | |
3228cc1d | 407 | ret = open_output_file(pretty); |
77986bad JD |
408 | if (ret != BT_COMPONENT_STATUS_OK) { |
409 | goto end; | |
410 | } | |
6e1bc0df | 411 | |
6e1bc0df MD |
412 | value = false; /* Default. */ |
413 | ret = apply_one_bool("no-delta", params, &value, NULL); | |
414 | if (ret != BT_COMPONENT_STATUS_OK) { | |
415 | goto end; | |
416 | } | |
3228cc1d | 417 | pretty->options.print_delta_field = !value; /* Reverse logic. */ |
6e1bc0df MD |
418 | |
419 | value = false; /* Default. */ | |
420 | ret = apply_one_bool("clock-cycles", params, &value, NULL); | |
421 | if (ret != BT_COMPONENT_STATUS_OK) { | |
422 | goto end; | |
423 | } | |
3228cc1d | 424 | pretty->options.print_timestamp_cycles = value; |
6e1bc0df MD |
425 | |
426 | value = false; /* Default. */ | |
427 | ret = apply_one_bool("clock-seconds", params, &value, NULL); | |
428 | if (ret != BT_COMPONENT_STATUS_OK) { | |
429 | goto end; | |
430 | } | |
3228cc1d | 431 | pretty->options.clock_seconds = value; |
6e1bc0df MD |
432 | |
433 | value = false; /* Default. */ | |
434 | ret = apply_one_bool("clock-date", params, &value, NULL); | |
435 | if (ret != BT_COMPONENT_STATUS_OK) { | |
436 | goto end; | |
437 | } | |
3228cc1d | 438 | pretty->options.clock_date = value; |
6e1bc0df MD |
439 | |
440 | value = false; /* Default. */ | |
441 | ret = apply_one_bool("clock-gmt", params, &value, NULL); | |
442 | if (ret != BT_COMPONENT_STATUS_OK) { | |
443 | goto end; | |
444 | } | |
3228cc1d | 445 | pretty->options.clock_gmt = value; |
6e1bc0df | 446 | |
a263021c JD |
447 | value = false; /* Default. */ |
448 | ret = apply_one_bool("verbose", params, &value, NULL); | |
449 | if (ret != BT_COMPONENT_STATUS_OK) { | |
450 | goto end; | |
451 | } | |
3228cc1d | 452 | pretty->options.verbose = value; |
a263021c | 453 | |
6e1bc0df MD |
454 | /* Names. */ |
455 | ret = apply_one_string("name-default", params, &str); | |
456 | if (ret != BT_COMPONENT_STATUS_OK) { | |
457 | goto end; | |
458 | } | |
459 | if (!str) { | |
3228cc1d | 460 | pretty->options.name_default = PRETTY_DEFAULT_UNSET; |
6e1bc0df | 461 | } else if (!strcmp(str, "show")) { |
3228cc1d | 462 | pretty->options.name_default = PRETTY_DEFAULT_SHOW; |
6e1bc0df | 463 | } else if (!strcmp(str, "hide")) { |
3228cc1d | 464 | pretty->options.name_default = PRETTY_DEFAULT_HIDE; |
6e1bc0df MD |
465 | } else { |
466 | ret = BT_COMPONENT_STATUS_ERROR; | |
467 | goto end; | |
468 | } | |
469 | g_free(str); | |
470 | str = NULL; | |
471 | ||
3228cc1d PP |
472 | switch (pretty->options.name_default) { |
473 | case PRETTY_DEFAULT_UNSET: | |
474 | pretty->options.print_payload_field_names = true; | |
475 | pretty->options.print_context_field_names = true; | |
476 | pretty->options.print_header_field_names = false; | |
477 | pretty->options.print_scope_field_names = false; | |
6e1bc0df | 478 | break; |
3228cc1d PP |
479 | case PRETTY_DEFAULT_SHOW: |
480 | pretty->options.print_payload_field_names = true; | |
481 | pretty->options.print_context_field_names = true; | |
482 | pretty->options.print_header_field_names = true; | |
483 | pretty->options.print_scope_field_names = true; | |
6e1bc0df | 484 | break; |
3228cc1d PP |
485 | case PRETTY_DEFAULT_HIDE: |
486 | pretty->options.print_payload_field_names = false; | |
487 | pretty->options.print_context_field_names = false; | |
488 | pretty->options.print_header_field_names = false; | |
489 | pretty->options.print_scope_field_names = false; | |
6e1bc0df MD |
490 | break; |
491 | default: | |
492 | ret = BT_COMPONENT_STATUS_ERROR; | |
493 | goto end; | |
494 | } | |
495 | ||
496 | value = false; | |
497 | found = false; | |
498 | ret = apply_one_bool("name-payload", params, &value, &found); | |
499 | if (ret != BT_COMPONENT_STATUS_OK) { | |
500 | goto end; | |
501 | } | |
502 | if (found) { | |
3228cc1d | 503 | pretty->options.print_payload_field_names = value; |
6e1bc0df MD |
504 | } |
505 | ||
506 | value = false; | |
507 | found = false; | |
508 | ret = apply_one_bool("name-context", params, &value, &found); | |
509 | if (ret != BT_COMPONENT_STATUS_OK) { | |
510 | goto end; | |
511 | } | |
512 | if (found) { | |
3228cc1d | 513 | pretty->options.print_context_field_names = value; |
6e1bc0df MD |
514 | } |
515 | ||
516 | value = false; | |
517 | found = false; | |
518 | ret = apply_one_bool("name-header", params, &value, &found); | |
519 | if (ret != BT_COMPONENT_STATUS_OK) { | |
520 | goto end; | |
521 | } | |
522 | if (found) { | |
3228cc1d | 523 | pretty->options.print_header_field_names = value; |
6e1bc0df MD |
524 | } |
525 | ||
526 | value = false; | |
527 | found = false; | |
528 | ret = apply_one_bool("name-scope", params, &value, &found); | |
529 | if (ret != BT_COMPONENT_STATUS_OK) { | |
530 | goto end; | |
531 | } | |
532 | if (found) { | |
3228cc1d | 533 | pretty->options.print_scope_field_names = value; |
6e1bc0df MD |
534 | } |
535 | ||
536 | /* Fields. */ | |
537 | ret = apply_one_string("field-default", params, &str); | |
538 | if (ret != BT_COMPONENT_STATUS_OK) { | |
539 | goto end; | |
540 | } | |
541 | if (!str) { | |
3228cc1d | 542 | pretty->options.field_default = PRETTY_DEFAULT_UNSET; |
6e1bc0df | 543 | } else if (!strcmp(str, "show")) { |
3228cc1d | 544 | pretty->options.field_default = PRETTY_DEFAULT_SHOW; |
6e1bc0df | 545 | } else if (!strcmp(str, "hide")) { |
3228cc1d | 546 | pretty->options.field_default = PRETTY_DEFAULT_HIDE; |
6e1bc0df MD |
547 | } else { |
548 | ret = BT_COMPONENT_STATUS_ERROR; | |
549 | goto end; | |
550 | } | |
551 | g_free(str); | |
552 | str = NULL; | |
553 | ||
3228cc1d PP |
554 | switch (pretty->options.field_default) { |
555 | case PRETTY_DEFAULT_UNSET: | |
556 | pretty->options.print_trace_field = false; | |
557 | pretty->options.print_trace_hostname_field = true; | |
558 | pretty->options.print_trace_domain_field = false; | |
559 | pretty->options.print_trace_procname_field = true; | |
560 | pretty->options.print_trace_vpid_field = true; | |
561 | pretty->options.print_loglevel_field = false; | |
562 | pretty->options.print_emf_field = false; | |
563 | pretty->options.print_callsite_field = false; | |
6e1bc0df | 564 | break; |
3228cc1d PP |
565 | case PRETTY_DEFAULT_SHOW: |
566 | pretty->options.print_trace_field = true; | |
567 | pretty->options.print_trace_hostname_field = true; | |
568 | pretty->options.print_trace_domain_field = true; | |
569 | pretty->options.print_trace_procname_field = true; | |
570 | pretty->options.print_trace_vpid_field = true; | |
571 | pretty->options.print_loglevel_field = true; | |
572 | pretty->options.print_emf_field = true; | |
573 | pretty->options.print_callsite_field = true; | |
6e1bc0df | 574 | break; |
3228cc1d PP |
575 | case PRETTY_DEFAULT_HIDE: |
576 | pretty->options.print_trace_field = false; | |
577 | pretty->options.print_trace_hostname_field = false; | |
578 | pretty->options.print_trace_domain_field = false; | |
579 | pretty->options.print_trace_procname_field = false; | |
580 | pretty->options.print_trace_vpid_field = false; | |
581 | pretty->options.print_loglevel_field = false; | |
582 | pretty->options.print_emf_field = false; | |
583 | pretty->options.print_callsite_field = false; | |
6e1bc0df MD |
584 | break; |
585 | default: | |
586 | ret = BT_COMPONENT_STATUS_ERROR; | |
587 | goto end; | |
588 | } | |
589 | ||
590 | value = false; | |
591 | found = false; | |
592 | ret = apply_one_bool("field-trace", params, &value, &found); | |
593 | if (ret != BT_COMPONENT_STATUS_OK) { | |
594 | goto end; | |
595 | } | |
596 | if (found) { | |
3228cc1d | 597 | pretty->options.print_trace_field = value; |
6e1bc0df MD |
598 | } |
599 | ||
600 | value = false; | |
601 | found = false; | |
602 | ret = apply_one_bool("field-trace:hostname", params, &value, &found); | |
603 | if (ret != BT_COMPONENT_STATUS_OK) { | |
604 | goto end; | |
605 | } | |
606 | if (found) { | |
3228cc1d | 607 | pretty->options.print_trace_hostname_field = value; |
6e1bc0df MD |
608 | } |
609 | ||
610 | value = false; | |
611 | found = false; | |
612 | ret = apply_one_bool("field-trace:domain", params, &value, &found); | |
613 | if (ret != BT_COMPONENT_STATUS_OK) { | |
614 | goto end; | |
615 | } | |
616 | if (found) { | |
3228cc1d | 617 | pretty->options.print_trace_domain_field = value; |
6e1bc0df MD |
618 | } |
619 | ||
620 | value = false; | |
621 | found = false; | |
622 | ret = apply_one_bool("field-trace:procname", params, &value, &found); | |
623 | if (ret != BT_COMPONENT_STATUS_OK) { | |
624 | goto end; | |
625 | } | |
626 | if (found) { | |
3228cc1d | 627 | pretty->options.print_trace_procname_field = value; |
6e1bc0df MD |
628 | } |
629 | ||
630 | value = false; | |
631 | found = false; | |
632 | ret = apply_one_bool("field-trace:vpid", params, &value, &found); | |
633 | if (ret != BT_COMPONENT_STATUS_OK) { | |
634 | goto end; | |
635 | } | |
636 | if (found) { | |
3228cc1d | 637 | pretty->options.print_trace_vpid_field = value; |
6e1bc0df MD |
638 | } |
639 | ||
640 | value = false; | |
641 | found = false; | |
642 | ret = apply_one_bool("field-loglevel", params, &value, &found); | |
643 | if (ret != BT_COMPONENT_STATUS_OK) { | |
644 | goto end; | |
645 | } | |
646 | if (found) { | |
3228cc1d | 647 | pretty->options.print_loglevel_field = value; |
6e1bc0df MD |
648 | } |
649 | ||
650 | value = false; | |
651 | found = false; | |
652 | ret = apply_one_bool("field-emf", params, &value, &found); | |
653 | if (ret != BT_COMPONENT_STATUS_OK) { | |
654 | goto end; | |
655 | } | |
656 | if (found) { | |
3228cc1d | 657 | pretty->options.print_emf_field = value; |
6e1bc0df MD |
658 | } |
659 | ||
660 | value = false; | |
661 | found = false; | |
60535549 | 662 | ret = apply_one_bool("field-callsite", params, &value, &found); |
6e1bc0df MD |
663 | if (ret != BT_COMPONENT_STATUS_OK) { |
664 | goto end; | |
665 | } | |
666 | if (found) { | |
3228cc1d | 667 | pretty->options.print_callsite_field = value; |
6e1bc0df MD |
668 | } |
669 | ||
6e1bc0df | 670 | end: |
3228cc1d PP |
671 | bt_put(pretty->plugin_opt_map); |
672 | pretty->plugin_opt_map = NULL; | |
6e1bc0df MD |
673 | g_free(str); |
674 | return ret; | |
675 | } | |
676 | ||
ad96d936 | 677 | static |
3228cc1d | 678 | void set_use_colors(struct pretty_component *pretty) |
ad96d936 | 679 | { |
3228cc1d PP |
680 | switch (pretty->options.color) { |
681 | case PRETTY_COLOR_OPT_ALWAYS: | |
682 | pretty->use_colors = true; | |
ad96d936 | 683 | break; |
3228cc1d PP |
684 | case PRETTY_COLOR_OPT_AUTO: |
685 | pretty->use_colors = pretty->out == stdout && | |
ad96d936 PP |
686 | bt_common_colors_supported(); |
687 | break; | |
3228cc1d PP |
688 | case PRETTY_COLOR_OPT_NEVER: |
689 | pretty->use_colors = false; | |
ad96d936 PP |
690 | break; |
691 | } | |
692 | } | |
693 | ||
2b4c4a7c JD |
694 | static |
695 | void init_stream_packet_context_quarks(void) | |
696 | { | |
697 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = | |
698 | g_quark_from_string("timestamp_begin"); | |
699 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = | |
700 | g_quark_from_string("timestamp_begin"); | |
701 | stream_packet_context_quarks[Q_TIMESTAMP_END] = | |
702 | g_quark_from_string("timestamp_end"); | |
703 | stream_packet_context_quarks[Q_EVENTS_DISCARDED] = | |
704 | g_quark_from_string("events_discarded"); | |
705 | stream_packet_context_quarks[Q_CONTENT_SIZE] = | |
706 | g_quark_from_string("content_size"); | |
707 | stream_packet_context_quarks[Q_PACKET_SIZE] = | |
708 | g_quark_from_string("packet_size"); | |
709 | stream_packet_context_quarks[Q_PACKET_SEQ_NUM] = | |
710 | g_quark_from_string("packet_seq_num"); | |
711 | } | |
712 | ||
3228cc1d PP |
713 | BT_HIDDEN |
714 | enum bt_component_status pretty_init( | |
890882ef PP |
715 | struct bt_private_component *component, |
716 | struct bt_value *params, | |
7d61fa8e | 717 | UNUSED_VAR void *init_method_data) |
bac67f0f JG |
718 | { |
719 | enum bt_component_status ret; | |
3228cc1d | 720 | struct pretty_component *pretty = create_pretty(); |
bac67f0f | 721 | |
3228cc1d | 722 | if (!pretty) { |
bac67f0f JG |
723 | ret = BT_COMPONENT_STATUS_NOMEM; |
724 | goto end; | |
725 | } | |
726 | ||
3228cc1d PP |
727 | pretty->out = stdout; |
728 | pretty->err = stderr; | |
6e1bc0df | 729 | |
3228cc1d PP |
730 | pretty->delta_cycles = -1ULL; |
731 | pretty->last_cycles_timestamp = -1ULL; | |
3af83b5a | 732 | |
3228cc1d PP |
733 | pretty->delta_real_timestamp = -1ULL; |
734 | pretty->last_real_timestamp = -1ULL; | |
3af83b5a | 735 | |
3228cc1d | 736 | ret = apply_params(pretty, params); |
6e1bc0df MD |
737 | if (ret != BT_COMPONENT_STATUS_OK) { |
738 | goto error; | |
739 | } | |
740 | ||
3228cc1d | 741 | set_use_colors(pretty); |
ad96d936 | 742 | |
3228cc1d | 743 | ret = bt_private_component_set_user_data(component, pretty); |
bac67f0f JG |
744 | if (ret != BT_COMPONENT_STATUS_OK) { |
745 | goto error; | |
746 | } | |
2b4c4a7c JD |
747 | |
748 | init_stream_packet_context_quarks(); | |
749 | ||
bac67f0f JG |
750 | end: |
751 | return ret; | |
752 | error: | |
3228cc1d | 753 | destroy_pretty_data(pretty); |
bac67f0f JG |
754 | return ret; |
755 | } |