| 1 | /* |
| 2 | * pretty.c |
| 3 | * |
| 4 | * Babeltrace CTF Text Output Plugin |
| 5 | * |
| 6 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 7 | * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 10 | * |
| 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
| 17 | * |
| 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 27 | * SOFTWARE. |
| 28 | */ |
| 29 | |
| 30 | #include <babeltrace/plugin/plugin-dev.h> |
| 31 | #include <babeltrace/graph/component.h> |
| 32 | #include <babeltrace/graph/private-component.h> |
| 33 | #include <babeltrace/graph/private-component-sink.h> |
| 34 | #include <babeltrace/graph/component-sink.h> |
| 35 | #include <babeltrace/graph/port.h> |
| 36 | #include <babeltrace/graph/private-port.h> |
| 37 | #include <babeltrace/graph/connection.h> |
| 38 | #include <babeltrace/graph/private-connection.h> |
| 39 | #include <babeltrace/graph/notification.h> |
| 40 | #include <babeltrace/graph/notification-iterator.h> |
| 41 | #include <babeltrace/graph/notification-event.h> |
| 42 | #include <babeltrace/values.h> |
| 43 | #include <babeltrace/compiler-internal.h> |
| 44 | #include <babeltrace/common-internal.h> |
| 45 | #include <plugins-common.h> |
| 46 | #include <stdio.h> |
| 47 | #include <stdbool.h> |
| 48 | #include <glib.h> |
| 49 | #include <assert.h> |
| 50 | |
| 51 | #include "pretty.h" |
| 52 | |
| 53 | static |
| 54 | const char *plugin_options[] = { |
| 55 | "color", |
| 56 | "path", |
| 57 | "no-delta", |
| 58 | "clock-cycles", |
| 59 | "clock-seconds", |
| 60 | "clock-date", |
| 61 | "clock-gmt", |
| 62 | "verbose", |
| 63 | "name-default", /* show/hide */ |
| 64 | "name-payload", |
| 65 | "name-context", |
| 66 | "name-scope", |
| 67 | "name-header", |
| 68 | "field-default", /* show/hide */ |
| 69 | "field-trace", |
| 70 | "field-trace:hostname", |
| 71 | "field-trace:domain", |
| 72 | "field-trace:procname", |
| 73 | "field-trace:vpid", |
| 74 | "field-loglevel", |
| 75 | "field-emf", |
| 76 | "field-callsite", |
| 77 | }; |
| 78 | |
| 79 | static |
| 80 | void destroy_pretty_data(struct pretty_component *pretty) |
| 81 | { |
| 82 | bt_put(pretty->input_iterator); |
| 83 | (void) g_string_free(pretty->string, TRUE); |
| 84 | if (pretty->out != stdout) { |
| 85 | int ret; |
| 86 | |
| 87 | ret = fclose(pretty->out); |
| 88 | if (ret) { |
| 89 | perror("close output file"); |
| 90 | } |
| 91 | } |
| 92 | g_free(pretty->options.output_path); |
| 93 | g_free(pretty); |
| 94 | } |
| 95 | |
| 96 | static |
| 97 | struct pretty_component *create_pretty(void) |
| 98 | { |
| 99 | struct pretty_component *pretty; |
| 100 | |
| 101 | pretty = g_new0(struct pretty_component, 1); |
| 102 | if (!pretty) { |
| 103 | goto end; |
| 104 | } |
| 105 | pretty->string = g_string_new(""); |
| 106 | if (!pretty->string) { |
| 107 | goto error; |
| 108 | } |
| 109 | end: |
| 110 | return pretty; |
| 111 | |
| 112 | error: |
| 113 | g_free(pretty); |
| 114 | return NULL; |
| 115 | } |
| 116 | |
| 117 | BT_HIDDEN |
| 118 | void pretty_finalize(struct bt_private_component *component) |
| 119 | { |
| 120 | void *data = bt_private_component_get_user_data(component); |
| 121 | |
| 122 | destroy_pretty_data(data); |
| 123 | } |
| 124 | |
| 125 | static |
| 126 | enum bt_component_status handle_notification(struct pretty_component *pretty, |
| 127 | struct bt_notification *notification) |
| 128 | { |
| 129 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 130 | |
| 131 | assert(pretty); |
| 132 | |
| 133 | if (bt_notification_get_type(notification) == BT_NOTIFICATION_TYPE_EVENT) { |
| 134 | ret = pretty_print_event(pretty, notification); |
| 135 | } |
| 136 | |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | BT_HIDDEN |
| 141 | void pretty_port_connected( |
| 142 | struct bt_private_component *component, |
| 143 | struct bt_private_port *self_port, |
| 144 | struct bt_port *other_port) |
| 145 | { |
| 146 | struct bt_private_connection *connection; |
| 147 | struct pretty_component *pretty; |
| 148 | static const enum bt_notification_type notif_types[] = { |
| 149 | BT_NOTIFICATION_TYPE_EVENT, |
| 150 | BT_NOTIFICATION_TYPE_SENTINEL, |
| 151 | }; |
| 152 | |
| 153 | pretty = bt_private_component_get_user_data(component); |
| 154 | assert(pretty); |
| 155 | assert(!pretty->input_iterator); |
| 156 | connection = bt_private_port_get_private_connection(self_port); |
| 157 | assert(connection); |
| 158 | pretty->input_iterator = |
| 159 | bt_private_connection_create_notification_iterator(connection, |
| 160 | notif_types); |
| 161 | |
| 162 | if (!pretty->input_iterator) { |
| 163 | pretty->error = true; |
| 164 | } |
| 165 | |
| 166 | bt_put(connection); |
| 167 | } |
| 168 | |
| 169 | BT_HIDDEN |
| 170 | enum bt_component_status pretty_consume(struct bt_private_component *component) |
| 171 | { |
| 172 | enum bt_component_status ret; |
| 173 | struct bt_notification *notification = NULL; |
| 174 | struct bt_notification_iterator *it; |
| 175 | struct pretty_component *pretty = |
| 176 | bt_private_component_get_user_data(component); |
| 177 | enum bt_notification_iterator_status it_ret; |
| 178 | |
| 179 | if (unlikely(pretty->error)) { |
| 180 | ret = BT_COMPONENT_STATUS_ERROR; |
| 181 | goto end; |
| 182 | } |
| 183 | |
| 184 | it = pretty->input_iterator; |
| 185 | it_ret = bt_notification_iterator_next(it); |
| 186 | |
| 187 | switch (it_ret) { |
| 188 | case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: |
| 189 | ret = BT_COMPONENT_STATUS_ERROR; |
| 190 | goto end; |
| 191 | case BT_NOTIFICATION_ITERATOR_STATUS_END: |
| 192 | ret = BT_COMPONENT_STATUS_END; |
| 193 | BT_PUT(pretty->input_iterator); |
| 194 | goto end; |
| 195 | case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: |
| 196 | ret = BT_COMPONENT_STATUS_AGAIN; |
| 197 | goto end; |
| 198 | case BT_NOTIFICATION_ITERATOR_STATUS_OK: |
| 199 | break; |
| 200 | default: |
| 201 | ret = BT_COMPONENT_STATUS_ERROR; |
| 202 | goto end; |
| 203 | } |
| 204 | |
| 205 | notification = bt_notification_iterator_get_notification(it); |
| 206 | assert(notification); |
| 207 | ret = handle_notification(pretty, notification); |
| 208 | |
| 209 | end: |
| 210 | bt_put(notification); |
| 211 | return ret; |
| 212 | } |
| 213 | |
| 214 | static |
| 215 | enum bt_component_status add_params_to_map(struct bt_value *plugin_opt_map) |
| 216 | { |
| 217 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 218 | unsigned int i; |
| 219 | |
| 220 | for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) { |
| 221 | const char *key = plugin_options[i]; |
| 222 | enum bt_value_status status; |
| 223 | |
| 224 | status = bt_value_map_insert(plugin_opt_map, key, bt_value_null); |
| 225 | switch (status) { |
| 226 | case BT_VALUE_STATUS_OK: |
| 227 | break; |
| 228 | default: |
| 229 | ret = BT_COMPONENT_STATUS_ERROR; |
| 230 | goto end; |
| 231 | } |
| 232 | } |
| 233 | end: |
| 234 | return ret; |
| 235 | } |
| 236 | |
| 237 | static |
| 238 | bool check_param_exists(const char *key, struct bt_value *object, void *data) |
| 239 | { |
| 240 | struct pretty_component *pretty = data; |
| 241 | struct bt_value *plugin_opt_map = pretty->plugin_opt_map; |
| 242 | |
| 243 | if (!bt_value_map_get(plugin_opt_map, key)) { |
| 244 | fprintf(pretty->err, |
| 245 | "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); |
| 246 | } |
| 247 | return true; |
| 248 | } |
| 249 | |
| 250 | static |
| 251 | enum bt_component_status apply_one_string(const char *key, |
| 252 | struct bt_value *params, |
| 253 | char **option) |
| 254 | { |
| 255 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 256 | struct bt_value *value = NULL; |
| 257 | enum bt_value_status status; |
| 258 | const char *str; |
| 259 | |
| 260 | value = bt_value_map_get(params, key); |
| 261 | if (!value) { |
| 262 | goto end; |
| 263 | } |
| 264 | if (bt_value_is_null(value)) { |
| 265 | goto end; |
| 266 | } |
| 267 | status = bt_value_string_get(value, &str); |
| 268 | switch (status) { |
| 269 | case BT_VALUE_STATUS_OK: |
| 270 | break; |
| 271 | default: |
| 272 | ret = BT_COMPONENT_STATUS_ERROR; |
| 273 | goto end; |
| 274 | } |
| 275 | *option = g_strdup(str); |
| 276 | end: |
| 277 | bt_put(value); |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | static |
| 282 | enum bt_component_status apply_one_bool(const char *key, |
| 283 | struct bt_value *params, |
| 284 | bool *option, |
| 285 | bool *found) |
| 286 | { |
| 287 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 288 | struct bt_value *value = NULL; |
| 289 | enum bt_value_status status; |
| 290 | |
| 291 | value = bt_value_map_get(params, key); |
| 292 | if (!value) { |
| 293 | goto end; |
| 294 | } |
| 295 | status = bt_value_bool_get(value, option); |
| 296 | switch (status) { |
| 297 | case BT_VALUE_STATUS_OK: |
| 298 | break; |
| 299 | default: |
| 300 | ret = BT_COMPONENT_STATUS_ERROR; |
| 301 | goto end; |
| 302 | } |
| 303 | if (found) { |
| 304 | *found = true; |
| 305 | } |
| 306 | end: |
| 307 | bt_put(value); |
| 308 | return ret; |
| 309 | } |
| 310 | |
| 311 | static |
| 312 | void warn_wrong_color_param(struct pretty_component *pretty) |
| 313 | { |
| 314 | fprintf(pretty->err, |
| 315 | "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n"); |
| 316 | } |
| 317 | |
| 318 | static |
| 319 | enum bt_component_status open_output_file(struct pretty_component *pretty) |
| 320 | { |
| 321 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 322 | |
| 323 | if (!pretty->options.output_path) { |
| 324 | goto end; |
| 325 | } |
| 326 | |
| 327 | pretty->out = fopen(pretty->options.output_path, "w"); |
| 328 | if (!pretty->out) { |
| 329 | goto error; |
| 330 | } |
| 331 | |
| 332 | goto end; |
| 333 | |
| 334 | error: |
| 335 | ret = BT_COMPONENT_STATUS_ERROR; |
| 336 | end: |
| 337 | return ret; |
| 338 | } |
| 339 | |
| 340 | static |
| 341 | enum bt_component_status apply_params(struct pretty_component *pretty, |
| 342 | struct bt_value *params) |
| 343 | { |
| 344 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 345 | enum bt_value_status status; |
| 346 | bool value, found; |
| 347 | char *str = NULL; |
| 348 | |
| 349 | pretty->plugin_opt_map = bt_value_map_create(); |
| 350 | if (!pretty->plugin_opt_map) { |
| 351 | ret = BT_COMPONENT_STATUS_ERROR; |
| 352 | goto end; |
| 353 | } |
| 354 | ret = add_params_to_map(pretty->plugin_opt_map); |
| 355 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 356 | goto end; |
| 357 | } |
| 358 | /* Report unknown parameters. */ |
| 359 | status = bt_value_map_foreach(params, check_param_exists, pretty); |
| 360 | switch (status) { |
| 361 | case BT_VALUE_STATUS_OK: |
| 362 | break; |
| 363 | default: |
| 364 | ret = BT_COMPONENT_STATUS_ERROR; |
| 365 | goto end; |
| 366 | } |
| 367 | /* Known parameters. */ |
| 368 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
| 369 | if (bt_value_map_has_key(params, "color")) { |
| 370 | struct bt_value *color_value; |
| 371 | const char *color; |
| 372 | |
| 373 | color_value = bt_value_map_get(params, "color"); |
| 374 | if (!color_value) { |
| 375 | goto end; |
| 376 | } |
| 377 | |
| 378 | status = bt_value_string_get(color_value, &color); |
| 379 | if (status) { |
| 380 | warn_wrong_color_param(pretty); |
| 381 | } else { |
| 382 | if (strcmp(color, "never") == 0) { |
| 383 | pretty->options.color = PRETTY_COLOR_OPT_NEVER; |
| 384 | } else if (strcmp(color, "auto") == 0) { |
| 385 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
| 386 | } else if (strcmp(color, "always") == 0) { |
| 387 | pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; |
| 388 | } else { |
| 389 | warn_wrong_color_param(pretty); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | bt_put(color_value); |
| 394 | } |
| 395 | |
| 396 | ret = apply_one_string("path", params, &pretty->options.output_path); |
| 397 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 398 | goto end; |
| 399 | } |
| 400 | ret = open_output_file(pretty); |
| 401 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 402 | goto end; |
| 403 | } |
| 404 | |
| 405 | value = false; /* Default. */ |
| 406 | ret = apply_one_bool("no-delta", params, &value, NULL); |
| 407 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 408 | goto end; |
| 409 | } |
| 410 | pretty->options.print_delta_field = !value; /* Reverse logic. */ |
| 411 | |
| 412 | value = false; /* Default. */ |
| 413 | ret = apply_one_bool("clock-cycles", params, &value, NULL); |
| 414 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 415 | goto end; |
| 416 | } |
| 417 | pretty->options.print_timestamp_cycles = value; |
| 418 | |
| 419 | value = false; /* Default. */ |
| 420 | ret = apply_one_bool("clock-seconds", params, &value, NULL); |
| 421 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 422 | goto end; |
| 423 | } |
| 424 | pretty->options.clock_seconds = value; |
| 425 | |
| 426 | value = false; /* Default. */ |
| 427 | ret = apply_one_bool("clock-date", params, &value, NULL); |
| 428 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 429 | goto end; |
| 430 | } |
| 431 | pretty->options.clock_date = value; |
| 432 | |
| 433 | value = false; /* Default. */ |
| 434 | ret = apply_one_bool("clock-gmt", params, &value, NULL); |
| 435 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 436 | goto end; |
| 437 | } |
| 438 | pretty->options.clock_gmt = value; |
| 439 | |
| 440 | value = false; /* Default. */ |
| 441 | ret = apply_one_bool("verbose", params, &value, NULL); |
| 442 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 443 | goto end; |
| 444 | } |
| 445 | pretty->options.verbose = value; |
| 446 | |
| 447 | /* Names. */ |
| 448 | ret = apply_one_string("name-default", params, &str); |
| 449 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 450 | goto end; |
| 451 | } |
| 452 | if (!str) { |
| 453 | pretty->options.name_default = PRETTY_DEFAULT_UNSET; |
| 454 | } else if (!strcmp(str, "show")) { |
| 455 | pretty->options.name_default = PRETTY_DEFAULT_SHOW; |
| 456 | } else if (!strcmp(str, "hide")) { |
| 457 | pretty->options.name_default = PRETTY_DEFAULT_HIDE; |
| 458 | } else { |
| 459 | ret = BT_COMPONENT_STATUS_ERROR; |
| 460 | goto end; |
| 461 | } |
| 462 | g_free(str); |
| 463 | str = NULL; |
| 464 | |
| 465 | switch (pretty->options.name_default) { |
| 466 | case PRETTY_DEFAULT_UNSET: |
| 467 | pretty->options.print_payload_field_names = true; |
| 468 | pretty->options.print_context_field_names = true; |
| 469 | pretty->options.print_header_field_names = false; |
| 470 | pretty->options.print_scope_field_names = false; |
| 471 | break; |
| 472 | case PRETTY_DEFAULT_SHOW: |
| 473 | pretty->options.print_payload_field_names = true; |
| 474 | pretty->options.print_context_field_names = true; |
| 475 | pretty->options.print_header_field_names = true; |
| 476 | pretty->options.print_scope_field_names = true; |
| 477 | break; |
| 478 | case PRETTY_DEFAULT_HIDE: |
| 479 | pretty->options.print_payload_field_names = false; |
| 480 | pretty->options.print_context_field_names = false; |
| 481 | pretty->options.print_header_field_names = false; |
| 482 | pretty->options.print_scope_field_names = false; |
| 483 | break; |
| 484 | default: |
| 485 | ret = BT_COMPONENT_STATUS_ERROR; |
| 486 | goto end; |
| 487 | } |
| 488 | |
| 489 | value = false; |
| 490 | found = false; |
| 491 | ret = apply_one_bool("name-payload", params, &value, &found); |
| 492 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 493 | goto end; |
| 494 | } |
| 495 | if (found) { |
| 496 | pretty->options.print_payload_field_names = value; |
| 497 | } |
| 498 | |
| 499 | value = false; |
| 500 | found = false; |
| 501 | ret = apply_one_bool("name-context", params, &value, &found); |
| 502 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 503 | goto end; |
| 504 | } |
| 505 | if (found) { |
| 506 | pretty->options.print_context_field_names = value; |
| 507 | } |
| 508 | |
| 509 | value = false; |
| 510 | found = false; |
| 511 | ret = apply_one_bool("name-header", params, &value, &found); |
| 512 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 513 | goto end; |
| 514 | } |
| 515 | if (found) { |
| 516 | pretty->options.print_header_field_names = value; |
| 517 | } |
| 518 | |
| 519 | value = false; |
| 520 | found = false; |
| 521 | ret = apply_one_bool("name-scope", params, &value, &found); |
| 522 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 523 | goto end; |
| 524 | } |
| 525 | if (found) { |
| 526 | pretty->options.print_scope_field_names = value; |
| 527 | } |
| 528 | |
| 529 | /* Fields. */ |
| 530 | ret = apply_one_string("field-default", params, &str); |
| 531 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 532 | goto end; |
| 533 | } |
| 534 | if (!str) { |
| 535 | pretty->options.field_default = PRETTY_DEFAULT_UNSET; |
| 536 | } else if (!strcmp(str, "show")) { |
| 537 | pretty->options.field_default = PRETTY_DEFAULT_SHOW; |
| 538 | } else if (!strcmp(str, "hide")) { |
| 539 | pretty->options.field_default = PRETTY_DEFAULT_HIDE; |
| 540 | } else { |
| 541 | ret = BT_COMPONENT_STATUS_ERROR; |
| 542 | goto end; |
| 543 | } |
| 544 | g_free(str); |
| 545 | str = NULL; |
| 546 | |
| 547 | switch (pretty->options.field_default) { |
| 548 | case PRETTY_DEFAULT_UNSET: |
| 549 | pretty->options.print_trace_field = false; |
| 550 | pretty->options.print_trace_hostname_field = true; |
| 551 | pretty->options.print_trace_domain_field = false; |
| 552 | pretty->options.print_trace_procname_field = true; |
| 553 | pretty->options.print_trace_vpid_field = true; |
| 554 | pretty->options.print_loglevel_field = false; |
| 555 | pretty->options.print_emf_field = false; |
| 556 | pretty->options.print_callsite_field = false; |
| 557 | break; |
| 558 | case PRETTY_DEFAULT_SHOW: |
| 559 | pretty->options.print_trace_field = true; |
| 560 | pretty->options.print_trace_hostname_field = true; |
| 561 | pretty->options.print_trace_domain_field = true; |
| 562 | pretty->options.print_trace_procname_field = true; |
| 563 | pretty->options.print_trace_vpid_field = true; |
| 564 | pretty->options.print_loglevel_field = true; |
| 565 | pretty->options.print_emf_field = true; |
| 566 | pretty->options.print_callsite_field = true; |
| 567 | break; |
| 568 | case PRETTY_DEFAULT_HIDE: |
| 569 | pretty->options.print_trace_field = false; |
| 570 | pretty->options.print_trace_hostname_field = false; |
| 571 | pretty->options.print_trace_domain_field = false; |
| 572 | pretty->options.print_trace_procname_field = false; |
| 573 | pretty->options.print_trace_vpid_field = false; |
| 574 | pretty->options.print_loglevel_field = false; |
| 575 | pretty->options.print_emf_field = false; |
| 576 | pretty->options.print_callsite_field = false; |
| 577 | break; |
| 578 | default: |
| 579 | ret = BT_COMPONENT_STATUS_ERROR; |
| 580 | goto end; |
| 581 | } |
| 582 | |
| 583 | value = false; |
| 584 | found = false; |
| 585 | ret = apply_one_bool("field-trace", params, &value, &found); |
| 586 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 587 | goto end; |
| 588 | } |
| 589 | if (found) { |
| 590 | pretty->options.print_trace_field = value; |
| 591 | } |
| 592 | |
| 593 | value = false; |
| 594 | found = false; |
| 595 | ret = apply_one_bool("field-trace:hostname", params, &value, &found); |
| 596 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 597 | goto end; |
| 598 | } |
| 599 | if (found) { |
| 600 | pretty->options.print_trace_hostname_field = value; |
| 601 | } |
| 602 | |
| 603 | value = false; |
| 604 | found = false; |
| 605 | ret = apply_one_bool("field-trace:domain", params, &value, &found); |
| 606 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 607 | goto end; |
| 608 | } |
| 609 | if (found) { |
| 610 | pretty->options.print_trace_domain_field = value; |
| 611 | } |
| 612 | |
| 613 | value = false; |
| 614 | found = false; |
| 615 | ret = apply_one_bool("field-trace:procname", params, &value, &found); |
| 616 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 617 | goto end; |
| 618 | } |
| 619 | if (found) { |
| 620 | pretty->options.print_trace_procname_field = value; |
| 621 | } |
| 622 | |
| 623 | value = false; |
| 624 | found = false; |
| 625 | ret = apply_one_bool("field-trace:vpid", params, &value, &found); |
| 626 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 627 | goto end; |
| 628 | } |
| 629 | if (found) { |
| 630 | pretty->options.print_trace_vpid_field = value; |
| 631 | } |
| 632 | |
| 633 | value = false; |
| 634 | found = false; |
| 635 | ret = apply_one_bool("field-loglevel", params, &value, &found); |
| 636 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 637 | goto end; |
| 638 | } |
| 639 | if (found) { |
| 640 | pretty->options.print_loglevel_field = value; |
| 641 | } |
| 642 | |
| 643 | value = false; |
| 644 | found = false; |
| 645 | ret = apply_one_bool("field-emf", params, &value, &found); |
| 646 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 647 | goto end; |
| 648 | } |
| 649 | if (found) { |
| 650 | pretty->options.print_emf_field = value; |
| 651 | } |
| 652 | |
| 653 | value = false; |
| 654 | found = false; |
| 655 | ret = apply_one_bool("field-callsite", params, &value, &found); |
| 656 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 657 | goto end; |
| 658 | } |
| 659 | if (found) { |
| 660 | pretty->options.print_callsite_field = value; |
| 661 | } |
| 662 | |
| 663 | end: |
| 664 | bt_put(pretty->plugin_opt_map); |
| 665 | pretty->plugin_opt_map = NULL; |
| 666 | g_free(str); |
| 667 | return ret; |
| 668 | } |
| 669 | |
| 670 | static |
| 671 | void set_use_colors(struct pretty_component *pretty) |
| 672 | { |
| 673 | switch (pretty->options.color) { |
| 674 | case PRETTY_COLOR_OPT_ALWAYS: |
| 675 | pretty->use_colors = true; |
| 676 | break; |
| 677 | case PRETTY_COLOR_OPT_AUTO: |
| 678 | pretty->use_colors = pretty->out == stdout && |
| 679 | bt_common_colors_supported(); |
| 680 | break; |
| 681 | case PRETTY_COLOR_OPT_NEVER: |
| 682 | pretty->use_colors = false; |
| 683 | break; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | static |
| 688 | void init_stream_packet_context_quarks(void) |
| 689 | { |
| 690 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = |
| 691 | g_quark_from_string("timestamp_begin"); |
| 692 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = |
| 693 | g_quark_from_string("timestamp_begin"); |
| 694 | stream_packet_context_quarks[Q_TIMESTAMP_END] = |
| 695 | g_quark_from_string("timestamp_end"); |
| 696 | stream_packet_context_quarks[Q_EVENTS_DISCARDED] = |
| 697 | g_quark_from_string("events_discarded"); |
| 698 | stream_packet_context_quarks[Q_CONTENT_SIZE] = |
| 699 | g_quark_from_string("content_size"); |
| 700 | stream_packet_context_quarks[Q_PACKET_SIZE] = |
| 701 | g_quark_from_string("packet_size"); |
| 702 | stream_packet_context_quarks[Q_PACKET_SEQ_NUM] = |
| 703 | g_quark_from_string("packet_seq_num"); |
| 704 | } |
| 705 | |
| 706 | BT_HIDDEN |
| 707 | enum bt_component_status pretty_init( |
| 708 | struct bt_private_component *component, |
| 709 | struct bt_value *params, |
| 710 | UNUSED_VAR void *init_method_data) |
| 711 | { |
| 712 | enum bt_component_status ret; |
| 713 | struct pretty_component *pretty = create_pretty(); |
| 714 | void *priv_port; |
| 715 | |
| 716 | if (!pretty) { |
| 717 | ret = BT_COMPONENT_STATUS_NOMEM; |
| 718 | goto end; |
| 719 | } |
| 720 | |
| 721 | priv_port = bt_private_component_sink_add_input_private_port(component, |
| 722 | "in", NULL); |
| 723 | if (!priv_port) { |
| 724 | ret = BT_COMPONENT_STATUS_NOMEM; |
| 725 | goto end; |
| 726 | } |
| 727 | |
| 728 | bt_put(priv_port); |
| 729 | |
| 730 | pretty->out = stdout; |
| 731 | pretty->err = stderr; |
| 732 | |
| 733 | pretty->delta_cycles = -1ULL; |
| 734 | pretty->last_cycles_timestamp = -1ULL; |
| 735 | |
| 736 | pretty->delta_real_timestamp = -1ULL; |
| 737 | pretty->last_real_timestamp = -1ULL; |
| 738 | |
| 739 | ret = apply_params(pretty, params); |
| 740 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 741 | goto error; |
| 742 | } |
| 743 | |
| 744 | set_use_colors(pretty); |
| 745 | ret = bt_private_component_set_user_data(component, pretty); |
| 746 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 747 | goto error; |
| 748 | } |
| 749 | |
| 750 | init_stream_packet_context_quarks(); |
| 751 | |
| 752 | end: |
| 753 | return ret; |
| 754 | error: |
| 755 | destroy_pretty_data(pretty); |
| 756 | return ret; |
| 757 | } |