| 1 | /* |
| 2 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 3 | * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 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 | |
| 26 | #define BT_COMP_LOG_SELF_COMP self_comp |
| 27 | #define BT_LOG_OUTPUT_LEVEL log_level |
| 28 | #define BT_LOG_TAG "PLUGIN/SINK.TEXT.PRETTY" |
| 29 | #include "logging/comp-logging.h" |
| 30 | |
| 31 | #include <babeltrace2/babeltrace.h> |
| 32 | #include "compat/compiler.h" |
| 33 | #include "common/common.h" |
| 34 | #include <stdio.h> |
| 35 | #include <stdbool.h> |
| 36 | #include <glib.h> |
| 37 | #include <string.h> |
| 38 | #include "common/assert.h" |
| 39 | #include "plugins/common/param-validation/param-validation.h" |
| 40 | |
| 41 | #include "pretty.h" |
| 42 | |
| 43 | static |
| 44 | const char * const in_port_name = "in"; |
| 45 | |
| 46 | static |
| 47 | void destroy_pretty_data(struct pretty_component *pretty) |
| 48 | { |
| 49 | if (!pretty) { |
| 50 | goto end; |
| 51 | } |
| 52 | |
| 53 | bt_self_component_port_input_message_iterator_put_ref(pretty->iterator); |
| 54 | |
| 55 | if (pretty->string) { |
| 56 | (void) g_string_free(pretty->string, TRUE); |
| 57 | } |
| 58 | |
| 59 | if (pretty->tmp_string) { |
| 60 | (void) g_string_free(pretty->tmp_string, TRUE); |
| 61 | } |
| 62 | |
| 63 | if (pretty->out != stdout) { |
| 64 | int ret; |
| 65 | |
| 66 | ret = fclose(pretty->out); |
| 67 | if (ret) { |
| 68 | perror("close output file"); |
| 69 | } |
| 70 | } |
| 71 | g_free(pretty->options.output_path); |
| 72 | g_free(pretty); |
| 73 | |
| 74 | end: |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | static |
| 79 | struct pretty_component *create_pretty(void) |
| 80 | { |
| 81 | struct pretty_component *pretty; |
| 82 | |
| 83 | pretty = g_new0(struct pretty_component, 1); |
| 84 | if (!pretty) { |
| 85 | goto end; |
| 86 | } |
| 87 | pretty->string = g_string_new(""); |
| 88 | if (!pretty->string) { |
| 89 | goto error; |
| 90 | } |
| 91 | pretty->tmp_string = g_string_new(""); |
| 92 | if (!pretty->tmp_string) { |
| 93 | goto error; |
| 94 | } |
| 95 | end: |
| 96 | return pretty; |
| 97 | |
| 98 | error: |
| 99 | g_free(pretty); |
| 100 | return NULL; |
| 101 | } |
| 102 | |
| 103 | BT_HIDDEN |
| 104 | void pretty_finalize(bt_self_component_sink *comp) |
| 105 | { |
| 106 | destroy_pretty_data( |
| 107 | bt_self_component_get_data( |
| 108 | bt_self_component_sink_as_self_component(comp))); |
| 109 | } |
| 110 | |
| 111 | static |
| 112 | bt_component_class_message_iterator_next_method_status handle_message( |
| 113 | struct pretty_component *pretty, |
| 114 | const bt_message *message) |
| 115 | { |
| 116 | bt_component_class_message_iterator_next_method_status ret = |
| 117 | BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK; |
| 118 | |
| 119 | BT_ASSERT_DBG(pretty); |
| 120 | |
| 121 | switch (bt_message_get_type(message)) { |
| 122 | case BT_MESSAGE_TYPE_EVENT: |
| 123 | if (pretty_print_event(pretty, message)) { |
| 124 | ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR; |
| 125 | } |
| 126 | break; |
| 127 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: |
| 128 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: |
| 129 | if (pretty_print_discarded_items(pretty, message)) { |
| 130 | ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR; |
| 131 | } |
| 132 | break; |
| 133 | default: |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | BT_HIDDEN |
| 141 | bt_component_class_sink_graph_is_configured_method_status |
| 142 | pretty_graph_is_configured(bt_self_component_sink *comp) |
| 143 | { |
| 144 | bt_component_class_sink_graph_is_configured_method_status status; |
| 145 | bt_self_component_port_input_message_iterator_create_from_sink_component_status |
| 146 | msg_iter_status; |
| 147 | struct pretty_component *pretty; |
| 148 | |
| 149 | pretty = bt_self_component_get_data( |
| 150 | bt_self_component_sink_as_self_component(comp)); |
| 151 | BT_ASSERT(pretty); |
| 152 | BT_ASSERT(!pretty->iterator); |
| 153 | msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component( |
| 154 | comp, bt_self_component_sink_borrow_input_port_by_name(comp, |
| 155 | in_port_name), &pretty->iterator); |
| 156 | if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) { |
| 157 | status = (int) msg_iter_status; |
| 158 | goto end; |
| 159 | } |
| 160 | |
| 161 | status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; |
| 162 | |
| 163 | end: |
| 164 | return status; |
| 165 | } |
| 166 | |
| 167 | BT_HIDDEN |
| 168 | bt_component_class_sink_consume_method_status pretty_consume( |
| 169 | bt_self_component_sink *comp) |
| 170 | { |
| 171 | bt_component_class_sink_consume_method_status ret = |
| 172 | BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; |
| 173 | bt_message_array_const msgs; |
| 174 | bt_self_component_port_input_message_iterator *it; |
| 175 | struct pretty_component *pretty = bt_self_component_get_data( |
| 176 | bt_self_component_sink_as_self_component(comp)); |
| 177 | bt_message_iterator_next_status next_status; |
| 178 | uint64_t count = 0; |
| 179 | uint64_t i = 0; |
| 180 | |
| 181 | it = pretty->iterator; |
| 182 | next_status = bt_self_component_port_input_message_iterator_next(it, |
| 183 | &msgs, &count); |
| 184 | |
| 185 | switch (next_status) { |
| 186 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: |
| 187 | break; |
| 188 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: |
| 189 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: |
| 190 | ret = (int) next_status; |
| 191 | goto end; |
| 192 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: |
| 193 | ret = (int) next_status; |
| 194 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET( |
| 195 | pretty->iterator); |
| 196 | goto end; |
| 197 | default: |
| 198 | ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; |
| 199 | goto end; |
| 200 | } |
| 201 | |
| 202 | BT_ASSERT_DBG(next_status == BT_MESSAGE_ITERATOR_NEXT_STATUS_OK); |
| 203 | |
| 204 | for (i = 0; i < count; i++) { |
| 205 | ret = (int) handle_message(pretty, msgs[i]); |
| 206 | if (ret) { |
| 207 | goto end; |
| 208 | } |
| 209 | |
| 210 | bt_message_put_ref(msgs[i]); |
| 211 | } |
| 212 | |
| 213 | end: |
| 214 | for (; i < count; i++) { |
| 215 | bt_message_put_ref(msgs[i]); |
| 216 | } |
| 217 | |
| 218 | return ret; |
| 219 | } |
| 220 | |
| 221 | static |
| 222 | void apply_one_string(const char *key, const bt_value *params, char **option) |
| 223 | { |
| 224 | const bt_value *value = NULL; |
| 225 | const char *str; |
| 226 | |
| 227 | value = bt_value_map_borrow_entry_value_const(params, key); |
| 228 | if (!value) { |
| 229 | goto end; |
| 230 | } |
| 231 | |
| 232 | str = bt_value_string_get(value); |
| 233 | *option = g_strdup(str); |
| 234 | |
| 235 | end: |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * Apply parameter with key `key` to `option`. Use `def` as the value, if |
| 241 | * the parameter is not specified. |
| 242 | */ |
| 243 | |
| 244 | static |
| 245 | void apply_one_bool_with_default(const char *key, const bt_value *params, |
| 246 | bool *option, bool def) |
| 247 | { |
| 248 | const bt_value *value; |
| 249 | |
| 250 | value = bt_value_map_borrow_entry_value_const(params, key); |
| 251 | if (value) { |
| 252 | bt_bool bool_val = bt_value_bool_get(value); |
| 253 | |
| 254 | *option = (bool) bool_val; |
| 255 | } else { |
| 256 | *option = def; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | static |
| 261 | void apply_one_bool_if_specified(const char *key, const bt_value *params, bool *option) |
| 262 | { |
| 263 | const bt_value *value; |
| 264 | |
| 265 | value = bt_value_map_borrow_entry_value_const(params, key); |
| 266 | if (value) { |
| 267 | bt_bool bool_val = bt_value_bool_get(value); |
| 268 | |
| 269 | *option = (bool) bool_val; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | static |
| 274 | int open_output_file(struct pretty_component *pretty) |
| 275 | { |
| 276 | int ret = 0; |
| 277 | |
| 278 | if (!pretty->options.output_path) { |
| 279 | goto end; |
| 280 | } |
| 281 | |
| 282 | pretty->out = fopen(pretty->options.output_path, "w"); |
| 283 | if (!pretty->out) { |
| 284 | goto error; |
| 285 | } |
| 286 | |
| 287 | goto end; |
| 288 | |
| 289 | error: |
| 290 | ret = -1; |
| 291 | |
| 292 | end: |
| 293 | return ret; |
| 294 | } |
| 295 | |
| 296 | static const char *color_choices[] = { "never", "auto", "always", NULL }; |
| 297 | static const char *show_hide_choices[] = { "show", "hide", NULL }; |
| 298 | |
| 299 | static |
| 300 | struct bt_param_validation_map_value_entry_descr pretty_params[] = { |
| 301 | { "color", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { BT_VALUE_TYPE_STRING, .string = { |
| 302 | .choices = color_choices, |
| 303 | } } }, |
| 304 | { "path", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } }, |
| 305 | { "no-delta", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 306 | { "clock-cycles", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 307 | { "clock-seconds", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 308 | { "clock-date", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 309 | { "clock-gmt", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 310 | { "verbose", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 311 | |
| 312 | { "name-default", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { BT_VALUE_TYPE_STRING, .string = { |
| 313 | .choices = show_hide_choices, |
| 314 | } } }, |
| 315 | { "name-payload", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 316 | { "name-context", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 317 | { "name-scope", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 318 | { "name-header", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 319 | |
| 320 | { "field-default", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { BT_VALUE_TYPE_STRING, .string = { |
| 321 | .choices = show_hide_choices, |
| 322 | } } }, |
| 323 | { "field-trace", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 324 | { "field-trace:hostname", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 325 | { "field-trace:domain", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 326 | { "field-trace:procname", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 327 | { "field-trace:vpid", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 328 | { "field-loglevel", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 329 | { "field-emf", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 330 | { "field-callsite", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, |
| 331 | BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END |
| 332 | }; |
| 333 | |
| 334 | static |
| 335 | bt_component_class_initialize_method_status apply_params( |
| 336 | struct pretty_component *pretty, const bt_value *params, |
| 337 | bt_self_component *self_comp, bt_logging_level log_level) |
| 338 | { |
| 339 | int ret; |
| 340 | const bt_value *value; |
| 341 | bt_component_class_initialize_method_status status; |
| 342 | enum bt_param_validation_status validation_status; |
| 343 | gchar *validate_error = NULL; |
| 344 | |
| 345 | validation_status = bt_param_validation_validate(params, |
| 346 | pretty_params, &validate_error); |
| 347 | if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) { |
| 348 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
| 349 | goto end; |
| 350 | } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { |
| 351 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
| 352 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error); |
| 353 | goto end; |
| 354 | } |
| 355 | |
| 356 | /* Known parameters. */ |
| 357 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
| 358 | value = bt_value_map_borrow_entry_value_const(params, "color"); |
| 359 | if (value) { |
| 360 | const char *color = bt_value_string_get(value); |
| 361 | |
| 362 | if (strcmp(color, "never") == 0) { |
| 363 | pretty->options.color = PRETTY_COLOR_OPT_NEVER; |
| 364 | } else if (strcmp(color, "auto") == 0) { |
| 365 | pretty->options.color = PRETTY_COLOR_OPT_AUTO; |
| 366 | } else { |
| 367 | BT_ASSERT(strcmp(color, "always") == 0); |
| 368 | pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | apply_one_string("path", params, &pretty->options.output_path); |
| 373 | ret = open_output_file(pretty); |
| 374 | if (ret) { |
| 375 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
| 376 | goto end; |
| 377 | } |
| 378 | |
| 379 | apply_one_bool_with_default("no-delta", params, |
| 380 | &pretty->options.print_delta_field, false); |
| 381 | /* Reverse logic. */ |
| 382 | pretty->options.print_delta_field = !pretty->options.print_delta_field; |
| 383 | |
| 384 | apply_one_bool_with_default("clock-cycles", params, |
| 385 | &pretty->options.print_timestamp_cycles, false); |
| 386 | |
| 387 | apply_one_bool_with_default("clock-seconds", params, |
| 388 | &pretty->options.clock_seconds , false); |
| 389 | |
| 390 | apply_one_bool_with_default("clock-date", params, |
| 391 | &pretty->options.clock_date, false); |
| 392 | |
| 393 | apply_one_bool_with_default("clock-gmt", params, |
| 394 | &pretty->options.clock_gmt, false); |
| 395 | |
| 396 | apply_one_bool_with_default("verbose", params, |
| 397 | &pretty->options.verbose, false); |
| 398 | |
| 399 | /* Names. */ |
| 400 | value = bt_value_map_borrow_entry_value_const(params, "name-default"); |
| 401 | if (value) { |
| 402 | const char *str = bt_value_string_get(value); |
| 403 | |
| 404 | if (strcmp(str, "show") == 0) { |
| 405 | pretty->options.name_default = PRETTY_DEFAULT_SHOW; |
| 406 | } else { |
| 407 | BT_ASSERT(strcmp(str, "hide") == 0); |
| 408 | pretty->options.name_default = PRETTY_DEFAULT_HIDE; |
| 409 | } |
| 410 | } else { |
| 411 | pretty->options.name_default = PRETTY_DEFAULT_UNSET; |
| 412 | } |
| 413 | |
| 414 | switch (pretty->options.name_default) { |
| 415 | case PRETTY_DEFAULT_UNSET: |
| 416 | pretty->options.print_payload_field_names = true; |
| 417 | pretty->options.print_context_field_names = true; |
| 418 | pretty->options.print_header_field_names = false; |
| 419 | pretty->options.print_scope_field_names = false; |
| 420 | break; |
| 421 | case PRETTY_DEFAULT_SHOW: |
| 422 | pretty->options.print_payload_field_names = true; |
| 423 | pretty->options.print_context_field_names = true; |
| 424 | pretty->options.print_header_field_names = true; |
| 425 | pretty->options.print_scope_field_names = true; |
| 426 | break; |
| 427 | case PRETTY_DEFAULT_HIDE: |
| 428 | pretty->options.print_payload_field_names = false; |
| 429 | pretty->options.print_context_field_names = false; |
| 430 | pretty->options.print_header_field_names = false; |
| 431 | pretty->options.print_scope_field_names = false; |
| 432 | break; |
| 433 | default: |
| 434 | bt_common_abort(); |
| 435 | } |
| 436 | |
| 437 | apply_one_bool_if_specified("name-payload", params, |
| 438 | &pretty->options.print_payload_field_names); |
| 439 | |
| 440 | apply_one_bool_if_specified("name-context", params, |
| 441 | &pretty->options.print_context_field_names); |
| 442 | |
| 443 | apply_one_bool_if_specified("name-header", params, |
| 444 | &pretty->options.print_header_field_names); |
| 445 | |
| 446 | apply_one_bool_if_specified("name-scope", params, |
| 447 | &pretty->options.print_scope_field_names); |
| 448 | |
| 449 | /* Fields. */ |
| 450 | value = bt_value_map_borrow_entry_value_const(params, "field-default"); |
| 451 | if (value) { |
| 452 | const char *str = bt_value_string_get(value); |
| 453 | |
| 454 | if (strcmp(str, "show") == 0) { |
| 455 | pretty->options.field_default = PRETTY_DEFAULT_SHOW; |
| 456 | } else { |
| 457 | BT_ASSERT(strcmp(str, "hide") == 0); |
| 458 | pretty->options.field_default = PRETTY_DEFAULT_HIDE; |
| 459 | } |
| 460 | } else { |
| 461 | pretty->options.field_default = PRETTY_DEFAULT_UNSET; |
| 462 | } |
| 463 | |
| 464 | switch (pretty->options.field_default) { |
| 465 | case PRETTY_DEFAULT_UNSET: |
| 466 | pretty->options.print_trace_field = false; |
| 467 | pretty->options.print_trace_hostname_field = true; |
| 468 | pretty->options.print_trace_domain_field = false; |
| 469 | pretty->options.print_trace_procname_field = true; |
| 470 | pretty->options.print_trace_vpid_field = true; |
| 471 | pretty->options.print_loglevel_field = false; |
| 472 | pretty->options.print_emf_field = false; |
| 473 | pretty->options.print_callsite_field = false; |
| 474 | break; |
| 475 | case PRETTY_DEFAULT_SHOW: |
| 476 | pretty->options.print_trace_field = true; |
| 477 | pretty->options.print_trace_hostname_field = true; |
| 478 | pretty->options.print_trace_domain_field = true; |
| 479 | pretty->options.print_trace_procname_field = true; |
| 480 | pretty->options.print_trace_vpid_field = true; |
| 481 | pretty->options.print_loglevel_field = true; |
| 482 | pretty->options.print_emf_field = true; |
| 483 | pretty->options.print_callsite_field = true; |
| 484 | break; |
| 485 | case PRETTY_DEFAULT_HIDE: |
| 486 | pretty->options.print_trace_field = false; |
| 487 | pretty->options.print_trace_hostname_field = false; |
| 488 | pretty->options.print_trace_domain_field = false; |
| 489 | pretty->options.print_trace_procname_field = false; |
| 490 | pretty->options.print_trace_vpid_field = false; |
| 491 | pretty->options.print_loglevel_field = false; |
| 492 | pretty->options.print_emf_field = false; |
| 493 | pretty->options.print_callsite_field = false; |
| 494 | break; |
| 495 | default: |
| 496 | bt_common_abort(); |
| 497 | } |
| 498 | |
| 499 | apply_one_bool_if_specified("field-trace", params, |
| 500 | &pretty->options.print_trace_field); |
| 501 | |
| 502 | apply_one_bool_if_specified("field-trace:hostname", params, |
| 503 | &pretty->options.print_trace_hostname_field); |
| 504 | |
| 505 | apply_one_bool_if_specified("field-trace:domain", params, |
| 506 | &pretty->options.print_trace_domain_field); |
| 507 | |
| 508 | apply_one_bool_if_specified("field-trace:procname", params, |
| 509 | &pretty->options.print_trace_procname_field); |
| 510 | |
| 511 | apply_one_bool_if_specified("field-trace:vpid", params, |
| 512 | &pretty->options.print_trace_vpid_field); |
| 513 | |
| 514 | apply_one_bool_if_specified("field-loglevel", params, |
| 515 | &pretty->options.print_loglevel_field); |
| 516 | |
| 517 | apply_one_bool_if_specified("field-emf", params, |
| 518 | &pretty->options.print_emf_field); |
| 519 | |
| 520 | apply_one_bool_if_specified("field-callsite", params, |
| 521 | &pretty->options.print_callsite_field); |
| 522 | |
| 523 | pretty_print_init(); |
| 524 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; |
| 525 | |
| 526 | end: |
| 527 | g_free(validate_error); |
| 528 | |
| 529 | return status; |
| 530 | } |
| 531 | |
| 532 | static |
| 533 | void set_use_colors(struct pretty_component *pretty) |
| 534 | { |
| 535 | switch (pretty->options.color) { |
| 536 | case PRETTY_COLOR_OPT_ALWAYS: |
| 537 | pretty->use_colors = true; |
| 538 | break; |
| 539 | case PRETTY_COLOR_OPT_AUTO: |
| 540 | pretty->use_colors = pretty->out == stdout && |
| 541 | bt_common_colors_supported(); |
| 542 | break; |
| 543 | case PRETTY_COLOR_OPT_NEVER: |
| 544 | pretty->use_colors = false; |
| 545 | break; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | BT_HIDDEN |
| 550 | bt_component_class_initialize_method_status pretty_init( |
| 551 | bt_self_component_sink *self_comp_sink, |
| 552 | bt_self_component_sink_configuration *config, |
| 553 | const bt_value *params, |
| 554 | __attribute__((unused)) void *init_method_data) |
| 555 | { |
| 556 | bt_component_class_initialize_method_status status; |
| 557 | bt_self_component_add_port_status add_port_status; |
| 558 | struct pretty_component *pretty = create_pretty(); |
| 559 | bt_self_component *self_comp = |
| 560 | bt_self_component_sink_as_self_component(self_comp_sink); |
| 561 | const bt_component *comp = bt_self_component_as_component(self_comp); |
| 562 | bt_logging_level log_level = bt_component_get_logging_level(comp); |
| 563 | |
| 564 | if (!pretty) { |
| 565 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
| 566 | goto error; |
| 567 | } |
| 568 | |
| 569 | add_port_status = bt_self_component_sink_add_input_port(self_comp_sink, |
| 570 | in_port_name, NULL, NULL); |
| 571 | if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) { |
| 572 | status = (int) add_port_status; |
| 573 | goto error; |
| 574 | } |
| 575 | |
| 576 | pretty->out = stdout; |
| 577 | pretty->err = stderr; |
| 578 | |
| 579 | pretty->delta_cycles = -1ULL; |
| 580 | pretty->last_cycles_timestamp = -1ULL; |
| 581 | |
| 582 | pretty->delta_real_timestamp = -1ULL; |
| 583 | pretty->last_real_timestamp = -1ULL; |
| 584 | |
| 585 | status = apply_params(pretty, params, self_comp, log_level); |
| 586 | if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { |
| 587 | goto error; |
| 588 | } |
| 589 | |
| 590 | set_use_colors(pretty); |
| 591 | bt_self_component_set_data(self_comp, pretty); |
| 592 | |
| 593 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; |
| 594 | goto end; |
| 595 | |
| 596 | error: |
| 597 | destroy_pretty_data(pretty); |
| 598 | |
| 599 | end: |
| 600 | return status; |
| 601 | } |