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