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