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