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