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