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