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