lib: rename transforming bt_X_borrow_Y() -> bt_X_as_Y()
[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>
6e1bc0df 27#include <babeltrace/values.h>
3d9990ac 28#include <babeltrace/compiler-internal.h>
ad96d936 29#include <babeltrace/common-internal.h>
7d61fa8e 30#include <plugins-common.h>
bfd20a42 31#include <stdio.h>
39cfa40f 32#include <stdbool.h>
bac67f0f 33#include <glib.h>
f6ccaed9 34#include <babeltrace/assert-internal.h>
6405967d 35
3228cc1d
PP
36#include "pretty.h"
37
61d6f9b1
MJ
38GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN];
39
6e1bc0df
MD
40static
41const char *plugin_options[] = {
ad96d936 42 "color",
a0ad501b 43 "path",
6e1bc0df
MD
44 "no-delta",
45 "clock-cycles",
46 "clock-seconds",
47 "clock-date",
48 "clock-gmt",
a263021c 49 "verbose",
6e1bc0df
MD
50 "name-default", /* show/hide */
51 "name-payload",
52 "name-context",
53 "name-scope",
54 "name-header",
55 "field-default", /* show/hide */
56 "field-trace",
57 "field-trace:hostname",
58 "field-trace:domain",
59 "field-trace:procname",
60 "field-trace:vpid",
61 "field-loglevel",
62 "field-emf",
60535549 63 "field-callsite",
6e1bc0df
MD
64};
65
bfd20a42 66static
3228cc1d 67void destroy_pretty_data(struct pretty_component *pretty)
bac67f0f 68{
d94d92ac 69 bt_object_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
d94d92ac 117void pretty_finalize(struct 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
d94d92ac
PP
125enum bt_self_component_status handle_notification(
126 struct pretty_component *pretty,
6e1bc0df 127 struct bt_notification *notification)
4c1456f0 128{
d94d92ac 129 enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
541b0a11 130
f6ccaed9 131 BT_ASSERT(pretty);
541b0a11 132
7cdc2bab 133 switch (bt_notification_get_type(notification)) {
0f6bea4e 134 case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
d94d92ac
PP
135 if (pretty_print_packet(pretty, notification)) {
136 ret = BT_SELF_COMPONENT_STATUS_ERROR;
137 }
0f6bea4e 138 break;
7cdc2bab 139 case BT_NOTIFICATION_TYPE_EVENT:
d94d92ac
PP
140 if (pretty_print_event(pretty, notification)) {
141 ret = BT_SELF_COMPONENT_STATUS_ERROR;
142 }
7cdc2bab
MD
143 break;
144 case BT_NOTIFICATION_TYPE_INACTIVITY:
145 fprintf(stderr, "Inactivity notification\n");
146 break;
7cdc2bab 147 default:
f42867e2 148 break;
78586d8a 149 }
b5e978f4 150
541b0a11 151 return ret;
4c1456f0 152}
bac67f0f 153
3228cc1d 154BT_HIDDEN
d94d92ac
PP
155enum bt_self_component_status pretty_port_connected(
156 struct bt_self_component_sink *comp,
157 struct bt_self_component_port_input *self_port,
158 struct bt_port_output *other_port)
75e1829b 159{
d94d92ac 160 enum 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
PP
166 BT_ASSERT(!pretty->iterator);
167 pretty->iterator = bt_self_component_port_input_notification_iterator_create(
168 self_port);
169 if (!pretty->iterator) {
170 status = BT_SELF_COMPONENT_STATUS_NOMEM;
75e1829b 171 }
72b913fb 172
bf55043c 173 return status;
75e1829b
JG
174}
175
3228cc1d 176BT_HIDDEN
d94d92ac
PP
177enum bt_self_component_status pretty_consume(
178 struct bt_self_component_sink *comp)
fec2a9f2 179{
d94d92ac 180 enum bt_self_component_status ret;
d4393e08 181 bt_notification_array notifs;
d94d92ac
PP
182 struct bt_self_component_port_input_notification_iterator *it;
183 struct pretty_component *pretty = bt_self_component_get_data(
707b7d35 184 bt_self_component_sink_as_self_component(comp));
41a2b7ae 185 enum bt_notification_iterator_status it_ret;
d4393e08
PP
186 uint64_t count = 0;
187 uint64_t i = 0;
fec2a9f2 188
d94d92ac
PP
189 it = pretty->iterator;
190 it_ret = bt_self_component_port_input_notification_iterator_next(it,
191 &notifs, &count);
0d8b4d8e 192
41a2b7ae 193 switch (it_ret) {
d94d92ac
PP
194 case BT_NOTIFICATION_ITERATOR_STATUS_OK:
195 break;
196 case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM:
197 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
41a2b7ae 198 goto end;
dfa6653c 199 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
d94d92ac
PP
200 ret = BT_SELF_COMPONENT_STATUS_AGAIN;
201 goto end;
202 case BT_NOTIFICATION_ITERATOR_STATUS_END:
203 ret = BT_SELF_COMPONENT_STATUS_END;
204 BT_OBJECT_PUT_REF_AND_RESET(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
d4393e08
PP
211 BT_ASSERT(it_ret == BT_NOTIFICATION_ITERATOR_STATUS_OK);
212
213 for (i = 0; i < count; i++) {
214 ret = handle_notification(pretty, notifs[i]);
215 if (ret) {
216 goto end;
217 }
218
65300d60 219 bt_object_put_ref(notifs[i]);
d4393e08 220 }
dfa6653c 221
fec2a9f2 222end:
d4393e08 223 for (; i < count; i++) {
65300d60 224 bt_object_put_ref(notifs[i]);
d4393e08
PP
225 }
226
fec2a9f2
JG
227 return ret;
228}
229
6e1bc0df 230static
d94d92ac 231int add_params_to_map(struct bt_private_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
da91b29a
PP
240 status = bt_private_value_map_insert_entry(plugin_opt_map, key,
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
c55a9f58 255bt_bool check_param_exists(const char *key, struct bt_value *object, void *data)
6e1bc0df 256{
3228cc1d 257 struct pretty_component *pretty = data;
6e1bc0df 258
da91b29a 259 if (!bt_value_map_has_entry(
707b7d35 260 bt_private_value_as_value(pretty->plugin_opt_map),
da91b29a 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
d94d92ac 269void apply_one_string(const char *key, struct bt_value *params, char **option)
6e1bc0df 270{
6e1bc0df 271 struct bt_value *value = NULL;
6e1bc0df
MD
272 const char *str;
273
07208d85 274 value = bt_value_map_borrow_entry_value(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
d94d92ac 289void apply_one_bool(const char *key, struct bt_value *params, bool *option,
6e1bc0df
MD
290 bool *found)
291{
6e1bc0df 292 struct bt_value *value = NULL;
c55a9f58 293 bt_bool bool_val;
6e1bc0df 294
07208d85 295 value = bt_value_map_borrow_entry_value(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
d94d92ac 340int apply_params(struct pretty_component *pretty, struct 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
da91b29a 347 pretty->plugin_opt_map = bt_private_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. */
07208d85 357 status = bt_value_map_foreach_entry(params, check_param_exists, pretty);
6e1bc0df
MD
358 switch (status) {
359 case BT_VALUE_STATUS_OK:
360 break;
361 default:
d94d92ac 362 ret = -1;
6e1bc0df
MD
363 goto end;
364 }
365 /* Known parameters. */
3228cc1d 366 pretty->options.color = PRETTY_COLOR_OPT_AUTO;
07208d85 367 if (bt_value_map_has_entry(params, "color")) {
ad96d936
PP
368 struct bt_value *color_value;
369 const char *color;
370
07208d85 371 color_value = bt_value_map_borrow_entry_value(params, "color");
ad96d936
PP
372 if (!color_value) {
373 goto end;
374 }
375
601b0d3c
PP
376 color = bt_value_string_get(color_value);
377
378 if (strcmp(color, "never") == 0) {
379 pretty->options.color = PRETTY_COLOR_OPT_NEVER;
380 } else if (strcmp(color, "auto") == 0) {
381 pretty->options.color = PRETTY_COLOR_OPT_AUTO;
382 } else if (strcmp(color, "always") == 0) {
383 pretty->options.color = PRETTY_COLOR_OPT_ALWAYS;
ad96d936 384 } else {
601b0d3c 385 warn_wrong_color_param(pretty);
ad96d936 386 }
ad96d936
PP
387 }
388
d94d92ac 389 apply_one_string("path", params, &pretty->options.output_path);
3228cc1d 390 ret = open_output_file(pretty);
d94d92ac 391 if (ret) {
77986bad
JD
392 goto end;
393 }
6e1bc0df 394
6e1bc0df 395 value = false; /* Default. */
d94d92ac 396 apply_one_bool("no-delta", params, &value, NULL);
3228cc1d 397 pretty->options.print_delta_field = !value; /* Reverse logic. */
6e1bc0df
MD
398
399 value = false; /* Default. */
d94d92ac 400 apply_one_bool("clock-cycles", params, &value, NULL);
3228cc1d 401 pretty->options.print_timestamp_cycles = value;
6e1bc0df
MD
402
403 value = false; /* Default. */
d94d92ac 404 apply_one_bool("clock-seconds", params, &value, NULL);
3228cc1d 405 pretty->options.clock_seconds = value;
6e1bc0df
MD
406
407 value = false; /* Default. */
d94d92ac 408 apply_one_bool("clock-date", params, &value, NULL);
3228cc1d 409 pretty->options.clock_date = value;
6e1bc0df
MD
410
411 value = false; /* Default. */
d94d92ac 412 apply_one_bool("clock-gmt", params, &value, NULL);
3228cc1d 413 pretty->options.clock_gmt = value;
6e1bc0df 414
a263021c 415 value = false; /* Default. */
d94d92ac 416 apply_one_bool("verbose", params, &value, NULL);
3228cc1d 417 pretty->options.verbose = value;
a263021c 418
6e1bc0df 419 /* Names. */
d94d92ac 420 apply_one_string("name-default", params, &str);
6e1bc0df 421 if (!str) {
3228cc1d 422 pretty->options.name_default = PRETTY_DEFAULT_UNSET;
6e1bc0df 423 } else if (!strcmp(str, "show")) {
3228cc1d 424 pretty->options.name_default = PRETTY_DEFAULT_SHOW;
6e1bc0df 425 } else if (!strcmp(str, "hide")) {
3228cc1d 426 pretty->options.name_default = PRETTY_DEFAULT_HIDE;
6e1bc0df 427 } else {
d94d92ac 428 ret = -1;
6e1bc0df
MD
429 goto end;
430 }
431 g_free(str);
432 str = NULL;
433
3228cc1d
PP
434 switch (pretty->options.name_default) {
435 case PRETTY_DEFAULT_UNSET:
436 pretty->options.print_payload_field_names = true;
437 pretty->options.print_context_field_names = true;
438 pretty->options.print_header_field_names = false;
439 pretty->options.print_scope_field_names = false;
6e1bc0df 440 break;
3228cc1d
PP
441 case PRETTY_DEFAULT_SHOW:
442 pretty->options.print_payload_field_names = true;
443 pretty->options.print_context_field_names = true;
444 pretty->options.print_header_field_names = true;
445 pretty->options.print_scope_field_names = true;
6e1bc0df 446 break;
3228cc1d
PP
447 case PRETTY_DEFAULT_HIDE:
448 pretty->options.print_payload_field_names = false;
449 pretty->options.print_context_field_names = false;
450 pretty->options.print_header_field_names = false;
451 pretty->options.print_scope_field_names = false;
6e1bc0df
MD
452 break;
453 default:
d94d92ac 454 ret = -1;
6e1bc0df
MD
455 goto end;
456 }
457
458 value = false;
459 found = false;
d94d92ac 460 apply_one_bool("name-payload", params, &value, &found);
6e1bc0df 461 if (found) {
3228cc1d 462 pretty->options.print_payload_field_names = value;
6e1bc0df
MD
463 }
464
465 value = false;
466 found = false;
d94d92ac 467 apply_one_bool("name-context", params, &value, &found);
6e1bc0df 468 if (found) {
3228cc1d 469 pretty->options.print_context_field_names = value;
6e1bc0df
MD
470 }
471
472 value = false;
473 found = false;
d94d92ac 474 apply_one_bool("name-header", params, &value, &found);
6e1bc0df 475 if (found) {
3228cc1d 476 pretty->options.print_header_field_names = value;
6e1bc0df
MD
477 }
478
479 value = false;
480 found = false;
d94d92ac 481 apply_one_bool("name-scope", params, &value, &found);
6e1bc0df 482 if (found) {
3228cc1d 483 pretty->options.print_scope_field_names = value;
6e1bc0df
MD
484 }
485
486 /* Fields. */
d94d92ac 487 apply_one_string("field-default", params, &str);
6e1bc0df 488 if (!str) {
3228cc1d 489 pretty->options.field_default = PRETTY_DEFAULT_UNSET;
6e1bc0df 490 } else if (!strcmp(str, "show")) {
3228cc1d 491 pretty->options.field_default = PRETTY_DEFAULT_SHOW;
6e1bc0df 492 } else if (!strcmp(str, "hide")) {
3228cc1d 493 pretty->options.field_default = PRETTY_DEFAULT_HIDE;
6e1bc0df 494 } else {
d94d92ac 495 ret = -1;
6e1bc0df
MD
496 goto end;
497 }
498 g_free(str);
499 str = NULL;
500
3228cc1d
PP
501 switch (pretty->options.field_default) {
502 case PRETTY_DEFAULT_UNSET:
503 pretty->options.print_trace_field = false;
504 pretty->options.print_trace_hostname_field = true;
505 pretty->options.print_trace_domain_field = false;
506 pretty->options.print_trace_procname_field = true;
507 pretty->options.print_trace_vpid_field = true;
508 pretty->options.print_loglevel_field = false;
509 pretty->options.print_emf_field = false;
510 pretty->options.print_callsite_field = false;
6e1bc0df 511 break;
3228cc1d
PP
512 case PRETTY_DEFAULT_SHOW:
513 pretty->options.print_trace_field = true;
514 pretty->options.print_trace_hostname_field = true;
515 pretty->options.print_trace_domain_field = true;
516 pretty->options.print_trace_procname_field = true;
517 pretty->options.print_trace_vpid_field = true;
518 pretty->options.print_loglevel_field = true;
519 pretty->options.print_emf_field = true;
520 pretty->options.print_callsite_field = true;
6e1bc0df 521 break;
3228cc1d
PP
522 case PRETTY_DEFAULT_HIDE:
523 pretty->options.print_trace_field = false;
524 pretty->options.print_trace_hostname_field = false;
525 pretty->options.print_trace_domain_field = false;
526 pretty->options.print_trace_procname_field = false;
527 pretty->options.print_trace_vpid_field = false;
528 pretty->options.print_loglevel_field = false;
529 pretty->options.print_emf_field = false;
530 pretty->options.print_callsite_field = false;
6e1bc0df
MD
531 break;
532 default:
d94d92ac 533 ret = -1;
6e1bc0df
MD
534 goto end;
535 }
536
537 value = false;
538 found = false;
d94d92ac 539 apply_one_bool("field-trace", params, &value, &found);
6e1bc0df 540 if (found) {
3228cc1d 541 pretty->options.print_trace_field = value;
6e1bc0df
MD
542 }
543
544 value = false;
545 found = false;
d94d92ac 546 apply_one_bool("field-trace:hostname", params, &value, &found);
6e1bc0df 547 if (found) {
3228cc1d 548 pretty->options.print_trace_hostname_field = value;
6e1bc0df
MD
549 }
550
551 value = false;
552 found = false;
d94d92ac 553 apply_one_bool("field-trace:domain", params, &value, &found);
6e1bc0df 554 if (found) {
3228cc1d 555 pretty->options.print_trace_domain_field = value;
6e1bc0df
MD
556 }
557
558 value = false;
559 found = false;
d94d92ac 560 apply_one_bool("field-trace:procname", params, &value, &found);
6e1bc0df 561 if (found) {
3228cc1d 562 pretty->options.print_trace_procname_field = value;
6e1bc0df
MD
563 }
564
565 value = false;
566 found = false;
d94d92ac 567 apply_one_bool("field-trace:vpid", params, &value, &found);
6e1bc0df 568 if (found) {
3228cc1d 569 pretty->options.print_trace_vpid_field = value;
6e1bc0df
MD
570 }
571
572 value = false;
573 found = false;
d94d92ac 574 apply_one_bool("field-loglevel", params, &value, &found);
6e1bc0df 575 if (found) {
3228cc1d 576 pretty->options.print_loglevel_field = value;
6e1bc0df
MD
577 }
578
579 value = false;
580 found = false;
d94d92ac 581 apply_one_bool("field-emf", params, &value, &found);
6e1bc0df 582 if (found) {
3228cc1d 583 pretty->options.print_emf_field = value;
6e1bc0df
MD
584 }
585
586 value = false;
587 found = false;
d94d92ac 588 apply_one_bool("field-callsite", params, &value, &found);
6e1bc0df 589 if (found) {
3228cc1d 590 pretty->options.print_callsite_field = value;
6e1bc0df
MD
591 }
592
6e1bc0df 593end:
65300d60 594 bt_object_put_ref(pretty->plugin_opt_map);
3228cc1d 595 pretty->plugin_opt_map = NULL;
6e1bc0df
MD
596 g_free(str);
597 return ret;
598}
599
ad96d936 600static
3228cc1d 601void set_use_colors(struct pretty_component *pretty)
ad96d936 602{
3228cc1d
PP
603 switch (pretty->options.color) {
604 case PRETTY_COLOR_OPT_ALWAYS:
605 pretty->use_colors = true;
ad96d936 606 break;
3228cc1d
PP
607 case PRETTY_COLOR_OPT_AUTO:
608 pretty->use_colors = pretty->out == stdout &&
ad96d936
PP
609 bt_common_colors_supported();
610 break;
3228cc1d
PP
611 case PRETTY_COLOR_OPT_NEVER:
612 pretty->use_colors = false;
ad96d936
PP
613 break;
614 }
615}
616
2b4c4a7c
JD
617static
618void init_stream_packet_context_quarks(void)
619{
620 stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] =
621 g_quark_from_string("timestamp_begin");
622 stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] =
623 g_quark_from_string("timestamp_begin");
624 stream_packet_context_quarks[Q_TIMESTAMP_END] =
625 g_quark_from_string("timestamp_end");
626 stream_packet_context_quarks[Q_EVENTS_DISCARDED] =
627 g_quark_from_string("events_discarded");
628 stream_packet_context_quarks[Q_CONTENT_SIZE] =
629 g_quark_from_string("content_size");
630 stream_packet_context_quarks[Q_PACKET_SIZE] =
631 g_quark_from_string("packet_size");
632 stream_packet_context_quarks[Q_PACKET_SEQ_NUM] =
633 g_quark_from_string("packet_seq_num");
634}
635
3228cc1d 636BT_HIDDEN
d94d92ac
PP
637enum bt_self_component_status pretty_init(
638 struct bt_self_component_sink *comp,
890882ef 639 struct bt_value *params,
7d61fa8e 640 UNUSED_VAR void *init_method_data)
bac67f0f 641{
d94d92ac 642 enum bt_self_component_status ret;
3228cc1d 643 struct pretty_component *pretty = create_pretty();
bac67f0f 644
3228cc1d 645 if (!pretty) {
d94d92ac 646 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
bac67f0f
JG
647 goto end;
648 }
649
d94d92ac
PP
650 ret = bt_self_component_sink_add_input_port(comp, "in", NULL, NULL);
651 if (ret != BT_SELF_COMPONENT_STATUS_OK) {
b9d103be
PP
652 goto end;
653 }
654
3228cc1d
PP
655 pretty->out = stdout;
656 pretty->err = stderr;
6e1bc0df 657
3228cc1d
PP
658 pretty->delta_cycles = -1ULL;
659 pretty->last_cycles_timestamp = -1ULL;
3af83b5a 660
3228cc1d
PP
661 pretty->delta_real_timestamp = -1ULL;
662 pretty->last_real_timestamp = -1ULL;
3af83b5a 663
d94d92ac
PP
664 if (apply_params(pretty, params)) {
665 ret = BT_SELF_COMPONENT_STATUS_ERROR;
6e1bc0df
MD
666 goto error;
667 }
668
3228cc1d 669 set_use_colors(pretty);
d94d92ac 670 bt_self_component_set_data(
707b7d35 671 bt_self_component_sink_as_self_component(comp), pretty);
2b4c4a7c
JD
672 init_stream_packet_context_quarks();
673
bac67f0f
JG
674end:
675 return ret;
d94d92ac 676
bac67f0f 677error:
3228cc1d 678 destroy_pretty_data(pretty);
bac67f0f
JG
679 return ret;
680}
This page took 0.075585 seconds and 4 git commands to generate.