| 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 | switch (bt_notification_get_type(notification)) { |
| 134 | case BT_NOTIFICATION_TYPE_EVENT: |
| 135 | ret = pretty_print_event(pretty, notification); |
| 136 | break; |
| 137 | case BT_NOTIFICATION_TYPE_INACTIVITY: |
| 138 | fprintf(stderr, "Inactivity notification\n"); |
| 139 | break; |
| 140 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: |
| 141 | case BT_NOTIFICATION_TYPE_PACKET_END: |
| 142 | case BT_NOTIFICATION_TYPE_STREAM_BEGIN: |
| 143 | case BT_NOTIFICATION_TYPE_STREAM_END: |
| 144 | break; |
| 145 | default: |
| 146 | fprintf(stderr, "Unhandled notification type\n"); |
| 147 | } |
| 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
| 152 | BT_HIDDEN |
| 153 | void pretty_port_connected( |
| 154 | struct bt_private_component *component, |
| 155 | struct bt_private_port *self_port, |
| 156 | struct bt_port *other_port) |
| 157 | { |
| 158 | struct bt_private_connection *connection; |
| 159 | struct pretty_component *pretty; |
| 160 | static const enum bt_notification_type notif_types[] = { |
| 161 | BT_NOTIFICATION_TYPE_EVENT, |
| 162 | BT_NOTIFICATION_TYPE_SENTINEL, |
| 163 | }; |
| 164 | |
| 165 | pretty = bt_private_component_get_user_data(component); |
| 166 | assert(pretty); |
| 167 | assert(!pretty->input_iterator); |
| 168 | connection = bt_private_port_get_private_connection(self_port); |
| 169 | assert(connection); |
| 170 | pretty->input_iterator = |
| 171 | bt_private_connection_create_notification_iterator(connection, |
| 172 | notif_types); |
| 173 | |
| 174 | if (!pretty->input_iterator) { |
| 175 | pretty->error = true; |
| 176 | } |
| 177 | |
| 178 | bt_put(connection); |
| 179 | } |
| 180 | |
| 181 | BT_HIDDEN |
| 182 | enum bt_component_status pretty_consume(struct bt_private_component *component) |
| 183 | { |
| 184 | enum bt_component_status ret; |
| 185 | struct bt_notification *notification = NULL; |
| 186 | struct bt_notification_iterator *it; |
| 187 | struct pretty_component *pretty = |
| 188 | bt_private_component_get_user_data(component); |
| 189 | enum bt_notification_iterator_status it_ret; |
| 190 | |
| 191 | if (unlikely(pretty->error)) { |
| 192 | ret = BT_COMPONENT_STATUS_ERROR; |
| 193 | goto end; |
| 194 | } |
| 195 | |
| 196 | it = pretty->input_iterator; |
| 197 | it_ret = bt_notification_iterator_next(it); |
| 198 | |
| 199 | switch (it_ret) { |
| 200 | case BT_NOTIFICATION_ITERATOR_STATUS_END: |
| 201 | ret = BT_COMPONENT_STATUS_END; |
| 202 | BT_PUT(pretty->input_iterator); |
| 203 | goto end; |
| 204 | case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: |
| 205 | ret = BT_COMPONENT_STATUS_AGAIN; |
| 206 | goto end; |
| 207 | case BT_NOTIFICATION_ITERATOR_STATUS_OK: |
| 208 | break; |
| 209 | default: |
| 210 | ret = BT_COMPONENT_STATUS_ERROR; |
| 211 | goto end; |
| 212 | } |
| 213 | |
| 214 | notification = bt_notification_iterator_get_notification(it); |
| 215 | assert(notification); |
| 216 | ret = handle_notification(pretty, notification); |
| 217 | |
| 218 | end: |
| 219 | bt_put(notification); |
| 220 | return ret; |
| 221 | } |
| 222 | |
| 223 | static |
| 224 | enum bt_component_status add_params_to_map(struct bt_value *plugin_opt_map) |
| 225 | { |
| 226 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 227 | unsigned int i; |
| 228 | |
| 229 | for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) { |
| 230 | const char *key = plugin_options[i]; |
| 231 | enum bt_value_status status; |
| 232 | |
| 233 | status = bt_value_map_insert(plugin_opt_map, key, bt_value_null); |
| 234 | switch (status) { |
| 235 | case BT_VALUE_STATUS_OK: |
| 236 | break; |
| 237 | default: |
| 238 | ret = BT_COMPONENT_STATUS_ERROR; |
| 239 | goto end; |
| 240 | } |
| 241 | } |
| 242 | end: |
| 243 | return ret; |
| 244 | } |
| 245 | |
| 246 | static |
| 247 | bt_bool check_param_exists(const char *key, struct bt_value *object, void *data) |
| 248 | { |
| 249 | struct pretty_component *pretty = data; |
| 250 | struct bt_value *plugin_opt_map = pretty->plugin_opt_map; |
| 251 | |
| 252 | if (!bt_value_map_get(plugin_opt_map, key)) { |
| 253 | fprintf(pretty->err, |
| 254 | "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); |
| 255 | } |
| 256 | return BT_TRUE; |
| 257 | } |
| 258 | |
| 259 | static |
| 260 | enum bt_component_status apply_one_string(const char *key, |
| 261 | struct bt_value *params, |
| 262 | char **option) |
| 263 | { |
| 264 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 265 | struct bt_value *value = NULL; |
| 266 | enum bt_value_status status; |
| 267 | const char *str; |
| 268 | |
| 269 | value = bt_value_map_get(params, key); |
| 270 | if (!value) { |
| 271 | goto end; |
| 272 | } |
| 273 | if (bt_value_is_null(value)) { |
| 274 | goto end; |
| 275 | } |
| 276 | status = bt_value_string_get(value, &str); |
| 277 | switch (status) { |
| 278 | case BT_VALUE_STATUS_OK: |
| 279 | break; |
| 280 | default: |
| 281 | ret = BT_COMPONENT_STATUS_ERROR; |
| 282 | goto end; |
| 283 | } |
| 284 | *option = g_strdup(str); |
| 285 | end: |
| 286 | bt_put(value); |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | static |
| 291 | enum bt_component_status apply_one_bool(const char *key, |
| 292 | struct bt_value *params, |
| 293 | bool *option, |
| 294 | bool *found) |
| 295 | { |
| 296 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 297 | struct bt_value *value = NULL; |
| 298 | enum bt_value_status status; |
| 299 | bt_bool bool_val; |
| 300 | |
| 301 | value = bt_value_map_get(params, key); |
| 302 | if (!value) { |
| 303 | goto end; |
| 304 | } |
| 305 | status = bt_value_bool_get(value, &bool_val); |
| 306 | switch (status) { |
| 307 | case BT_VALUE_STATUS_OK: |
| 308 | break; |
| 309 | default: |
| 310 | ret = BT_COMPONENT_STATUS_ERROR; |
| 311 | goto end; |
| 312 | } |
| 313 | *option = (bool) bool_val; |
| 314 | if (found) { |
| 315 | *found = true; |
| 316 | } |
| 317 | end: |
| 318 | bt_put(value); |
| 319 | return ret; |
| 320 | } |
| 321 | |
| 322 | static |
| 323 | void warn_wrong_color_param(struct pretty_component *pretty) |
| 324 | { |
| 325 | fprintf(pretty->err, |
| 326 | "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n"); |
| 327 | } |
| 328 | |
| 329 | static |
| 330 | enum bt_component_status open_output_file(struct pretty_component *pretty) |
| 331 | { |
| 332 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 333 | |
| 334 | if (!pretty->options.output_path) { |
| 335 | goto end; |
| 336 | } |
| 337 | |
| 338 | pretty->out = fopen(pretty->options.output_path, "w"); |
| 339 | if (!pretty->out) { |
| 340 | goto error; |
| 341 | } |
| 342 | |
| 343 | goto end; |
| 344 | |
| 345 | error: |
| 346 | ret = BT_COMPONENT_STATUS_ERROR; |
| 347 | end: |
| 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | static |
| 352 | enum bt_component_status apply_params(struct pretty_component *pretty, |
| 353 | struct bt_value *params) |
| 354 | { |
| 355 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 356 | enum bt_value_status status; |
| 357 | bool value, found; |
| 358 | char *str = NULL; |
| 359 | |
| 360 | pretty->plugin_opt_map = bt_value_map_create(); |
| 361 | if (!pretty->plugin_opt_map) { |
| 362 | ret = BT_COMPONENT_STATUS_ERROR; |
| 363 | goto end; |
| 364 | } |
| 365 | ret = add_params_to_map(pretty->plugin_opt_map); |
| 366 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 367 | goto end; |
| 368 | } |
| 369 | /* Report unknown parameters. */ |
| 370 | status = bt_value_map_foreach(params, check_param_exists, pretty); |
| 371 | switch (status) { |
| 372 | case BT_VALUE_STATUS_OK: |
| 373 | break; |
| 374 | default: |
| 375 | ret = BT_COMPONENT_STATUS_ERROR; |
| 376 | goto end; |
| 377 | } |
| 378 | /* Known parameters. */ |
| 379 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
| 380 | if (bt_value_map_has_key(params, "color")) { |
| 381 | struct bt_value *color_value; |
| 382 | const char *color; |
| 383 | |
| 384 | color_value = bt_value_map_get(params, "color"); |
| 385 | if (!color_value) { |
| 386 | goto end; |
| 387 | } |
| 388 | |
| 389 | status = bt_value_string_get(color_value, &color); |
| 390 | if (status) { |
| 391 | warn_wrong_color_param(pretty); |
| 392 | } else { |
| 393 | if (strcmp(color, "never") == 0) { |
| 394 | pretty->options.color = PRETTY_COLOR_OPT_NEVER; |
| 395 | } else if (strcmp(color, "auto") == 0) { |
| 396 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
| 397 | } else if (strcmp(color, "always") == 0) { |
| 398 | pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; |
| 399 | } else { |
| 400 | warn_wrong_color_param(pretty); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | bt_put(color_value); |
| 405 | } |
| 406 | |
| 407 | ret = apply_one_string("path", params, &pretty->options.output_path); |
| 408 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 409 | goto end; |
| 410 | } |
| 411 | ret = open_output_file(pretty); |
| 412 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 413 | goto end; |
| 414 | } |
| 415 | |
| 416 | value = false; /* Default. */ |
| 417 | ret = apply_one_bool("no-delta", params, &value, NULL); |
| 418 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 419 | goto end; |
| 420 | } |
| 421 | pretty->options.print_delta_field = !value; /* Reverse logic. */ |
| 422 | |
| 423 | value = false; /* Default. */ |
| 424 | ret = apply_one_bool("clock-cycles", params, &value, NULL); |
| 425 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 426 | goto end; |
| 427 | } |
| 428 | pretty->options.print_timestamp_cycles = value; |
| 429 | |
| 430 | value = false; /* Default. */ |
| 431 | ret = apply_one_bool("clock-seconds", params, &value, NULL); |
| 432 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 433 | goto end; |
| 434 | } |
| 435 | pretty->options.clock_seconds = value; |
| 436 | |
| 437 | value = false; /* Default. */ |
| 438 | ret = apply_one_bool("clock-date", params, &value, NULL); |
| 439 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 440 | goto end; |
| 441 | } |
| 442 | pretty->options.clock_date = value; |
| 443 | |
| 444 | value = false; /* Default. */ |
| 445 | ret = apply_one_bool("clock-gmt", params, &value, NULL); |
| 446 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 447 | goto end; |
| 448 | } |
| 449 | pretty->options.clock_gmt = value; |
| 450 | |
| 451 | value = false; /* Default. */ |
| 452 | ret = apply_one_bool("verbose", params, &value, NULL); |
| 453 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 454 | goto end; |
| 455 | } |
| 456 | pretty->options.verbose = value; |
| 457 | |
| 458 | /* Names. */ |
| 459 | ret = apply_one_string("name-default", params, &str); |
| 460 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 461 | goto end; |
| 462 | } |
| 463 | if (!str) { |
| 464 | pretty->options.name_default = PRETTY_DEFAULT_UNSET; |
| 465 | } else if (!strcmp(str, "show")) { |
| 466 | pretty->options.name_default = PRETTY_DEFAULT_SHOW; |
| 467 | } else if (!strcmp(str, "hide")) { |
| 468 | pretty->options.name_default = PRETTY_DEFAULT_HIDE; |
| 469 | } else { |
| 470 | ret = BT_COMPONENT_STATUS_ERROR; |
| 471 | goto end; |
| 472 | } |
| 473 | g_free(str); |
| 474 | str = NULL; |
| 475 | |
| 476 | switch (pretty->options.name_default) { |
| 477 | case PRETTY_DEFAULT_UNSET: |
| 478 | pretty->options.print_payload_field_names = true; |
| 479 | pretty->options.print_context_field_names = true; |
| 480 | pretty->options.print_header_field_names = false; |
| 481 | pretty->options.print_scope_field_names = false; |
| 482 | break; |
| 483 | case PRETTY_DEFAULT_SHOW: |
| 484 | pretty->options.print_payload_field_names = true; |
| 485 | pretty->options.print_context_field_names = true; |
| 486 | pretty->options.print_header_field_names = true; |
| 487 | pretty->options.print_scope_field_names = true; |
| 488 | break; |
| 489 | case PRETTY_DEFAULT_HIDE: |
| 490 | pretty->options.print_payload_field_names = false; |
| 491 | pretty->options.print_context_field_names = false; |
| 492 | pretty->options.print_header_field_names = false; |
| 493 | pretty->options.print_scope_field_names = false; |
| 494 | break; |
| 495 | default: |
| 496 | ret = BT_COMPONENT_STATUS_ERROR; |
| 497 | goto end; |
| 498 | } |
| 499 | |
| 500 | value = false; |
| 501 | found = false; |
| 502 | ret = apply_one_bool("name-payload", params, &value, &found); |
| 503 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 504 | goto end; |
| 505 | } |
| 506 | if (found) { |
| 507 | pretty->options.print_payload_field_names = value; |
| 508 | } |
| 509 | |
| 510 | value = false; |
| 511 | found = false; |
| 512 | ret = apply_one_bool("name-context", params, &value, &found); |
| 513 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 514 | goto end; |
| 515 | } |
| 516 | if (found) { |
| 517 | pretty->options.print_context_field_names = value; |
| 518 | } |
| 519 | |
| 520 | value = false; |
| 521 | found = false; |
| 522 | ret = apply_one_bool("name-header", params, &value, &found); |
| 523 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 524 | goto end; |
| 525 | } |
| 526 | if (found) { |
| 527 | pretty->options.print_header_field_names = value; |
| 528 | } |
| 529 | |
| 530 | value = false; |
| 531 | found = false; |
| 532 | ret = apply_one_bool("name-scope", params, &value, &found); |
| 533 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 534 | goto end; |
| 535 | } |
| 536 | if (found) { |
| 537 | pretty->options.print_scope_field_names = value; |
| 538 | } |
| 539 | |
| 540 | /* Fields. */ |
| 541 | ret = apply_one_string("field-default", params, &str); |
| 542 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 543 | goto end; |
| 544 | } |
| 545 | if (!str) { |
| 546 | pretty->options.field_default = PRETTY_DEFAULT_UNSET; |
| 547 | } else if (!strcmp(str, "show")) { |
| 548 | pretty->options.field_default = PRETTY_DEFAULT_SHOW; |
| 549 | } else if (!strcmp(str, "hide")) { |
| 550 | pretty->options.field_default = PRETTY_DEFAULT_HIDE; |
| 551 | } else { |
| 552 | ret = BT_COMPONENT_STATUS_ERROR; |
| 553 | goto end; |
| 554 | } |
| 555 | g_free(str); |
| 556 | str = NULL; |
| 557 | |
| 558 | switch (pretty->options.field_default) { |
| 559 | case PRETTY_DEFAULT_UNSET: |
| 560 | pretty->options.print_trace_field = false; |
| 561 | pretty->options.print_trace_hostname_field = true; |
| 562 | pretty->options.print_trace_domain_field = false; |
| 563 | pretty->options.print_trace_procname_field = true; |
| 564 | pretty->options.print_trace_vpid_field = true; |
| 565 | pretty->options.print_loglevel_field = false; |
| 566 | pretty->options.print_emf_field = false; |
| 567 | pretty->options.print_callsite_field = false; |
| 568 | break; |
| 569 | case PRETTY_DEFAULT_SHOW: |
| 570 | pretty->options.print_trace_field = true; |
| 571 | pretty->options.print_trace_hostname_field = true; |
| 572 | pretty->options.print_trace_domain_field = true; |
| 573 | pretty->options.print_trace_procname_field = true; |
| 574 | pretty->options.print_trace_vpid_field = true; |
| 575 | pretty->options.print_loglevel_field = true; |
| 576 | pretty->options.print_emf_field = true; |
| 577 | pretty->options.print_callsite_field = true; |
| 578 | break; |
| 579 | case PRETTY_DEFAULT_HIDE: |
| 580 | pretty->options.print_trace_field = false; |
| 581 | pretty->options.print_trace_hostname_field = false; |
| 582 | pretty->options.print_trace_domain_field = false; |
| 583 | pretty->options.print_trace_procname_field = false; |
| 584 | pretty->options.print_trace_vpid_field = false; |
| 585 | pretty->options.print_loglevel_field = false; |
| 586 | pretty->options.print_emf_field = false; |
| 587 | pretty->options.print_callsite_field = false; |
| 588 | break; |
| 589 | default: |
| 590 | ret = BT_COMPONENT_STATUS_ERROR; |
| 591 | goto end; |
| 592 | } |
| 593 | |
| 594 | value = false; |
| 595 | found = false; |
| 596 | ret = apply_one_bool("field-trace", params, &value, &found); |
| 597 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 598 | goto end; |
| 599 | } |
| 600 | if (found) { |
| 601 | pretty->options.print_trace_field = value; |
| 602 | } |
| 603 | |
| 604 | value = false; |
| 605 | found = false; |
| 606 | ret = apply_one_bool("field-trace:hostname", params, &value, &found); |
| 607 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 608 | goto end; |
| 609 | } |
| 610 | if (found) { |
| 611 | pretty->options.print_trace_hostname_field = value; |
| 612 | } |
| 613 | |
| 614 | value = false; |
| 615 | found = false; |
| 616 | ret = apply_one_bool("field-trace:domain", params, &value, &found); |
| 617 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 618 | goto end; |
| 619 | } |
| 620 | if (found) { |
| 621 | pretty->options.print_trace_domain_field = value; |
| 622 | } |
| 623 | |
| 624 | value = false; |
| 625 | found = false; |
| 626 | ret = apply_one_bool("field-trace:procname", params, &value, &found); |
| 627 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 628 | goto end; |
| 629 | } |
| 630 | if (found) { |
| 631 | pretty->options.print_trace_procname_field = value; |
| 632 | } |
| 633 | |
| 634 | value = false; |
| 635 | found = false; |
| 636 | ret = apply_one_bool("field-trace:vpid", params, &value, &found); |
| 637 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 638 | goto end; |
| 639 | } |
| 640 | if (found) { |
| 641 | pretty->options.print_trace_vpid_field = value; |
| 642 | } |
| 643 | |
| 644 | value = false; |
| 645 | found = false; |
| 646 | ret = apply_one_bool("field-loglevel", params, &value, &found); |
| 647 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 648 | goto end; |
| 649 | } |
| 650 | if (found) { |
| 651 | pretty->options.print_loglevel_field = value; |
| 652 | } |
| 653 | |
| 654 | value = false; |
| 655 | found = false; |
| 656 | ret = apply_one_bool("field-emf", params, &value, &found); |
| 657 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 658 | goto end; |
| 659 | } |
| 660 | if (found) { |
| 661 | pretty->options.print_emf_field = value; |
| 662 | } |
| 663 | |
| 664 | value = false; |
| 665 | found = false; |
| 666 | ret = apply_one_bool("field-callsite", params, &value, &found); |
| 667 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 668 | goto end; |
| 669 | } |
| 670 | if (found) { |
| 671 | pretty->options.print_callsite_field = value; |
| 672 | } |
| 673 | |
| 674 | end: |
| 675 | bt_put(pretty->plugin_opt_map); |
| 676 | pretty->plugin_opt_map = NULL; |
| 677 | g_free(str); |
| 678 | return ret; |
| 679 | } |
| 680 | |
| 681 | static |
| 682 | void set_use_colors(struct pretty_component *pretty) |
| 683 | { |
| 684 | switch (pretty->options.color) { |
| 685 | case PRETTY_COLOR_OPT_ALWAYS: |
| 686 | pretty->use_colors = true; |
| 687 | break; |
| 688 | case PRETTY_COLOR_OPT_AUTO: |
| 689 | pretty->use_colors = pretty->out == stdout && |
| 690 | bt_common_colors_supported(); |
| 691 | break; |
| 692 | case PRETTY_COLOR_OPT_NEVER: |
| 693 | pretty->use_colors = false; |
| 694 | break; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | static |
| 699 | void init_stream_packet_context_quarks(void) |
| 700 | { |
| 701 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = |
| 702 | g_quark_from_string("timestamp_begin"); |
| 703 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = |
| 704 | g_quark_from_string("timestamp_begin"); |
| 705 | stream_packet_context_quarks[Q_TIMESTAMP_END] = |
| 706 | g_quark_from_string("timestamp_end"); |
| 707 | stream_packet_context_quarks[Q_EVENTS_DISCARDED] = |
| 708 | g_quark_from_string("events_discarded"); |
| 709 | stream_packet_context_quarks[Q_CONTENT_SIZE] = |
| 710 | g_quark_from_string("content_size"); |
| 711 | stream_packet_context_quarks[Q_PACKET_SIZE] = |
| 712 | g_quark_from_string("packet_size"); |
| 713 | stream_packet_context_quarks[Q_PACKET_SEQ_NUM] = |
| 714 | g_quark_from_string("packet_seq_num"); |
| 715 | } |
| 716 | |
| 717 | BT_HIDDEN |
| 718 | enum bt_component_status pretty_init( |
| 719 | struct bt_private_component *component, |
| 720 | struct bt_value *params, |
| 721 | UNUSED_VAR void *init_method_data) |
| 722 | { |
| 723 | enum bt_component_status ret; |
| 724 | struct pretty_component *pretty = create_pretty(); |
| 725 | void *priv_port; |
| 726 | |
| 727 | if (!pretty) { |
| 728 | ret = BT_COMPONENT_STATUS_NOMEM; |
| 729 | goto end; |
| 730 | } |
| 731 | |
| 732 | priv_port = bt_private_component_sink_add_input_private_port(component, |
| 733 | "in", NULL); |
| 734 | if (!priv_port) { |
| 735 | ret = BT_COMPONENT_STATUS_NOMEM; |
| 736 | goto end; |
| 737 | } |
| 738 | |
| 739 | bt_put(priv_port); |
| 740 | |
| 741 | pretty->out = stdout; |
| 742 | pretty->err = stderr; |
| 743 | |
| 744 | pretty->delta_cycles = -1ULL; |
| 745 | pretty->last_cycles_timestamp = -1ULL; |
| 746 | |
| 747 | pretty->delta_real_timestamp = -1ULL; |
| 748 | pretty->last_real_timestamp = -1ULL; |
| 749 | |
| 750 | ret = apply_params(pretty, params); |
| 751 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 752 | goto error; |
| 753 | } |
| 754 | |
| 755 | set_use_colors(pretty); |
| 756 | ret = bt_private_component_set_user_data(component, pretty); |
| 757 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 758 | goto error; |
| 759 | } |
| 760 | |
| 761 | init_stream_packet_context_quarks(); |
| 762 | |
| 763 | end: |
| 764 | return ret; |
| 765 | error: |
| 766 | destroy_pretty_data(pretty); |
| 767 | return ret; |
| 768 | } |