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