Logging: standardize logging tags
[babeltrace.git] / src / plugins / text / pretty / pretty.c
CommitLineData
7a278c8e 1/*
2e339de1 2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
f504043c 3 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7a278c8e
JG
4 *
5 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
350ad6c1 26#define BT_LOG_TAG "PLUGIN/SINK.TEXT.PRETTY"
0d2d7e51
FD
27#include "logging.h"
28
3fadfbc0 29#include <babeltrace2/babeltrace.h>
578e048b
MJ
30#include "compat/compiler.h"
31#include "common/common.h"
bfd20a42 32#include <stdio.h>
39cfa40f 33#include <stdbool.h>
bac67f0f 34#include <glib.h>
578e048b 35#include "common/assert.h"
6405967d 36
3228cc1d
PP
37#include "pretty.h"
38
61d6f9b1
MJ
39GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN];
40
6e1bc0df
MD
41static
42const char *plugin_options[] = {
ad96d936 43 "color",
a0ad501b 44 "path",
6e1bc0df
MD
45 "no-delta",
46 "clock-cycles",
47 "clock-seconds",
48 "clock-date",
49 "clock-gmt",
a263021c 50 "verbose",
6e1bc0df
MD
51 "name-default", /* show/hide */
52 "name-payload",
53 "name-context",
54 "name-scope",
55 "name-header",
56 "field-default", /* show/hide */
57 "field-trace",
58 "field-trace:hostname",
59 "field-trace:domain",
60 "field-trace:procname",
61 "field-trace:vpid",
62 "field-loglevel",
63 "field-emf",
60535549 64 "field-callsite",
6e1bc0df
MD
65};
66
5badd463
PP
67static
68const char * const in_port_name = "in";
69
bfd20a42 70static
3228cc1d 71void destroy_pretty_data(struct pretty_component *pretty)
bac67f0f 72{
d6e69534 73 bt_self_component_port_input_message_iterator_put_ref(pretty->iterator);
5280f742
PP
74
75 if (pretty->string) {
76 (void) g_string_free(pretty->string, TRUE);
77 }
78
79 if (pretty->tmp_string) {
80 (void) g_string_free(pretty->tmp_string, TRUE);
81 }
82
3228cc1d 83 if (pretty->out != stdout) {
77986bad
JD
84 int ret;
85
3228cc1d 86 ret = fclose(pretty->out);
77986bad
JD
87 if (ret) {
88 perror("close output file");
89 }
90 }
3228cc1d 91 g_free(pretty->options.output_path);
3228cc1d 92 g_free(pretty);
bac67f0f
JG
93}
94
b25bd455 95static
3228cc1d 96struct pretty_component *create_pretty(void)
bac67f0f 97{
3228cc1d 98 struct pretty_component *pretty;
541b0a11 99
3228cc1d
PP
100 pretty = g_new0(struct pretty_component, 1);
101 if (!pretty) {
541b0a11
JG
102 goto end;
103 }
3228cc1d
PP
104 pretty->string = g_string_new("");
105 if (!pretty->string) {
6a18b281
MD
106 goto error;
107 }
5280f742
PP
108 pretty->tmp_string = g_string_new("");
109 if (!pretty->tmp_string) {
110 goto error;
111 }
541b0a11 112end:
3228cc1d 113 return pretty;
6a18b281
MD
114
115error:
3228cc1d 116 g_free(pretty);
6a18b281 117 return NULL;
bac67f0f
JG
118}
119
3228cc1d 120BT_HIDDEN
b19ff26f 121void pretty_finalize(bt_self_component_sink *comp)
b25bd455 122{
d94d92ac
PP
123 destroy_pretty_data(
124 bt_self_component_get_data(
707b7d35 125 bt_self_component_sink_as_self_component(comp)));
b25bd455
JG
126}
127
bac67f0f 128static
4cdfc5e8 129bt_self_component_status handle_message(
d94d92ac 130 struct pretty_component *pretty,
d6e69534 131 const bt_message *message)
4c1456f0 132{
4cdfc5e8 133 bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
541b0a11 134
f6ccaed9 135 BT_ASSERT(pretty);
541b0a11 136
d6e69534 137 switch (bt_message_get_type(message)) {
d6e69534
PP
138 case BT_MESSAGE_TYPE_EVENT:
139 if (pretty_print_event(pretty, message)) {
d94d92ac
PP
140 ret = BT_SELF_COMPONENT_STATUS_ERROR;
141 }
7cdc2bab 142 break;
8e53bed4
PP
143 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
144 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
145 if (pretty_print_discarded_items(pretty, message)) {
146 ret = BT_SELF_COMPONENT_STATUS_ERROR;
147 }
148 break;
7cdc2bab 149 default:
f42867e2 150 break;
78586d8a 151 }
b5e978f4 152
541b0a11 153 return ret;
4c1456f0 154}
bac67f0f 155
3228cc1d 156BT_HIDDEN
5badd463
PP
157bt_self_component_status pretty_graph_is_configured(
158 bt_self_component_sink *comp)
75e1829b 159{
4cdfc5e8 160 bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
3228cc1d 161 struct pretty_component *pretty;
75e1829b 162
d94d92ac 163 pretty = bt_self_component_get_data(
707b7d35 164 bt_self_component_sink_as_self_component(comp));
f6ccaed9 165 BT_ASSERT(pretty);
d94d92ac 166 BT_ASSERT(!pretty->iterator);
d6e69534 167 pretty->iterator = bt_self_component_port_input_message_iterator_create(
5badd463
PP
168 bt_self_component_sink_borrow_input_port_by_name(comp,
169 in_port_name));
d94d92ac
PP
170 if (!pretty->iterator) {
171 status = BT_SELF_COMPONENT_STATUS_NOMEM;
75e1829b 172 }
72b913fb 173
bf55043c 174 return status;
75e1829b
JG
175}
176
3228cc1d 177BT_HIDDEN
4cdfc5e8 178bt_self_component_status pretty_consume(
b19ff26f 179 bt_self_component_sink *comp)
fec2a9f2 180{
4cdfc5e8 181 bt_self_component_status ret;
d6e69534
PP
182 bt_message_array_const msgs;
183 bt_self_component_port_input_message_iterator *it;
d94d92ac 184 struct pretty_component *pretty = bt_self_component_get_data(
707b7d35 185 bt_self_component_sink_as_self_component(comp));
4cdfc5e8 186 bt_message_iterator_status it_ret;
d4393e08
PP
187 uint64_t count = 0;
188 uint64_t i = 0;
fec2a9f2 189
d94d92ac 190 it = pretty->iterator;
d6e69534
PP
191 it_ret = bt_self_component_port_input_message_iterator_next(it,
192 &msgs, &count);
0d8b4d8e 193
41a2b7ae 194 switch (it_ret) {
d6e69534 195 case BT_MESSAGE_ITERATOR_STATUS_OK:
d94d92ac 196 break;
d6e69534 197 case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
d94d92ac 198 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
41a2b7ae 199 goto end;
d6e69534 200 case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
d94d92ac
PP
201 ret = BT_SELF_COMPONENT_STATUS_AGAIN;
202 goto end;
d6e69534 203 case BT_MESSAGE_ITERATOR_STATUS_END:
d94d92ac 204 ret = BT_SELF_COMPONENT_STATUS_END;
d6e69534 205 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(
c5b9b441 206 pretty->iterator);
dfa6653c 207 goto end;
dfa6653c 208 default:
d94d92ac 209 ret = BT_SELF_COMPONENT_STATUS_ERROR;
dfa6653c 210 goto end;
fec2a9f2
JG
211 }
212
d6e69534 213 BT_ASSERT(it_ret == BT_MESSAGE_ITERATOR_STATUS_OK);
d4393e08
PP
214
215 for (i = 0; i < count; i++) {
d6e69534 216 ret = handle_message(pretty, msgs[i]);
d4393e08
PP
217 if (ret) {
218 goto end;
219 }
220
d6e69534 221 bt_message_put_ref(msgs[i]);
d4393e08 222 }
dfa6653c 223
fec2a9f2 224end:
d4393e08 225 for (; i < count; i++) {
d6e69534 226 bt_message_put_ref(msgs[i]);
d4393e08
PP
227 }
228
fec2a9f2
JG
229 return ret;
230}
231
6e1bc0df 232static
b19ff26f 233int add_params_to_map(bt_value *plugin_opt_map)
6e1bc0df 234{
d94d92ac 235 int ret = 0;
6e1bc0df
MD
236 unsigned int i;
237
238 for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) {
239 const char *key = plugin_options[i];
4cdfc5e8 240 bt_value_status status;
6e1bc0df 241
05e21286 242 status = bt_value_map_insert_entry(plugin_opt_map, key,
da91b29a 243 bt_value_null);
6e1bc0df
MD
244 switch (status) {
245 case BT_VALUE_STATUS_OK:
246 break;
247 default:
d94d92ac 248 ret = -1;
6e1bc0df
MD
249 goto end;
250 }
251 }
252end:
253 return ret;
254}
255
256static
b19ff26f 257bt_bool check_param_exists(const char *key, const bt_value *object,
05e21286 258 void *data)
6e1bc0df 259{
3228cc1d 260 struct pretty_component *pretty = data;
6e1bc0df 261
05e21286
PP
262 if (!bt_value_map_has_entry(pretty->plugin_opt_map,
263 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
270static
b19ff26f 271void apply_one_string(const char *key, const bt_value *params, char **option)
6e1bc0df 272{
b19ff26f 273 const bt_value *value = NULL;
6e1bc0df
MD
274 const char *str;
275
05e21286 276 value = bt_value_map_borrow_entry_value_const(params, key);
6e1bc0df
MD
277 if (!value) {
278 goto end;
279 }
280 if (bt_value_is_null(value)) {
281 goto end;
282 }
601b0d3c 283 str = bt_value_string_get(value);
6e1bc0df 284 *option = g_strdup(str);
601b0d3c 285
6e1bc0df 286end:
d94d92ac 287 return;
6e1bc0df
MD
288}
289
290static
b19ff26f 291void apply_one_bool(const char *key, const bt_value *params, bool *option,
6e1bc0df
MD
292 bool *found)
293{
b19ff26f 294 const bt_value *value = NULL;
c55a9f58 295 bt_bool bool_val;
6e1bc0df 296
05e21286 297 value = bt_value_map_borrow_entry_value_const(params, key);
6e1bc0df
MD
298 if (!value) {
299 goto end;
300 }
601b0d3c 301 bool_val = bt_value_bool_get(value);
c55a9f58 302 *option = (bool) bool_val;
6e1bc0df
MD
303 if (found) {
304 *found = true;
305 }
a82e90e8 306
6e1bc0df 307end:
d94d92ac 308 return;
6e1bc0df
MD
309}
310
ad96d936 311static
3228cc1d 312void 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 318static
d94d92ac 319int open_output_file(struct pretty_component *pretty)
77986bad 320{
d94d92ac 321 int ret = 0;
77986bad 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
334error:
d94d92ac
PP
335 ret = -1;
336
77986bad
JD
337end:
338 return ret;
339}
340
6e1bc0df 341static
b19ff26f 342int apply_params(struct pretty_component *pretty, const bt_value *params)
6e1bc0df 343{
d94d92ac 344 int ret = 0;
4cdfc5e8 345 bt_value_status status;
6e1bc0df
MD
346 bool value, found;
347 char *str = NULL;
348
05e21286 349 pretty->plugin_opt_map = bt_value_map_create();
3228cc1d 350 if (!pretty->plugin_opt_map) {
d94d92ac 351 ret = -1;
6e1bc0df
MD
352 goto end;
353 }
3228cc1d 354 ret = add_params_to_map(pretty->plugin_opt_map);
d94d92ac 355 if (ret) {
6e1bc0df
MD
356 goto end;
357 }
358 /* Report unknown parameters. */
05e21286
PP
359 status = bt_value_map_foreach_entry_const(params,
360 check_param_exists, pretty);
6e1bc0df
MD
361 switch (status) {
362 case BT_VALUE_STATUS_OK:
363 break;
364 default:
d94d92ac 365 ret = -1;
6e1bc0df
MD
366 goto end;
367 }
368 /* Known parameters. */
3228cc1d 369 pretty->options.color = PRETTY_COLOR_OPT_AUTO;
07208d85 370 if (bt_value_map_has_entry(params, "color")) {
b19ff26f 371 const bt_value *color_value;
ad96d936
PP
372 const char *color;
373
05e21286
PP
374 color_value = bt_value_map_borrow_entry_value_const(params,
375 "color");
ad96d936
PP
376 if (!color_value) {
377 goto end;
378 }
379
601b0d3c
PP
380 color = bt_value_string_get(color_value);
381
382 if (strcmp(color, "never") == 0) {
383 pretty->options.color = PRETTY_COLOR_OPT_NEVER;
384 } else if (strcmp(color, "auto") == 0) {
385 pretty->options.color = PRETTY_COLOR_OPT_AUTO;
386 } else if (strcmp(color, "always") == 0) {
387 pretty->options.color = PRETTY_COLOR_OPT_ALWAYS;
ad96d936 388 } else {
601b0d3c 389 warn_wrong_color_param(pretty);
ad96d936 390 }
ad96d936
PP
391 }
392
d94d92ac 393 apply_one_string("path", params, &pretty->options.output_path);
3228cc1d 394 ret = open_output_file(pretty);
d94d92ac 395 if (ret) {
77986bad
JD
396 goto end;
397 }
6e1bc0df 398
6e1bc0df 399 value = false; /* Default. */
d94d92ac 400 apply_one_bool("no-delta", params, &value, NULL);
3228cc1d 401 pretty->options.print_delta_field = !value; /* Reverse logic. */
6e1bc0df
MD
402
403 value = false; /* Default. */
d94d92ac 404 apply_one_bool("clock-cycles", params, &value, NULL);
3228cc1d 405 pretty->options.print_timestamp_cycles = value;
6e1bc0df
MD
406
407 value = false; /* Default. */
d94d92ac 408 apply_one_bool("clock-seconds", params, &value, NULL);
3228cc1d 409 pretty->options.clock_seconds = value;
6e1bc0df
MD
410
411 value = false; /* Default. */
d94d92ac 412 apply_one_bool("clock-date", params, &value, NULL);
3228cc1d 413 pretty->options.clock_date = value;
6e1bc0df
MD
414
415 value = false; /* Default. */
d94d92ac 416 apply_one_bool("clock-gmt", params, &value, NULL);
3228cc1d 417 pretty->options.clock_gmt = value;
6e1bc0df 418
a263021c 419 value = false; /* Default. */
d94d92ac 420 apply_one_bool("verbose", params, &value, NULL);
3228cc1d 421 pretty->options.verbose = value;
a263021c 422
6e1bc0df 423 /* Names. */
d94d92ac 424 apply_one_string("name-default", params, &str);
6e1bc0df 425 if (!str) {
3228cc1d 426 pretty->options.name_default = PRETTY_DEFAULT_UNSET;
6e1bc0df 427 } else if (!strcmp(str, "show")) {
3228cc1d 428 pretty->options.name_default = PRETTY_DEFAULT_SHOW;
6e1bc0df 429 } else if (!strcmp(str, "hide")) {
3228cc1d 430 pretty->options.name_default = PRETTY_DEFAULT_HIDE;
6e1bc0df 431 } else {
d94d92ac 432 ret = -1;
6e1bc0df
MD
433 goto end;
434 }
435 g_free(str);
436 str = NULL;
437
3228cc1d
PP
438 switch (pretty->options.name_default) {
439 case PRETTY_DEFAULT_UNSET:
440 pretty->options.print_payload_field_names = true;
441 pretty->options.print_context_field_names = true;
442 pretty->options.print_header_field_names = false;
443 pretty->options.print_scope_field_names = false;
6e1bc0df 444 break;
3228cc1d
PP
445 case PRETTY_DEFAULT_SHOW:
446 pretty->options.print_payload_field_names = true;
447 pretty->options.print_context_field_names = true;
448 pretty->options.print_header_field_names = true;
449 pretty->options.print_scope_field_names = true;
6e1bc0df 450 break;
3228cc1d
PP
451 case PRETTY_DEFAULT_HIDE:
452 pretty->options.print_payload_field_names = false;
453 pretty->options.print_context_field_names = false;
454 pretty->options.print_header_field_names = false;
455 pretty->options.print_scope_field_names = false;
6e1bc0df
MD
456 break;
457 default:
d94d92ac 458 ret = -1;
6e1bc0df
MD
459 goto end;
460 }
461
462 value = false;
463 found = false;
d94d92ac 464 apply_one_bool("name-payload", params, &value, &found);
6e1bc0df 465 if (found) {
3228cc1d 466 pretty->options.print_payload_field_names = value;
6e1bc0df
MD
467 }
468
469 value = false;
470 found = false;
d94d92ac 471 apply_one_bool("name-context", params, &value, &found);
6e1bc0df 472 if (found) {
3228cc1d 473 pretty->options.print_context_field_names = value;
6e1bc0df
MD
474 }
475
476 value = false;
477 found = false;
d94d92ac 478 apply_one_bool("name-header", params, &value, &found);
6e1bc0df 479 if (found) {
3228cc1d 480 pretty->options.print_header_field_names = value;
6e1bc0df
MD
481 }
482
483 value = false;
484 found = false;
d94d92ac 485 apply_one_bool("name-scope", params, &value, &found);
6e1bc0df 486 if (found) {
3228cc1d 487 pretty->options.print_scope_field_names = value;
6e1bc0df
MD
488 }
489
490 /* Fields. */
d94d92ac 491 apply_one_string("field-default", params, &str);
6e1bc0df 492 if (!str) {
3228cc1d 493 pretty->options.field_default = PRETTY_DEFAULT_UNSET;
6e1bc0df 494 } else if (!strcmp(str, "show")) {
3228cc1d 495 pretty->options.field_default = PRETTY_DEFAULT_SHOW;
6e1bc0df 496 } else if (!strcmp(str, "hide")) {
3228cc1d 497 pretty->options.field_default = PRETTY_DEFAULT_HIDE;
6e1bc0df 498 } else {
d94d92ac 499 ret = -1;
6e1bc0df
MD
500 goto end;
501 }
502 g_free(str);
503 str = NULL;
504
3228cc1d
PP
505 switch (pretty->options.field_default) {
506 case PRETTY_DEFAULT_UNSET:
507 pretty->options.print_trace_field = false;
508 pretty->options.print_trace_hostname_field = true;
509 pretty->options.print_trace_domain_field = false;
510 pretty->options.print_trace_procname_field = true;
511 pretty->options.print_trace_vpid_field = true;
512 pretty->options.print_loglevel_field = false;
513 pretty->options.print_emf_field = false;
514 pretty->options.print_callsite_field = false;
6e1bc0df 515 break;
3228cc1d
PP
516 case PRETTY_DEFAULT_SHOW:
517 pretty->options.print_trace_field = true;
518 pretty->options.print_trace_hostname_field = true;
519 pretty->options.print_trace_domain_field = true;
520 pretty->options.print_trace_procname_field = true;
521 pretty->options.print_trace_vpid_field = true;
522 pretty->options.print_loglevel_field = true;
523 pretty->options.print_emf_field = true;
524 pretty->options.print_callsite_field = true;
6e1bc0df 525 break;
3228cc1d
PP
526 case PRETTY_DEFAULT_HIDE:
527 pretty->options.print_trace_field = false;
528 pretty->options.print_trace_hostname_field = false;
529 pretty->options.print_trace_domain_field = false;
530 pretty->options.print_trace_procname_field = false;
531 pretty->options.print_trace_vpid_field = false;
532 pretty->options.print_loglevel_field = false;
533 pretty->options.print_emf_field = false;
534 pretty->options.print_callsite_field = false;
6e1bc0df
MD
535 break;
536 default:
d94d92ac 537 ret = -1;
6e1bc0df
MD
538 goto end;
539 }
540
541 value = false;
542 found = false;
d94d92ac 543 apply_one_bool("field-trace", params, &value, &found);
6e1bc0df 544 if (found) {
3228cc1d 545 pretty->options.print_trace_field = value;
6e1bc0df
MD
546 }
547
548 value = false;
549 found = false;
d94d92ac 550 apply_one_bool("field-trace:hostname", params, &value, &found);
6e1bc0df 551 if (found) {
3228cc1d 552 pretty->options.print_trace_hostname_field = value;
6e1bc0df
MD
553 }
554
555 value = false;
556 found = false;
d94d92ac 557 apply_one_bool("field-trace:domain", params, &value, &found);
6e1bc0df 558 if (found) {
3228cc1d 559 pretty->options.print_trace_domain_field = value;
6e1bc0df
MD
560 }
561
562 value = false;
563 found = false;
d94d92ac 564 apply_one_bool("field-trace:procname", params, &value, &found);
6e1bc0df 565 if (found) {
3228cc1d 566 pretty->options.print_trace_procname_field = value;
6e1bc0df
MD
567 }
568
569 value = false;
570 found = false;
d94d92ac 571 apply_one_bool("field-trace:vpid", params, &value, &found);
6e1bc0df 572 if (found) {
3228cc1d 573 pretty->options.print_trace_vpid_field = value;
6e1bc0df
MD
574 }
575
576 value = false;
577 found = false;
d94d92ac 578 apply_one_bool("field-loglevel", params, &value, &found);
6e1bc0df 579 if (found) {
3228cc1d 580 pretty->options.print_loglevel_field = value;
6e1bc0df
MD
581 }
582
583 value = false;
584 found = false;
d94d92ac 585 apply_one_bool("field-emf", params, &value, &found);
6e1bc0df 586 if (found) {
3228cc1d 587 pretty->options.print_emf_field = value;
6e1bc0df
MD
588 }
589
590 value = false;
591 found = false;
d94d92ac 592 apply_one_bool("field-callsite", params, &value, &found);
6e1bc0df 593 if (found) {
3228cc1d 594 pretty->options.print_callsite_field = value;
6e1bc0df
MD
595 }
596
6e1bc0df 597end:
c5b9b441 598 bt_value_put_ref(pretty->plugin_opt_map);
3228cc1d 599 pretty->plugin_opt_map = NULL;
6e1bc0df
MD
600 g_free(str);
601 return ret;
602}
603
ad96d936 604static
3228cc1d 605void set_use_colors(struct pretty_component *pretty)
ad96d936 606{
3228cc1d
PP
607 switch (pretty->options.color) {
608 case PRETTY_COLOR_OPT_ALWAYS:
609 pretty->use_colors = true;
ad96d936 610 break;
3228cc1d
PP
611 case PRETTY_COLOR_OPT_AUTO:
612 pretty->use_colors = pretty->out == stdout &&
ad96d936
PP
613 bt_common_colors_supported();
614 break;
3228cc1d
PP
615 case PRETTY_COLOR_OPT_NEVER:
616 pretty->use_colors = false;
ad96d936
PP
617 break;
618 }
619}
620
2b4c4a7c
JD
621static
622void init_stream_packet_context_quarks(void)
623{
624 stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] =
625 g_quark_from_string("timestamp_begin");
626 stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] =
627 g_quark_from_string("timestamp_begin");
628 stream_packet_context_quarks[Q_TIMESTAMP_END] =
629 g_quark_from_string("timestamp_end");
630 stream_packet_context_quarks[Q_EVENTS_DISCARDED] =
631 g_quark_from_string("events_discarded");
632 stream_packet_context_quarks[Q_CONTENT_SIZE] =
633 g_quark_from_string("content_size");
634 stream_packet_context_quarks[Q_PACKET_SIZE] =
635 g_quark_from_string("packet_size");
636 stream_packet_context_quarks[Q_PACKET_SEQ_NUM] =
637 g_quark_from_string("packet_seq_num");
638}
639
3228cc1d 640BT_HIDDEN
4cdfc5e8 641bt_self_component_status pretty_init(
b19ff26f
PP
642 bt_self_component_sink *comp,
643 const bt_value *params,
c88dd1cb 644 __attribute__((unused)) void *init_method_data)
bac67f0f 645{
4cdfc5e8 646 bt_self_component_status ret;
3228cc1d 647 struct pretty_component *pretty = create_pretty();
bac67f0f 648
3228cc1d 649 if (!pretty) {
d94d92ac 650 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
bac67f0f
JG
651 goto end;
652 }
653
5badd463
PP
654 ret = bt_self_component_sink_add_input_port(comp, in_port_name,
655 NULL, NULL);
d94d92ac 656 if (ret != BT_SELF_COMPONENT_STATUS_OK) {
b9d103be
PP
657 goto end;
658 }
659
3228cc1d
PP
660 pretty->out = stdout;
661 pretty->err = stderr;
6e1bc0df 662
3228cc1d
PP
663 pretty->delta_cycles = -1ULL;
664 pretty->last_cycles_timestamp = -1ULL;
3af83b5a 665
3228cc1d
PP
666 pretty->delta_real_timestamp = -1ULL;
667 pretty->last_real_timestamp = -1ULL;
3af83b5a 668
d94d92ac
PP
669 if (apply_params(pretty, params)) {
670 ret = BT_SELF_COMPONENT_STATUS_ERROR;
6e1bc0df
MD
671 goto error;
672 }
673
3228cc1d 674 set_use_colors(pretty);
d94d92ac 675 bt_self_component_set_data(
707b7d35 676 bt_self_component_sink_as_self_component(comp), pretty);
2b4c4a7c
JD
677 init_stream_packet_context_quarks();
678
bac67f0f
JG
679end:
680 return ret;
d94d92ac 681
bac67f0f 682error:
3228cc1d 683 destroy_pretty_data(pretty);
bac67f0f
JG
684 return ret;
685}
This page took 0.08802 seconds and 4 git commands to generate.