Commit | Line | Data |
---|---|---|
7a278c8e | 1 | /* |
5dac767a | 2 | * text.c |
7a278c8e | 3 | * |
5dac767a | 4 | * Babeltrace CTF Text Output Plugin |
7a278c8e | 5 | * |
2e339de1 | 6 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
f504043c | 7 | * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
7a278c8e JG |
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 | ||
33b34c43 | 30 | #include <babeltrace/plugin/plugin-dev.h> |
b2e0c907 PP |
31 | #include <babeltrace/graph/component.h> |
32 | #include <babeltrace/graph/private-component.h> | |
33 | #include <babeltrace/graph/component-sink.h> | |
34 | #include <babeltrace/graph/port.h> | |
35 | #include <babeltrace/graph/private-port.h> | |
36 | #include <babeltrace/graph/connection.h> | |
37 | #include <babeltrace/graph/private-connection.h> | |
38 | #include <babeltrace/graph/notification.h> | |
39 | #include <babeltrace/graph/notification-iterator.h> | |
40 | #include <babeltrace/graph/notification-event.h> | |
6e1bc0df | 41 | #include <babeltrace/values.h> |
3d9990ac | 42 | #include <babeltrace/compiler-internal.h> |
ad96d936 | 43 | #include <babeltrace/common-internal.h> |
7d61fa8e | 44 | #include <plugins-common.h> |
bfd20a42 | 45 | #include <stdio.h> |
39cfa40f | 46 | #include <stdbool.h> |
bac67f0f | 47 | #include <glib.h> |
541b0a11 | 48 | #include "text.h" |
75e1829b | 49 | #include <assert.h> |
6405967d | 50 | |
6e1bc0df MD |
51 | static |
52 | const char *plugin_options[] = { | |
ad96d936 | 53 | "color", |
6e1bc0df MD |
54 | "output-path", |
55 | "debug-info-dir", | |
56 | "debug-info-target-prefix", | |
57 | "debug-info-full-path", | |
58 | "no-delta", | |
59 | "clock-cycles", | |
60 | "clock-seconds", | |
61 | "clock-date", | |
62 | "clock-gmt", | |
a263021c | 63 | "verbose", |
6e1bc0df MD |
64 | "name-default", /* show/hide */ |
65 | "name-payload", | |
66 | "name-context", | |
67 | "name-scope", | |
68 | "name-header", | |
69 | "field-default", /* show/hide */ | |
70 | "field-trace", | |
71 | "field-trace:hostname", | |
72 | "field-trace:domain", | |
73 | "field-trace:procname", | |
74 | "field-trace:vpid", | |
75 | "field-loglevel", | |
76 | "field-emf", | |
60535549 | 77 | "field-callsite", |
6e1bc0df MD |
78 | }; |
79 | ||
bfd20a42 | 80 | static |
541b0a11 | 81 | void destroy_text_data(struct text_component *text) |
bac67f0f | 82 | { |
75e1829b | 83 | bt_put(text->input_iterator); |
6a18b281 | 84 | (void) g_string_free(text->string, TRUE); |
77986bad JD |
85 | if (text->out != stdout) { |
86 | int ret; | |
87 | ||
88 | ret = fclose(text->out); | |
89 | if (ret) { | |
90 | perror("close output file"); | |
91 | } | |
92 | } | |
6e1bc0df MD |
93 | g_free(text->options.output_path); |
94 | g_free(text->options.debug_info_dir); | |
95 | g_free(text->options.debug_info_target_prefix); | |
541b0a11 | 96 | g_free(text); |
bac67f0f JG |
97 | } |
98 | ||
b25bd455 | 99 | static |
541b0a11 | 100 | struct text_component *create_text(void) |
bac67f0f | 101 | { |
541b0a11 JG |
102 | struct text_component *text; |
103 | ||
104 | text = g_new0(struct text_component, 1); | |
105 | if (!text) { | |
106 | goto end; | |
107 | } | |
6a18b281 MD |
108 | text->string = g_string_new(""); |
109 | if (!text->string) { | |
110 | goto error; | |
111 | } | |
541b0a11 JG |
112 | end: |
113 | return text; | |
6a18b281 MD |
114 | |
115 | error: | |
116 | g_free(text); | |
117 | return NULL; | |
bac67f0f JG |
118 | } |
119 | ||
fec2a9f2 | 120 | static |
64cadc66 | 121 | void finalize_text(struct bt_private_component *component) |
b25bd455 | 122 | { |
890882ef | 123 | void *data = bt_private_component_get_user_data(component); |
b25bd455 JG |
124 | |
125 | destroy_text_data(data); | |
126 | } | |
127 | ||
bac67f0f | 128 | static |
fec2a9f2 | 129 | enum bt_component_status handle_notification(struct text_component *text, |
6e1bc0df | 130 | struct bt_notification *notification) |
4c1456f0 | 131 | { |
541b0a11 | 132 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
541b0a11 JG |
133 | |
134 | if (!text) { | |
135 | ret = BT_COMPONENT_STATUS_ERROR; | |
136 | goto end; | |
137 | } | |
138 | ||
78586d8a | 139 | switch (bt_notification_get_type(notification)) { |
ea0e619e | 140 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: |
78586d8a JG |
141 | break; |
142 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
78586d8a JG |
143 | break; |
144 | case BT_NOTIFICATION_TYPE_EVENT: | |
541b0a11 JG |
145 | { |
146 | struct bt_ctf_event *event = bt_notification_event_get_event( | |
147 | notification); | |
148 | ||
541b0a11 JG |
149 | if (!event) { |
150 | ret = BT_COMPONENT_STATUS_ERROR; | |
151 | goto end; | |
152 | } | |
153 | ret = text_print_event(text, event); | |
fec2a9f2 | 154 | bt_put(event); |
541b0a11 JG |
155 | if (ret != BT_COMPONENT_STATUS_OK) { |
156 | goto end; | |
157 | } | |
043e2020 | 158 | break; |
541b0a11 | 159 | } |
043e2020 | 160 | case BT_NOTIFICATION_TYPE_STREAM_END: |
78586d8a JG |
161 | break; |
162 | default: | |
163 | puts("Unhandled notification type"); | |
164 | } | |
541b0a11 JG |
165 | end: |
166 | return ret; | |
4c1456f0 | 167 | } |
bac67f0f | 168 | |
75e1829b | 169 | static |
890882ef PP |
170 | enum bt_component_status text_accept_port_connection( |
171 | struct bt_private_component *component, | |
8f4799f7 PP |
172 | struct bt_private_port *self_port, |
173 | struct bt_port *other_port) | |
75e1829b JG |
174 | { |
175 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
890882ef | 176 | struct bt_private_connection *connection; |
75e1829b JG |
177 | struct text_component *text; |
178 | ||
890882ef | 179 | text = bt_private_component_get_user_data(component); |
75e1829b JG |
180 | assert(text); |
181 | assert(!text->input_iterator); | |
890882ef | 182 | connection = bt_private_port_get_private_connection(self_port); |
72b913fb | 183 | assert(connection); |
890882ef PP |
184 | text->input_iterator = |
185 | bt_private_connection_create_notification_iterator(connection); | |
75e1829b JG |
186 | |
187 | if (!text->input_iterator) { | |
188 | ret = BT_COMPONENT_STATUS_ERROR; | |
189 | } | |
72b913fb PP |
190 | |
191 | bt_put(connection); | |
75e1829b JG |
192 | return ret; |
193 | } | |
194 | ||
fec2a9f2 | 195 | static |
890882ef | 196 | enum bt_component_status run(struct bt_private_component *component) |
fec2a9f2 JG |
197 | { |
198 | enum bt_component_status ret; | |
199 | struct bt_notification *notification = NULL; | |
200 | struct bt_notification_iterator *it; | |
890882ef PP |
201 | struct text_component *text = |
202 | bt_private_component_get_user_data(component); | |
41a2b7ae | 203 | enum bt_notification_iterator_status it_ret; |
fec2a9f2 | 204 | |
75e1829b | 205 | it = text->input_iterator; |
fec2a9f2 | 206 | |
41a2b7ae PP |
207 | it_ret = bt_notification_iterator_next(it); |
208 | switch (it_ret) { | |
209 | case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: | |
fec2a9f2 JG |
210 | ret = BT_COMPONENT_STATUS_ERROR; |
211 | goto end; | |
41a2b7ae PP |
212 | case BT_NOTIFICATION_ITERATOR_STATUS_END: |
213 | ret = BT_COMPONENT_STATUS_END; | |
214 | BT_PUT(text->input_iterator); | |
215 | goto end; | |
216 | default: | |
217 | break; | |
fec2a9f2 JG |
218 | } |
219 | ||
41a2b7ae PP |
220 | notification = bt_notification_iterator_get_notification(it); |
221 | assert(notification); | |
fec2a9f2 | 222 | ret = handle_notification(text, notification); |
f48bc732 | 223 | text->processed_first_event = true; |
fec2a9f2 | 224 | end: |
fec2a9f2 JG |
225 | bt_put(notification); |
226 | return ret; | |
227 | } | |
228 | ||
6e1bc0df MD |
229 | static |
230 | enum bt_component_status add_params_to_map(struct bt_value *plugin_opt_map) | |
231 | { | |
232 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
233 | unsigned int i; | |
234 | ||
235 | for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) { | |
236 | const char *key = plugin_options[i]; | |
237 | enum bt_value_status status; | |
238 | ||
239 | status = bt_value_map_insert(plugin_opt_map, key, bt_value_null); | |
240 | switch (status) { | |
241 | case BT_VALUE_STATUS_OK: | |
242 | break; | |
243 | default: | |
244 | ret = BT_COMPONENT_STATUS_ERROR; | |
245 | goto end; | |
246 | } | |
247 | } | |
248 | end: | |
249 | return ret; | |
250 | } | |
251 | ||
252 | static | |
253 | bool check_param_exists(const char *key, struct bt_value *object, void *data) | |
254 | { | |
255 | struct text_component *text = data; | |
256 | struct bt_value *plugin_opt_map = text->plugin_opt_map; | |
257 | ||
258 | if (!bt_value_map_get(plugin_opt_map, key)) { | |
259 | fprintf(text->err, | |
6ba0b073 | 260 | "[warning] Parameter \"%s\" unknown to \"text\" plugin\n", key); |
6e1bc0df MD |
261 | } |
262 | return true; | |
263 | } | |
264 | ||
265 | static | |
266 | enum bt_component_status apply_one_string(const char *key, | |
267 | struct bt_value *params, | |
268 | char **option) | |
269 | { | |
270 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
271 | struct bt_value *value = NULL; | |
272 | enum bt_value_status status; | |
273 | const char *str; | |
274 | ||
275 | value = bt_value_map_get(params, key); | |
276 | if (!value) { | |
277 | goto end; | |
278 | } | |
279 | if (bt_value_is_null(value)) { | |
280 | goto end; | |
281 | } | |
282 | status = bt_value_string_get(value, &str); | |
283 | switch (status) { | |
284 | case BT_VALUE_STATUS_OK: | |
285 | break; | |
286 | default: | |
287 | ret = BT_COMPONENT_STATUS_ERROR; | |
288 | goto end; | |
289 | } | |
290 | *option = g_strdup(str); | |
291 | end: | |
292 | bt_put(value); | |
293 | return ret; | |
294 | } | |
295 | ||
296 | static | |
297 | enum bt_component_status apply_one_bool(const char *key, | |
298 | struct bt_value *params, | |
299 | bool *option, | |
300 | bool *found) | |
301 | { | |
302 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
303 | struct bt_value *value = NULL; | |
304 | enum bt_value_status status; | |
305 | ||
306 | value = bt_value_map_get(params, key); | |
307 | if (!value) { | |
308 | goto end; | |
309 | } | |
310 | status = bt_value_bool_get(value, option); | |
311 | switch (status) { | |
312 | case BT_VALUE_STATUS_OK: | |
313 | break; | |
314 | default: | |
315 | ret = BT_COMPONENT_STATUS_ERROR; | |
316 | goto end; | |
317 | } | |
318 | if (found) { | |
319 | *found = true; | |
320 | } | |
321 | end: | |
322 | bt_put(value); | |
323 | return ret; | |
324 | } | |
325 | ||
ad96d936 PP |
326 | static |
327 | void warn_wrong_color_param(struct text_component *text) | |
328 | { | |
329 | fprintf(text->err, | |
330 | "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n"); | |
331 | } | |
332 | ||
77986bad JD |
333 | static |
334 | enum bt_component_status open_output_file(struct text_component *text) | |
335 | { | |
336 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
337 | ||
338 | if (!text->options.output_path) { | |
339 | goto end; | |
340 | } | |
341 | ||
342 | text->out = fopen(text->options.output_path, "w"); | |
343 | if (!text->out) { | |
344 | goto error; | |
345 | } | |
346 | ||
347 | goto end; | |
348 | ||
349 | error: | |
350 | ret = BT_COMPONENT_STATUS_ERROR; | |
351 | end: | |
352 | return ret; | |
353 | } | |
354 | ||
6e1bc0df MD |
355 | static |
356 | enum bt_component_status apply_params(struct text_component *text, | |
357 | struct bt_value *params) | |
358 | { | |
359 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
360 | enum bt_value_status status; | |
361 | bool value, found; | |
362 | char *str = NULL; | |
363 | ||
364 | text->plugin_opt_map = bt_value_map_create(); | |
365 | if (!text->plugin_opt_map) { | |
366 | ret = BT_COMPONENT_STATUS_ERROR; | |
367 | goto end; | |
368 | } | |
369 | ret = add_params_to_map(text->plugin_opt_map); | |
370 | if (ret != BT_COMPONENT_STATUS_OK) { | |
371 | goto end; | |
372 | } | |
373 | /* Report unknown parameters. */ | |
374 | status = bt_value_map_foreach(params, check_param_exists, text); | |
375 | switch (status) { | |
376 | case BT_VALUE_STATUS_OK: | |
377 | break; | |
378 | default: | |
379 | ret = BT_COMPONENT_STATUS_ERROR; | |
380 | goto end; | |
381 | } | |
382 | /* Known parameters. */ | |
ad96d936 PP |
383 | text->options.color = TEXT_COLOR_OPT_AUTO; |
384 | if (bt_value_map_has_key(params, "color")) { | |
385 | struct bt_value *color_value; | |
386 | const char *color; | |
387 | ||
388 | color_value = bt_value_map_get(params, "color"); | |
389 | if (!color_value) { | |
390 | goto end; | |
391 | } | |
392 | ||
72b913fb PP |
393 | status = bt_value_string_get(color_value, &color); |
394 | if (status) { | |
ad96d936 PP |
395 | warn_wrong_color_param(text); |
396 | } else { | |
397 | if (strcmp(color, "never") == 0) { | |
398 | text->options.color = TEXT_COLOR_OPT_NEVER; | |
399 | } else if (strcmp(color, "auto") == 0) { | |
400 | text->options.color = TEXT_COLOR_OPT_AUTO; | |
401 | } else if (strcmp(color, "always") == 0) { | |
402 | text->options.color = TEXT_COLOR_OPT_ALWAYS; | |
403 | } else { | |
404 | warn_wrong_color_param(text); | |
405 | } | |
406 | } | |
407 | ||
408 | bt_put(color_value); | |
409 | } | |
410 | ||
6e1bc0df MD |
411 | ret = apply_one_string("output-path", |
412 | params, | |
413 | &text->options.output_path); | |
414 | if (ret != BT_COMPONENT_STATUS_OK) { | |
415 | goto end; | |
416 | } | |
77986bad JD |
417 | ret = open_output_file(text); |
418 | if (ret != BT_COMPONENT_STATUS_OK) { | |
419 | goto end; | |
420 | } | |
6e1bc0df MD |
421 | |
422 | ret = apply_one_string("debug-info-dir", | |
423 | params, | |
424 | &text->options.debug_info_dir); | |
425 | if (ret != BT_COMPONENT_STATUS_OK) { | |
426 | goto end; | |
427 | } | |
428 | ||
429 | ret = apply_one_string("debug-info-target-prefix", | |
430 | params, | |
431 | &text->options.debug_info_target_prefix); | |
432 | if (ret != BT_COMPONENT_STATUS_OK) { | |
433 | goto end; | |
434 | } | |
435 | ||
436 | value = false; /* Default. */ | |
437 | ret = apply_one_bool("debug-info-full-path", params, &value, NULL); | |
438 | if (ret != BT_COMPONENT_STATUS_OK) { | |
439 | goto end; | |
440 | } | |
441 | text->options.debug_info_full_path = value; | |
442 | ||
443 | value = false; /* Default. */ | |
444 | ret = apply_one_bool("no-delta", params, &value, NULL); | |
445 | if (ret != BT_COMPONENT_STATUS_OK) { | |
446 | goto end; | |
447 | } | |
448 | text->options.print_delta_field = !value; /* Reverse logic. */ | |
449 | ||
450 | value = false; /* Default. */ | |
451 | ret = apply_one_bool("clock-cycles", params, &value, NULL); | |
452 | if (ret != BT_COMPONENT_STATUS_OK) { | |
453 | goto end; | |
454 | } | |
455 | text->options.print_timestamp_cycles = value; | |
456 | ||
457 | value = false; /* Default. */ | |
458 | ret = apply_one_bool("clock-seconds", params, &value, NULL); | |
459 | if (ret != BT_COMPONENT_STATUS_OK) { | |
460 | goto end; | |
461 | } | |
462 | text->options.clock_seconds = value; | |
463 | ||
464 | value = false; /* Default. */ | |
465 | ret = apply_one_bool("clock-date", params, &value, NULL); | |
466 | if (ret != BT_COMPONENT_STATUS_OK) { | |
467 | goto end; | |
468 | } | |
469 | text->options.clock_date = value; | |
470 | ||
471 | value = false; /* Default. */ | |
472 | ret = apply_one_bool("clock-gmt", params, &value, NULL); | |
473 | if (ret != BT_COMPONENT_STATUS_OK) { | |
474 | goto end; | |
475 | } | |
476 | text->options.clock_gmt = value; | |
477 | ||
a263021c JD |
478 | value = false; /* Default. */ |
479 | ret = apply_one_bool("verbose", params, &value, NULL); | |
480 | if (ret != BT_COMPONENT_STATUS_OK) { | |
481 | goto end; | |
482 | } | |
483 | text->options.verbose = value; | |
484 | ||
6e1bc0df MD |
485 | /* Names. */ |
486 | ret = apply_one_string("name-default", params, &str); | |
487 | if (ret != BT_COMPONENT_STATUS_OK) { | |
488 | goto end; | |
489 | } | |
490 | if (!str) { | |
491 | text->options.name_default = TEXT_DEFAULT_UNSET; | |
492 | } else if (!strcmp(str, "show")) { | |
493 | text->options.name_default = TEXT_DEFAULT_SHOW; | |
494 | } else if (!strcmp(str, "hide")) { | |
495 | text->options.name_default = TEXT_DEFAULT_HIDE; | |
496 | } else { | |
497 | ret = BT_COMPONENT_STATUS_ERROR; | |
498 | goto end; | |
499 | } | |
500 | g_free(str); | |
501 | str = NULL; | |
502 | ||
503 | switch (text->options.name_default) { | |
504 | case TEXT_DEFAULT_UNSET: | |
505 | text->options.print_payload_field_names = true; | |
506 | text->options.print_context_field_names = true; | |
507 | text->options.print_header_field_names = false; | |
508 | text->options.print_scope_field_names = false; | |
509 | break; | |
510 | case TEXT_DEFAULT_SHOW: | |
511 | text->options.print_payload_field_names = true; | |
512 | text->options.print_context_field_names = true; | |
513 | text->options.print_header_field_names = true; | |
514 | text->options.print_scope_field_names = true; | |
515 | break; | |
516 | case TEXT_DEFAULT_HIDE: | |
517 | text->options.print_payload_field_names = false; | |
518 | text->options.print_context_field_names = false; | |
519 | text->options.print_header_field_names = false; | |
520 | text->options.print_scope_field_names = false; | |
521 | break; | |
522 | default: | |
523 | ret = BT_COMPONENT_STATUS_ERROR; | |
524 | goto end; | |
525 | } | |
526 | ||
527 | value = false; | |
528 | found = false; | |
529 | ret = apply_one_bool("name-payload", params, &value, &found); | |
530 | if (ret != BT_COMPONENT_STATUS_OK) { | |
531 | goto end; | |
532 | } | |
533 | if (found) { | |
534 | text->options.print_payload_field_names = value; | |
535 | } | |
536 | ||
537 | value = false; | |
538 | found = false; | |
539 | ret = apply_one_bool("name-context", params, &value, &found); | |
540 | if (ret != BT_COMPONENT_STATUS_OK) { | |
541 | goto end; | |
542 | } | |
543 | if (found) { | |
544 | text->options.print_context_field_names = value; | |
545 | } | |
546 | ||
547 | value = false; | |
548 | found = false; | |
549 | ret = apply_one_bool("name-header", params, &value, &found); | |
550 | if (ret != BT_COMPONENT_STATUS_OK) { | |
551 | goto end; | |
552 | } | |
553 | if (found) { | |
554 | text->options.print_header_field_names = value; | |
555 | } | |
556 | ||
557 | value = false; | |
558 | found = false; | |
559 | ret = apply_one_bool("name-scope", params, &value, &found); | |
560 | if (ret != BT_COMPONENT_STATUS_OK) { | |
561 | goto end; | |
562 | } | |
563 | if (found) { | |
564 | text->options.print_scope_field_names = value; | |
565 | } | |
566 | ||
567 | /* Fields. */ | |
568 | ret = apply_one_string("field-default", params, &str); | |
569 | if (ret != BT_COMPONENT_STATUS_OK) { | |
570 | goto end; | |
571 | } | |
572 | if (!str) { | |
573 | text->options.field_default = TEXT_DEFAULT_UNSET; | |
574 | } else if (!strcmp(str, "show")) { | |
575 | text->options.field_default = TEXT_DEFAULT_SHOW; | |
576 | } else if (!strcmp(str, "hide")) { | |
577 | text->options.field_default = TEXT_DEFAULT_HIDE; | |
578 | } else { | |
579 | ret = BT_COMPONENT_STATUS_ERROR; | |
580 | goto end; | |
581 | } | |
582 | g_free(str); | |
583 | str = NULL; | |
584 | ||
585 | switch (text->options.field_default) { | |
586 | case TEXT_DEFAULT_UNSET: | |
587 | text->options.print_trace_field = false; | |
588 | text->options.print_trace_hostname_field = true; | |
589 | text->options.print_trace_domain_field = false; | |
590 | text->options.print_trace_procname_field = true; | |
591 | text->options.print_trace_vpid_field = true; | |
592 | text->options.print_loglevel_field = false; | |
593 | text->options.print_emf_field = false; | |
60535549 | 594 | text->options.print_callsite_field = false; |
6e1bc0df MD |
595 | break; |
596 | case TEXT_DEFAULT_SHOW: | |
597 | text->options.print_trace_field = true; | |
598 | text->options.print_trace_hostname_field = true; | |
599 | text->options.print_trace_domain_field = true; | |
600 | text->options.print_trace_procname_field = true; | |
601 | text->options.print_trace_vpid_field = true; | |
602 | text->options.print_loglevel_field = true; | |
603 | text->options.print_emf_field = true; | |
60535549 | 604 | text->options.print_callsite_field = true; |
6e1bc0df MD |
605 | break; |
606 | case TEXT_DEFAULT_HIDE: | |
607 | text->options.print_trace_field = false; | |
608 | text->options.print_trace_hostname_field = false; | |
609 | text->options.print_trace_domain_field = false; | |
610 | text->options.print_trace_procname_field = false; | |
611 | text->options.print_trace_vpid_field = false; | |
612 | text->options.print_loglevel_field = false; | |
613 | text->options.print_emf_field = false; | |
60535549 | 614 | text->options.print_callsite_field = false; |
6e1bc0df MD |
615 | break; |
616 | default: | |
617 | ret = BT_COMPONENT_STATUS_ERROR; | |
618 | goto end; | |
619 | } | |
620 | ||
621 | value = false; | |
622 | found = false; | |
623 | ret = apply_one_bool("field-trace", params, &value, &found); | |
624 | if (ret != BT_COMPONENT_STATUS_OK) { | |
625 | goto end; | |
626 | } | |
627 | if (found) { | |
628 | text->options.print_trace_field = value; | |
629 | } | |
630 | ||
631 | value = false; | |
632 | found = false; | |
633 | ret = apply_one_bool("field-trace:hostname", params, &value, &found); | |
634 | if (ret != BT_COMPONENT_STATUS_OK) { | |
635 | goto end; | |
636 | } | |
637 | if (found) { | |
638 | text->options.print_trace_hostname_field = value; | |
639 | } | |
640 | ||
641 | value = false; | |
642 | found = false; | |
643 | ret = apply_one_bool("field-trace:domain", params, &value, &found); | |
644 | if (ret != BT_COMPONENT_STATUS_OK) { | |
645 | goto end; | |
646 | } | |
647 | if (found) { | |
648 | text->options.print_trace_domain_field = value; | |
649 | } | |
650 | ||
651 | value = false; | |
652 | found = false; | |
653 | ret = apply_one_bool("field-trace:procname", params, &value, &found); | |
654 | if (ret != BT_COMPONENT_STATUS_OK) { | |
655 | goto end; | |
656 | } | |
657 | if (found) { | |
658 | text->options.print_trace_procname_field = value; | |
659 | } | |
660 | ||
661 | value = false; | |
662 | found = false; | |
663 | ret = apply_one_bool("field-trace:vpid", params, &value, &found); | |
664 | if (ret != BT_COMPONENT_STATUS_OK) { | |
665 | goto end; | |
666 | } | |
667 | if (found) { | |
668 | text->options.print_trace_vpid_field = value; | |
669 | } | |
670 | ||
671 | value = false; | |
672 | found = false; | |
673 | ret = apply_one_bool("field-loglevel", params, &value, &found); | |
674 | if (ret != BT_COMPONENT_STATUS_OK) { | |
675 | goto end; | |
676 | } | |
677 | if (found) { | |
678 | text->options.print_loglevel_field = value; | |
679 | } | |
680 | ||
681 | value = false; | |
682 | found = false; | |
683 | ret = apply_one_bool("field-emf", params, &value, &found); | |
684 | if (ret != BT_COMPONENT_STATUS_OK) { | |
685 | goto end; | |
686 | } | |
687 | if (found) { | |
688 | text->options.print_emf_field = value; | |
689 | } | |
690 | ||
691 | value = false; | |
692 | found = false; | |
60535549 | 693 | ret = apply_one_bool("field-callsite", params, &value, &found); |
6e1bc0df MD |
694 | if (ret != BT_COMPONENT_STATUS_OK) { |
695 | goto end; | |
696 | } | |
697 | if (found) { | |
60535549 | 698 | text->options.print_callsite_field = value; |
6e1bc0df MD |
699 | } |
700 | ||
6e1bc0df MD |
701 | end: |
702 | bt_put(text->plugin_opt_map); | |
703 | text->plugin_opt_map = NULL; | |
704 | g_free(str); | |
705 | return ret; | |
706 | } | |
707 | ||
ad96d936 PP |
708 | static |
709 | void set_use_colors(struct text_component *text) | |
710 | { | |
711 | switch (text->options.color) { | |
712 | case TEXT_COLOR_OPT_ALWAYS: | |
713 | text->use_colors = true; | |
714 | break; | |
715 | case TEXT_COLOR_OPT_AUTO: | |
716 | text->use_colors = text->out == stdout && | |
717 | bt_common_colors_supported(); | |
718 | break; | |
719 | case TEXT_COLOR_OPT_NEVER: | |
720 | text->use_colors = false; | |
721 | break; | |
722 | } | |
723 | } | |
724 | ||
2b4c4a7c JD |
725 | static |
726 | void init_stream_packet_context_quarks(void) | |
727 | { | |
728 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = | |
729 | g_quark_from_string("timestamp_begin"); | |
730 | stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = | |
731 | g_quark_from_string("timestamp_begin"); | |
732 | stream_packet_context_quarks[Q_TIMESTAMP_END] = | |
733 | g_quark_from_string("timestamp_end"); | |
734 | stream_packet_context_quarks[Q_EVENTS_DISCARDED] = | |
735 | g_quark_from_string("events_discarded"); | |
736 | stream_packet_context_quarks[Q_CONTENT_SIZE] = | |
737 | g_quark_from_string("content_size"); | |
738 | stream_packet_context_quarks[Q_PACKET_SIZE] = | |
739 | g_quark_from_string("packet_size"); | |
740 | stream_packet_context_quarks[Q_PACKET_SEQ_NUM] = | |
741 | g_quark_from_string("packet_seq_num"); | |
742 | } | |
743 | ||
bac67f0f JG |
744 | static |
745 | enum bt_component_status text_component_init( | |
890882ef PP |
746 | struct bt_private_component *component, |
747 | struct bt_value *params, | |
7d61fa8e | 748 | UNUSED_VAR void *init_method_data) |
bac67f0f JG |
749 | { |
750 | enum bt_component_status ret; | |
751 | struct text_component *text = create_text(); | |
752 | ||
753 | if (!text) { | |
754 | ret = BT_COMPONENT_STATUS_NOMEM; | |
755 | goto end; | |
756 | } | |
757 | ||
6e1bc0df MD |
758 | text->out = stdout; |
759 | text->err = stderr; | |
760 | ||
3af83b5a MD |
761 | text->delta_cycles = -1ULL; |
762 | text->last_cycles_timestamp = -1ULL; | |
763 | ||
764 | text->delta_real_timestamp = -1ULL; | |
765 | text->last_real_timestamp = -1ULL; | |
766 | ||
6e1bc0df MD |
767 | ret = apply_params(text, params); |
768 | if (ret != BT_COMPONENT_STATUS_OK) { | |
769 | goto error; | |
770 | } | |
771 | ||
ad96d936 PP |
772 | set_use_colors(text); |
773 | ||
890882ef | 774 | ret = bt_private_component_set_user_data(component, text); |
bac67f0f JG |
775 | if (ret != BT_COMPONENT_STATUS_OK) { |
776 | goto error; | |
777 | } | |
2b4c4a7c JD |
778 | |
779 | init_stream_packet_context_quarks(); | |
780 | ||
bac67f0f JG |
781 | end: |
782 | return ret; | |
783 | error: | |
b25bd455 | 784 | destroy_text_data(text); |
bac67f0f JG |
785 | return ret; |
786 | } | |
787 | ||
bac67f0f | 788 | /* Initialize plug-in entry points. */ |
6ba0b073 | 789 | BT_PLUGIN(text); |
bac67f0f JG |
790 | BT_PLUGIN_DESCRIPTION("Babeltrace text output plug-in."); |
791 | BT_PLUGIN_AUTHOR("Jérémie Galarneau"); | |
792 | BT_PLUGIN_LICENSE("MIT"); | |
d3e4dcd8 PP |
793 | BT_PLUGIN_SINK_COMPONENT_CLASS(text, run); |
794 | BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(text, text_component_init); | |
72b913fb | 795 | BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD(text, text_accept_port_connection); |
64cadc66 | 796 | BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD(text, finalize_text); |
d3e4dcd8 | 797 | BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(text, |
6ba0b073 | 798 | "Formats CTF-IR to text. Formerly known as ctf-text."); |