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