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 MD |
55 | "output-path", |
56 | "debug-info-dir", | |
57 | "debug-info-target-prefix", | |
58 | "debug-info-full-path", | |
59 | "no-delta", | |
60 | "clock-cycles", | |
61 | "clock-seconds", | |
62 | "clock-date", | |
63 | "clock-gmt", | |
a263021c | 64 | "verbose", |
6e1bc0df MD |
65 | "name-default", /* show/hide */ |
66 | "name-payload", | |
67 | "name-context", | |
68 | "name-scope", | |
69 | "name-header", | |
70 | "field-default", /* show/hide */ | |
71 | "field-trace", | |
72 | "field-trace:hostname", | |
73 | "field-trace:domain", | |
74 | "field-trace:procname", | |
75 | "field-trace:vpid", | |
76 | "field-loglevel", | |
77 | "field-emf", | |
60535549 | 78 | "field-callsite", |
6e1bc0df MD |
79 | }; |
80 | ||
bfd20a42 | 81 | static |
3228cc1d | 82 | void destroy_pretty_data(struct pretty_component *pretty) |
bac67f0f | 83 | { |
3228cc1d PP |
84 | bt_put(pretty->input_iterator); |
85 | (void) g_string_free(pretty->string, TRUE); | |
86 | if (pretty->out != stdout) { | |
77986bad JD |
87 | int ret; |
88 | ||
3228cc1d | 89 | ret = fclose(pretty->out); |
77986bad JD |
90 | if (ret) { |
91 | perror("close output file"); | |
92 | } | |
93 | } | |
3228cc1d PP |
94 | g_free(pretty->options.output_path); |
95 | g_free(pretty->options.debug_info_dir); | |
96 | g_free(pretty->options.debug_info_target_prefix); | |
97 | g_free(pretty); | |
bac67f0f JG |
98 | } |
99 | ||
b25bd455 | 100 | static |
3228cc1d | 101 | struct pretty_component *create_pretty(void) |
bac67f0f | 102 | { |
3228cc1d | 103 | struct pretty_component *pretty; |
541b0a11 | 104 | |
3228cc1d PP |
105 | pretty = g_new0(struct pretty_component, 1); |
106 | if (!pretty) { | |
541b0a11 JG |
107 | goto end; |
108 | } | |
3228cc1d PP |
109 | pretty->string = g_string_new(""); |
110 | if (!pretty->string) { | |
6a18b281 MD |
111 | goto error; |
112 | } | |
541b0a11 | 113 | end: |
3228cc1d | 114 | return pretty; |
6a18b281 MD |
115 | |
116 | error: | |
3228cc1d | 117 | g_free(pretty); |
6a18b281 | 118 | return NULL; |
bac67f0f JG |
119 | } |
120 | ||
3228cc1d PP |
121 | BT_HIDDEN |
122 | void pretty_finalize(struct bt_private_component *component) | |
b25bd455 | 123 | { |
890882ef | 124 | void *data = bt_private_component_get_user_data(component); |
b25bd455 | 125 | |
3228cc1d | 126 | destroy_pretty_data(data); |
b25bd455 JG |
127 | } |
128 | ||
bac67f0f | 129 | static |
3228cc1d | 130 | enum bt_component_status handle_notification(struct pretty_component *pretty, |
6e1bc0df | 131 | struct bt_notification *notification) |
4c1456f0 | 132 | { |
541b0a11 | 133 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
541b0a11 | 134 | |
3228cc1d | 135 | if (!pretty) { |
541b0a11 JG |
136 | ret = BT_COMPONENT_STATUS_ERROR; |
137 | goto end; | |
138 | } | |
139 | ||
78586d8a | 140 | switch (bt_notification_get_type(notification)) { |
ea0e619e | 141 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: |
78586d8a JG |
142 | break; |
143 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
78586d8a JG |
144 | break; |
145 | case BT_NOTIFICATION_TYPE_EVENT: | |
541b0a11 JG |
146 | { |
147 | struct bt_ctf_event *event = bt_notification_event_get_event( | |
148 | notification); | |
149 | ||
541b0a11 JG |
150 | if (!event) { |
151 | ret = BT_COMPONENT_STATUS_ERROR; | |
152 | goto end; | |
153 | } | |
3228cc1d | 154 | ret = pretty_print_event(pretty, event); |
fec2a9f2 | 155 | bt_put(event); |
541b0a11 JG |
156 | if (ret != BT_COMPONENT_STATUS_OK) { |
157 | goto end; | |
158 | } | |
043e2020 | 159 | break; |
541b0a11 | 160 | } |
043e2020 | 161 | case BT_NOTIFICATION_TYPE_STREAM_END: |
78586d8a JG |
162 | break; |
163 | default: | |
164 | puts("Unhandled notification type"); | |
165 | } | |
541b0a11 JG |
166 | end: |
167 | return ret; | |
4c1456f0 | 168 | } |
bac67f0f | 169 | |
3228cc1d | 170 | BT_HIDDEN |
0d8b4d8e | 171 | void pretty_port_connected( |
890882ef | 172 | struct bt_private_component *component, |
8f4799f7 PP |
173 | struct bt_private_port *self_port, |
174 | struct bt_port *other_port) | |
75e1829b | 175 | { |
890882ef | 176 | struct bt_private_connection *connection; |
3228cc1d | 177 | struct pretty_component *pretty; |
75e1829b | 178 | |
3228cc1d PP |
179 | pretty = bt_private_component_get_user_data(component); |
180 | assert(pretty); | |
181 | assert(!pretty->input_iterator); | |
890882ef | 182 | connection = bt_private_port_get_private_connection(self_port); |
72b913fb | 183 | assert(connection); |
3228cc1d | 184 | pretty->input_iterator = |
890882ef | 185 | bt_private_connection_create_notification_iterator(connection); |
75e1829b | 186 | |
3228cc1d | 187 | if (!pretty->input_iterator) { |
0d8b4d8e | 188 | pretty->error = true; |
75e1829b | 189 | } |
72b913fb PP |
190 | |
191 | bt_put(connection); | |
75e1829b JG |
192 | } |
193 | ||
3228cc1d PP |
194 | BT_HIDDEN |
195 | enum bt_component_status pretty_consume(struct bt_private_component *component) | |
fec2a9f2 JG |
196 | { |
197 | enum bt_component_status ret; | |
198 | struct bt_notification *notification = NULL; | |
199 | struct bt_notification_iterator *it; | |
3228cc1d | 200 | struct pretty_component *pretty = |
890882ef | 201 | bt_private_component_get_user_data(component); |
41a2b7ae | 202 | enum bt_notification_iterator_status it_ret; |
fec2a9f2 | 203 | |
0d8b4d8e PP |
204 | if (unlikely(pretty->error)) { |
205 | ret = BT_COMPONENT_STATUS_ERROR; | |
206 | goto end; | |
207 | } | |
fec2a9f2 | 208 | |
0d8b4d8e | 209 | it = pretty->input_iterator; |
41a2b7ae | 210 | it_ret = bt_notification_iterator_next(it); |
0d8b4d8e | 211 | |
41a2b7ae PP |
212 | switch (it_ret) { |
213 | case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: | |
fec2a9f2 JG |
214 | ret = BT_COMPONENT_STATUS_ERROR; |
215 | goto end; | |
41a2b7ae PP |
216 | case BT_NOTIFICATION_ITERATOR_STATUS_END: |
217 | ret = BT_COMPONENT_STATUS_END; | |
3228cc1d | 218 | BT_PUT(pretty->input_iterator); |
41a2b7ae PP |
219 | goto end; |
220 | default: | |
221 | break; | |
fec2a9f2 JG |
222 | } |
223 | ||
41a2b7ae PP |
224 | notification = bt_notification_iterator_get_notification(it); |
225 | assert(notification); | |
3228cc1d PP |
226 | ret = handle_notification(pretty, notification); |
227 | pretty->processed_first_event = true; | |
fec2a9f2 | 228 | end: |
fec2a9f2 JG |
229 | bt_put(notification); |
230 | return ret; | |
231 | } | |
232 | ||
6e1bc0df MD |
233 | static |
234 | enum bt_component_status add_params_to_map(struct bt_value *plugin_opt_map) | |
235 | { | |
236 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
237 | unsigned int i; | |
238 | ||
239 | for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) { | |
240 | const char *key = plugin_options[i]; | |
241 | enum bt_value_status status; | |
242 | ||
243 | status = bt_value_map_insert(plugin_opt_map, key, bt_value_null); | |
244 | switch (status) { | |
245 | case BT_VALUE_STATUS_OK: | |
246 | break; | |
247 | default: | |
248 | ret = BT_COMPONENT_STATUS_ERROR; | |
249 | goto end; | |
250 | } | |
251 | } | |
252 | end: | |
253 | return ret; | |
254 | } | |
255 | ||
256 | static | |
257 | bool check_param_exists(const char *key, struct bt_value *object, void *data) | |
258 | { | |
3228cc1d PP |
259 | struct pretty_component *pretty = data; |
260 | struct bt_value *plugin_opt_map = pretty->plugin_opt_map; | |
6e1bc0df MD |
261 | |
262 | if (!bt_value_map_get(plugin_opt_map, key)) { | |
3228cc1d PP |
263 | fprintf(pretty->err, |
264 | "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); | |
6e1bc0df MD |
265 | } |
266 | return true; | |
267 | } | |
268 | ||
269 | static | |
270 | enum bt_component_status apply_one_string(const char *key, | |
271 | struct bt_value *params, | |
272 | char **option) | |
273 | { | |
274 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
275 | struct bt_value *value = NULL; | |
276 | enum bt_value_status status; | |
277 | const char *str; | |
278 | ||
279 | value = bt_value_map_get(params, key); | |
280 | if (!value) { | |
281 | goto end; | |
282 | } | |
283 | if (bt_value_is_null(value)) { | |
284 | goto end; | |
285 | } | |
286 | status = bt_value_string_get(value, &str); | |
287 | switch (status) { | |
288 | case BT_VALUE_STATUS_OK: | |
289 | break; | |
290 | default: | |
291 | ret = BT_COMPONENT_STATUS_ERROR; | |
292 | goto end; | |
293 | } | |
294 | *option = g_strdup(str); | |
295 | end: | |
296 | bt_put(value); | |
297 | return ret; | |
298 | } | |
299 | ||
300 | static | |
301 | enum bt_component_status apply_one_bool(const char *key, | |
302 | struct bt_value *params, | |
303 | bool *option, | |
304 | bool *found) | |
305 | { | |
306 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
307 | struct bt_value *value = NULL; | |
308 | enum bt_value_status status; | |
309 | ||
310 | value = bt_value_map_get(params, key); | |
311 | if (!value) { | |
312 | goto end; | |
313 | } | |
314 | status = bt_value_bool_get(value, option); | |
315 | switch (status) { | |
316 | case BT_VALUE_STATUS_OK: | |
317 | break; | |
318 | default: | |
319 | ret = BT_COMPONENT_STATUS_ERROR; | |
320 | goto end; | |
321 | } | |
322 | if (found) { | |
323 | *found = true; | |
324 | } | |
325 | end: | |
326 | bt_put(value); | |
327 | return ret; | |
328 | } | |
329 | ||
ad96d936 | 330 | static |
3228cc1d | 331 | void warn_wrong_color_param(struct pretty_component *pretty) |
ad96d936 | 332 | { |
3228cc1d | 333 | fprintf(pretty->err, |
ad96d936 PP |
334 | "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n"); |
335 | } | |
336 | ||
77986bad | 337 | static |
3228cc1d | 338 | enum bt_component_status open_output_file(struct pretty_component *pretty) |
77986bad JD |
339 | { |
340 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
341 | ||
3228cc1d | 342 | if (!pretty->options.output_path) { |
77986bad JD |
343 | goto end; |
344 | } | |
345 | ||
3228cc1d PP |
346 | pretty->out = fopen(pretty->options.output_path, "w"); |
347 | if (!pretty->out) { | |
77986bad JD |
348 | goto error; |
349 | } | |
350 | ||
351 | goto end; | |
352 | ||
353 | error: | |
354 | ret = BT_COMPONENT_STATUS_ERROR; | |
355 | end: | |
356 | return ret; | |
357 | } | |
358 | ||
6e1bc0df | 359 | static |
3228cc1d | 360 | enum bt_component_status apply_params(struct pretty_component *pretty, |
6e1bc0df MD |
361 | struct bt_value *params) |
362 | { | |
363 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
364 | enum bt_value_status status; | |
365 | bool value, found; | |
366 | char *str = NULL; | |
367 | ||
3228cc1d PP |
368 | pretty->plugin_opt_map = bt_value_map_create(); |
369 | if (!pretty->plugin_opt_map) { | |
6e1bc0df MD |
370 | ret = BT_COMPONENT_STATUS_ERROR; |
371 | goto end; | |
372 | } | |
3228cc1d | 373 | ret = add_params_to_map(pretty->plugin_opt_map); |
6e1bc0df MD |
374 | if (ret != BT_COMPONENT_STATUS_OK) { |
375 | goto end; | |
376 | } | |
377 | /* Report unknown parameters. */ | |
3228cc1d | 378 | status = bt_value_map_foreach(params, check_param_exists, pretty); |
6e1bc0df MD |
379 | switch (status) { |
380 | case BT_VALUE_STATUS_OK: | |
381 | break; | |
382 | default: | |
383 | ret = BT_COMPONENT_STATUS_ERROR; | |
384 | goto end; | |
385 | } | |
386 | /* Known parameters. */ | |
3228cc1d | 387 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
ad96d936 PP |
388 | if (bt_value_map_has_key(params, "color")) { |
389 | struct bt_value *color_value; | |
390 | const char *color; | |
391 | ||
392 | color_value = bt_value_map_get(params, "color"); | |
393 | if (!color_value) { | |
394 | goto end; | |
395 | } | |
396 | ||
72b913fb PP |
397 | status = bt_value_string_get(color_value, &color); |
398 | if (status) { | |
3228cc1d | 399 | warn_wrong_color_param(pretty); |
ad96d936 PP |
400 | } else { |
401 | if (strcmp(color, "never") == 0) { | |
3228cc1d | 402 | pretty->options.color = PRETTY_COLOR_OPT_NEVER; |
ad96d936 | 403 | } else if (strcmp(color, "auto") == 0) { |
3228cc1d | 404 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
ad96d936 | 405 | } else if (strcmp(color, "always") == 0) { |
3228cc1d | 406 | pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; |
ad96d936 | 407 | } else { |
3228cc1d | 408 | warn_wrong_color_param(pretty); |
ad96d936 PP |
409 | } |
410 | } | |
411 | ||
412 | bt_put(color_value); | |
413 | } | |
414 | ||
6e1bc0df MD |
415 | ret = apply_one_string("output-path", |
416 | params, | |
3228cc1d | 417 | &pretty->options.output_path); |
6e1bc0df MD |
418 | if (ret != BT_COMPONENT_STATUS_OK) { |
419 | goto end; | |
420 | } | |
3228cc1d | 421 | ret = open_output_file(pretty); |
77986bad JD |
422 | if (ret != BT_COMPONENT_STATUS_OK) { |
423 | goto end; | |
424 | } | |
6e1bc0df MD |
425 | |
426 | ret = apply_one_string("debug-info-dir", | |
427 | params, | |
3228cc1d | 428 | &pretty->options.debug_info_dir); |
6e1bc0df MD |
429 | if (ret != BT_COMPONENT_STATUS_OK) { |
430 | goto end; | |
431 | } | |
432 | ||
433 | ret = apply_one_string("debug-info-target-prefix", | |
434 | params, | |
3228cc1d | 435 | &pretty->options.debug_info_target_prefix); |
6e1bc0df MD |
436 | if (ret != BT_COMPONENT_STATUS_OK) { |
437 | goto end; | |
438 | } | |
439 | ||
440 | value = false; /* Default. */ | |
441 | ret = apply_one_bool("debug-info-full-path", params, &value, NULL); | |
442 | if (ret != BT_COMPONENT_STATUS_OK) { | |
443 | goto end; | |
444 | } | |
3228cc1d | 445 | pretty->options.debug_info_full_path = value; |
6e1bc0df MD |
446 | |
447 | value = false; /* Default. */ | |
448 | ret = apply_one_bool("no-delta", params, &value, NULL); | |
449 | if (ret != BT_COMPONENT_STATUS_OK) { | |
450 | goto end; | |
451 | } | |
3228cc1d | 452 | pretty->options.print_delta_field = !value; /* Reverse logic. */ |
6e1bc0df MD |
453 | |
454 | value = false; /* Default. */ | |
455 | ret = apply_one_bool("clock-cycles", params, &value, NULL); | |
456 | if (ret != BT_COMPONENT_STATUS_OK) { | |
457 | goto end; | |
458 | } | |
3228cc1d | 459 | pretty->options.print_timestamp_cycles = value; |
6e1bc0df MD |
460 | |
461 | value = false; /* Default. */ | |
462 | ret = apply_one_bool("clock-seconds", params, &value, NULL); | |
463 | if (ret != BT_COMPONENT_STATUS_OK) { | |
464 | goto end; | |
465 | } | |
3228cc1d | 466 | pretty->options.clock_seconds = value; |
6e1bc0df MD |
467 | |
468 | value = false; /* Default. */ | |
469 | ret = apply_one_bool("clock-date", params, &value, NULL); | |
470 | if (ret != BT_COMPONENT_STATUS_OK) { | |
471 | goto end; | |
472 | } | |
3228cc1d | 473 | pretty->options.clock_date = value; |
6e1bc0df MD |
474 | |
475 | value = false; /* Default. */ | |
476 | ret = apply_one_bool("clock-gmt", params, &value, NULL); | |
477 | if (ret != BT_COMPONENT_STATUS_OK) { | |
478 | goto end; | |
479 | } | |
3228cc1d | 480 | pretty->options.clock_gmt = value; |
6e1bc0df | 481 | |
a263021c JD |
482 | value = false; /* Default. */ |
483 | ret = apply_one_bool("verbose", params, &value, NULL); | |
484 | if (ret != BT_COMPONENT_STATUS_OK) { | |
485 | goto end; | |
486 | } | |
3228cc1d | 487 | pretty->options.verbose = value; |
a263021c | 488 | |
6e1bc0df MD |
489 | /* Names. */ |
490 | ret = apply_one_string("name-default", params, &str); | |
491 | if (ret != BT_COMPONENT_STATUS_OK) { | |
492 | goto end; | |
493 | } | |
494 | if (!str) { | |
3228cc1d | 495 | pretty->options.name_default = PRETTY_DEFAULT_UNSET; |
6e1bc0df | 496 | } else if (!strcmp(str, "show")) { |
3228cc1d | 497 | pretty->options.name_default = PRETTY_DEFAULT_SHOW; |
6e1bc0df | 498 | } else if (!strcmp(str, "hide")) { |
3228cc1d | 499 | pretty->options.name_default = PRETTY_DEFAULT_HIDE; |
6e1bc0df MD |
500 | } else { |
501 | ret = BT_COMPONENT_STATUS_ERROR; | |
502 | goto end; | |
503 | } | |
504 | g_free(str); | |
505 | str = NULL; | |
506 | ||
3228cc1d PP |
507 | switch (pretty->options.name_default) { |
508 | case PRETTY_DEFAULT_UNSET: | |
509 | pretty->options.print_payload_field_names = true; | |
510 | pretty->options.print_context_field_names = true; | |
511 | pretty->options.print_header_field_names = false; | |
512 | pretty->options.print_scope_field_names = false; | |
6e1bc0df | 513 | break; |
3228cc1d PP |
514 | case PRETTY_DEFAULT_SHOW: |
515 | pretty->options.print_payload_field_names = true; | |
516 | pretty->options.print_context_field_names = true; | |
517 | pretty->options.print_header_field_names = true; | |
518 | pretty->options.print_scope_field_names = true; | |
6e1bc0df | 519 | break; |
3228cc1d PP |
520 | case PRETTY_DEFAULT_HIDE: |
521 | pretty->options.print_payload_field_names = false; | |
522 | pretty->options.print_context_field_names = false; | |
523 | pretty->options.print_header_field_names = false; | |
524 | pretty->options.print_scope_field_names = false; | |
6e1bc0df MD |
525 | break; |
526 | default: | |
527 | ret = BT_COMPONENT_STATUS_ERROR; | |
528 | goto end; | |
529 | } | |
530 | ||
531 | value = false; | |
532 | found = false; | |
533 | ret = apply_one_bool("name-payload", params, &value, &found); | |
534 | if (ret != BT_COMPONENT_STATUS_OK) { | |
535 | goto end; | |
536 | } | |
537 | if (found) { | |
3228cc1d | 538 | pretty->options.print_payload_field_names = value; |
6e1bc0df MD |
539 | } |
540 | ||
541 | value = false; | |
542 | found = false; | |
543 | ret = apply_one_bool("name-context", params, &value, &found); | |
544 | if (ret != BT_COMPONENT_STATUS_OK) { | |
545 | goto end; | |
546 | } | |
547 | if (found) { | |
3228cc1d | 548 | pretty->options.print_context_field_names = value; |
6e1bc0df MD |
549 | } |
550 | ||
551 | value = false; | |
552 | found = false; | |
553 | ret = apply_one_bool("name-header", params, &value, &found); | |
554 | if (ret != BT_COMPONENT_STATUS_OK) { | |
555 | goto end; | |
556 | } | |
557 | if (found) { | |
3228cc1d | 558 | pretty->options.print_header_field_names = value; |
6e1bc0df MD |
559 | } |
560 | ||
561 | value = false; | |
562 | found = false; | |
563 | ret = apply_one_bool("name-scope", params, &value, &found); | |
564 | if (ret != BT_COMPONENT_STATUS_OK) { | |
565 | goto end; | |
566 | } | |
567 | if (found) { | |
3228cc1d | 568 | pretty->options.print_scope_field_names = value; |
6e1bc0df MD |
569 | } |
570 | ||
571 | /* Fields. */ | |
572 | ret = apply_one_string("field-default", params, &str); | |
573 | if (ret != BT_COMPONENT_STATUS_OK) { | |
574 | goto end; | |
575 | } | |
576 | if (!str) { | |
3228cc1d | 577 | pretty->options.field_default = PRETTY_DEFAULT_UNSET; |
6e1bc0df | 578 | } else if (!strcmp(str, "show")) { |
3228cc1d | 579 | pretty->options.field_default = PRETTY_DEFAULT_SHOW; |
6e1bc0df | 580 | } else if (!strcmp(str, "hide")) { |
3228cc1d | 581 | pretty->options.field_default = PRETTY_DEFAULT_HIDE; |
6e1bc0df MD |
582 | } else { |
583 | ret = BT_COMPONENT_STATUS_ERROR; | |
584 | goto end; | |
585 | } | |
586 | g_free(str); | |
587 | str = NULL; | |
588 | ||
3228cc1d PP |
589 | switch (pretty->options.field_default) { |
590 | case PRETTY_DEFAULT_UNSET: | |
591 | pretty->options.print_trace_field = false; | |
592 | pretty->options.print_trace_hostname_field = true; | |
593 | pretty->options.print_trace_domain_field = false; | |
594 | pretty->options.print_trace_procname_field = true; | |
595 | pretty->options.print_trace_vpid_field = true; | |
596 | pretty->options.print_loglevel_field = false; | |
597 | pretty->options.print_emf_field = false; | |
598 | pretty->options.print_callsite_field = false; | |
6e1bc0df | 599 | break; |
3228cc1d PP |
600 | case PRETTY_DEFAULT_SHOW: |
601 | pretty->options.print_trace_field = true; | |
602 | pretty->options.print_trace_hostname_field = true; | |
603 | pretty->options.print_trace_domain_field = true; | |
604 | pretty->options.print_trace_procname_field = true; | |
605 | pretty->options.print_trace_vpid_field = true; | |
606 | pretty->options.print_loglevel_field = true; | |
607 | pretty->options.print_emf_field = true; | |
608 | pretty->options.print_callsite_field = true; | |
6e1bc0df | 609 | break; |
3228cc1d PP |
610 | case PRETTY_DEFAULT_HIDE: |
611 | pretty->options.print_trace_field = false; | |
612 | pretty->options.print_trace_hostname_field = false; | |
613 | pretty->options.print_trace_domain_field = false; | |
614 | pretty->options.print_trace_procname_field = false; | |
615 | pretty->options.print_trace_vpid_field = false; | |
616 | pretty->options.print_loglevel_field = false; | |
617 | pretty->options.print_emf_field = false; | |
618 | pretty->options.print_callsite_field = false; | |
6e1bc0df MD |
619 | break; |
620 | default: | |
621 | ret = BT_COMPONENT_STATUS_ERROR; | |
622 | goto end; | |
623 | } | |
624 | ||
625 | value = false; | |
626 | found = false; | |
627 | ret = apply_one_bool("field-trace", params, &value, &found); | |
628 | if (ret != BT_COMPONENT_STATUS_OK) { | |
629 | goto end; | |
630 | } | |
631 | if (found) { | |
3228cc1d | 632 | pretty->options.print_trace_field = value; |
6e1bc0df MD |
633 | } |
634 | ||
635 | value = false; | |
636 | found = false; | |
637 | ret = apply_one_bool("field-trace:hostname", params, &value, &found); | |
638 | if (ret != BT_COMPONENT_STATUS_OK) { | |
639 | goto end; | |
640 | } | |
641 | if (found) { | |
3228cc1d | 642 | pretty->options.print_trace_hostname_field = value; |
6e1bc0df MD |
643 | } |
644 | ||
645 | value = false; | |
646 | found = false; | |
647 | ret = apply_one_bool("field-trace:domain", params, &value, &found); | |
648 | if (ret != BT_COMPONENT_STATUS_OK) { | |
649 | goto end; | |
650 | } | |
651 | if (found) { | |
3228cc1d | 652 | pretty->options.print_trace_domain_field = value; |
6e1bc0df MD |
653 | } |
654 | ||
655 | value = false; | |
656 | found = false; | |
657 | ret = apply_one_bool("field-trace:procname", params, &value, &found); | |
658 | if (ret != BT_COMPONENT_STATUS_OK) { | |
659 | goto end; | |
660 | } | |
661 | if (found) { | |
3228cc1d | 662 | pretty->options.print_trace_procname_field = value; |
6e1bc0df MD |
663 | } |
664 | ||
665 | value = false; | |
666 | found = false; | |
667 | ret = apply_one_bool("field-trace:vpid", params, &value, &found); | |
668 | if (ret != BT_COMPONENT_STATUS_OK) { | |
669 | goto end; | |
670 | } | |
671 | if (found) { | |
3228cc1d | 672 | pretty->options.print_trace_vpid_field = value; |
6e1bc0df MD |
673 | } |
674 | ||
675 | value = false; | |
676 | found = false; | |
677 | ret = apply_one_bool("field-loglevel", params, &value, &found); | |
678 | if (ret != BT_COMPONENT_STATUS_OK) { | |
679 | goto end; | |
680 | } | |
681 | if (found) { | |
3228cc1d | 682 | pretty->options.print_loglevel_field = value; |
6e1bc0df MD |
683 | } |
684 | ||
685 | value = false; | |
686 | found = false; | |
687 | ret = apply_one_bool("field-emf", params, &value, &found); | |
688 | if (ret != BT_COMPONENT_STATUS_OK) { | |
689 | goto end; | |
690 | } | |
691 | if (found) { | |
3228cc1d | 692 | pretty->options.print_emf_field = value; |
6e1bc0df MD |
693 | } |
694 | ||
695 | value = false; | |
696 | found = false; | |
60535549 | 697 | ret = apply_one_bool("field-callsite", params, &value, &found); |
6e1bc0df MD |
698 | if (ret != BT_COMPONENT_STATUS_OK) { |
699 | goto end; | |
700 | } | |
701 | if (found) { | |
3228cc1d | 702 | pretty->options.print_callsite_field = value; |
6e1bc0df MD |
703 | } |
704 | ||
6e1bc0df | 705 | end: |
3228cc1d PP |
706 | bt_put(pretty->plugin_opt_map); |
707 | pretty->plugin_opt_map = NULL; | |
6e1bc0df MD |
708 | g_free(str); |
709 | return ret; | |
710 | } | |
711 | ||
ad96d936 | 712 | static |
3228cc1d | 713 | void set_use_colors(struct pretty_component *pretty) |
ad96d936 | 714 | { |
3228cc1d PP |
715 | switch (pretty->options.color) { |
716 | case PRETTY_COLOR_OPT_ALWAYS: | |
717 | pretty->use_colors = true; | |
ad96d936 | 718 | break; |
3228cc1d PP |
719 | case PRETTY_COLOR_OPT_AUTO: |
720 | pretty->use_colors = pretty->out == stdout && | |
ad96d936 PP |
721 | bt_common_colors_supported(); |
722 | break; | |
3228cc1d PP |
723 | case PRETTY_COLOR_OPT_NEVER: |
724 | pretty->use_colors = false; | |
ad96d936 PP |
725 | break; |
726 | } | |
727 | } | |
728 | ||
2b4c4a7c JD |
729 | static |
730 | void init_stream_packet_context_quarks(void) | |
731 | { | |
732 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = | |
733 | g_quark_from_string("timestamp_begin"); | |
734 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = | |
735 | g_quark_from_string("timestamp_begin"); | |
736 | stream_packet_context_quarks[Q_TIMESTAMP_END] = | |
737 | g_quark_from_string("timestamp_end"); | |
738 | stream_packet_context_quarks[Q_EVENTS_DISCARDED] = | |
739 | g_quark_from_string("events_discarded"); | |
740 | stream_packet_context_quarks[Q_CONTENT_SIZE] = | |
741 | g_quark_from_string("content_size"); | |
742 | stream_packet_context_quarks[Q_PACKET_SIZE] = | |
743 | g_quark_from_string("packet_size"); | |
744 | stream_packet_context_quarks[Q_PACKET_SEQ_NUM] = | |
745 | g_quark_from_string("packet_seq_num"); | |
746 | } | |
747 | ||
3228cc1d PP |
748 | BT_HIDDEN |
749 | enum bt_component_status pretty_init( | |
890882ef PP |
750 | struct bt_private_component *component, |
751 | struct bt_value *params, | |
7d61fa8e | 752 | UNUSED_VAR void *init_method_data) |
bac67f0f JG |
753 | { |
754 | enum bt_component_status ret; | |
3228cc1d | 755 | struct pretty_component *pretty = create_pretty(); |
bac67f0f | 756 | |
3228cc1d | 757 | if (!pretty) { |
bac67f0f JG |
758 | ret = BT_COMPONENT_STATUS_NOMEM; |
759 | goto end; | |
760 | } | |
761 | ||
3228cc1d PP |
762 | pretty->out = stdout; |
763 | pretty->err = stderr; | |
6e1bc0df | 764 | |
3228cc1d PP |
765 | pretty->delta_cycles = -1ULL; |
766 | pretty->last_cycles_timestamp = -1ULL; | |
3af83b5a | 767 | |
3228cc1d PP |
768 | pretty->delta_real_timestamp = -1ULL; |
769 | pretty->last_real_timestamp = -1ULL; | |
3af83b5a | 770 | |
3228cc1d | 771 | ret = apply_params(pretty, params); |
6e1bc0df MD |
772 | if (ret != BT_COMPONENT_STATUS_OK) { |
773 | goto error; | |
774 | } | |
775 | ||
3228cc1d | 776 | set_use_colors(pretty); |
ad96d936 | 777 | |
3228cc1d | 778 | ret = bt_private_component_set_user_data(component, pretty); |
bac67f0f JG |
779 | if (ret != BT_COMPONENT_STATUS_OK) { |
780 | goto error; | |
781 | } | |
2b4c4a7c JD |
782 | |
783 | init_stream_packet_context_quarks(); | |
784 | ||
bac67f0f JG |
785 | end: |
786 | return ret; | |
787 | error: | |
3228cc1d | 788 | destroy_pretty_data(pretty); |
bac67f0f JG |
789 | return ret; |
790 | } |