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