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