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