4 * Babeltrace CTF Text Output Plugin Event Printing
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/ctf-ir/event.h>
30 #include <babeltrace/ctf-ir/event-class.h>
31 #include <babeltrace/ctf-ir/packet.h>
32 #include <babeltrace/ctf-ir/stream.h>
33 #include <babeltrace/ctf-ir/stream-class.h>
34 #include <babeltrace/ctf-ir/clock.h>
35 #include <babeltrace/ctf-ir/field-types.h>
36 #include <babeltrace/ctf-ir/fields.h>
37 #include <babeltrace/ctf-ir/trace.h>
38 #include <babeltrace/bitfield.h>
42 #define NSEC_PER_SEC 1000000000LL
45 const char *rem_(const char *str
)
54 int64_t real_timestamp
; /* Relative to UNIX epoch. */
55 uint64_t clock_value
; /* In cycles. */
59 enum bt_component_status
print_field(struct text_component
*text
,
60 struct bt_ctf_field
*field
, bool print_names
);
63 void print_timestamp_cycles(struct text_component
*text
,
64 struct bt_ctf_clock
*clock
,
65 struct bt_ctf_event
*event
)
68 struct bt_ctf_clock_value
*clock_value
;
71 clock_value
= bt_ctf_event_get_clock_value(event
, clock
);
73 fputs("????????????????????", text
->out
);
77 ret
= bt_ctf_clock_value_get_value(clock_value
, &cycles
);
80 fprintf(text
->out
, "Error");
83 fprintf(text
->out
, "%020" PRIu64
, cycles
);
87 void print_timestamp_wall(struct text_component
*text
,
88 struct bt_ctf_clock
*clock
,
89 struct bt_ctf_event
*event
)
92 struct bt_ctf_clock_value
*clock_value
;
93 int64_t ts_nsec
= 0; /* add configurable offset */
94 int64_t ts_sec
= 0; /* add configurable offset */
95 uint64_t ts_sec_abs
, ts_nsec_abs
;
98 clock_value
= bt_ctf_event_get_clock_value(event
, clock
);
100 fputs("??:??:??.?????????", text
->out
);
104 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(clock_value
, &ts_nsec
);
107 fprintf(text
->out
, "Error");
111 ts_sec
+= ts_nsec
/ NSEC_PER_SEC
;
112 ts_nsec
= ts_nsec
% NSEC_PER_SEC
;
113 if (ts_sec
>= 0 && ts_nsec
>= 0) {
116 ts_nsec_abs
= ts_nsec
;
117 } else if (ts_sec
> 0 && ts_nsec
< 0) {
119 ts_sec_abs
= ts_sec
- 1;
120 ts_nsec_abs
= NSEC_PER_SEC
+ ts_nsec
;
121 } else if (ts_sec
== 0 && ts_nsec
< 0) {
124 ts_nsec_abs
= -ts_nsec
;
125 } else if (ts_sec
< 0 && ts_nsec
> 0) {
127 ts_sec_abs
= -(ts_sec
+ 1);
128 ts_nsec_abs
= NSEC_PER_SEC
- ts_nsec
;
129 } else if (ts_sec
< 0 && ts_nsec
== 0) {
131 ts_sec_abs
= -ts_sec
;
132 ts_nsec_abs
= ts_nsec
;
133 } else { /* (ts_sec < 0 && ts_nsec < 0) */
135 ts_sec_abs
= -ts_sec
;
136 ts_nsec_abs
= -ts_nsec
;
139 if (/*!opt_clock_seconds*/true) {
141 time_t time_s
= (time_t) ts_sec_abs
;
144 fprintf(stderr
, "[warning] Fallback to [sec.ns] to print negative time value. Use --clock-seconds.\n");
148 if (/*!opt_clock_gmt*/true) {
151 res
= localtime_r(&time_s
, &tm
);
153 fprintf(stderr
, "[warning] Unable to get localtime.\n");
159 res
= gmtime_r(&time_s
, &tm
);
161 fprintf(stderr
, "[warning] Unable to get gmtime.\n");
165 if (/*opt_clock_date*/false) {
169 /* Print date and time */
170 res
= strftime(timestr
, sizeof(timestr
),
173 fprintf(stderr
, "[warning] Unable to print ascii time.\n");
176 fprintf(text
->out
, "%s", timestr
);
178 /* Print time in HH:MM:SS.ns */
179 fprintf(text
->out
, "%02d:%02d:%02d.%09" PRIu64
,
180 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
, ts_nsec_abs
);
184 fprintf(text
->out
, "%s%" PRId64
".%09" PRIu64
,
185 is_negative
? "-" : "", ts_sec_abs
, ts_nsec_abs
);
191 enum bt_component_status
print_event_timestamp(struct text_component
*text
,
192 struct bt_ctf_event
*event
, bool *start_line
)
194 bool print_names
= text
->options
.print_header_field_names
;
195 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
196 struct bt_ctf_stream
*stream
= NULL
;
197 struct bt_ctf_stream_class
*stream_class
= NULL
;
198 struct bt_ctf_trace
*trace
= NULL
;
199 struct bt_ctf_clock
*clock
= NULL
;
200 FILE *out
= text
->out
;
201 FILE *err
= text
->err
;
202 uint64_t real_timestamp
;
204 stream
= bt_ctf_event_get_stream(event
);
206 ret
= BT_COMPONENT_STATUS_ERROR
;
210 /* FIXME - error checking */
211 stream_class
= bt_ctf_stream_get_class(stream
);
212 trace
= bt_ctf_stream_class_get_trace(stream_class
);
213 clock
= bt_ctf_trace_get_clock(trace
, 0);
215 fputs(print_names
? "timestamp = " : "[", out
);
216 if (text
->options
.print_timestamp_cycles
) {
217 print_timestamp_cycles(text
, clock
, event
);
219 print_timestamp_wall(text
, clock
, event
);
224 *start_line
= !print_names
;
226 if (!text
->options
.print_delta_field
) {
232 bt_put(stream_class
);
238 enum bt_component_status
print_event_header(struct text_component
*text
,
239 struct bt_ctf_event
*event
)
241 bool print_names
= text
->options
.print_header_field_names
;
242 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
243 struct bt_ctf_event_class
*event_class
= NULL
;
244 struct bt_ctf_stream_class
*stream_class
= NULL
;
245 struct bt_ctf_trace
*trace_class
= NULL
;
247 event_class
= bt_ctf_event_get_class(event
);
249 ret
= BT_COMPONENT_STATUS_ERROR
;
252 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
254 ret
= BT_COMPONENT_STATUS_ERROR
;
257 trace_class
= bt_ctf_stream_class_get_trace(stream_class
);
259 ret
= BT_COMPONENT_STATUS_ERROR
;
262 if (!text
->start_line
) {
263 fputs(", ", text
->out
);
265 text
->start_line
= false;
266 ret
= print_event_timestamp(text
, event
, &text
->start_line
);
267 if (ret
!= BT_COMPONENT_STATUS_OK
) {
270 if (text
->options
.print_trace_field
) {
273 name
= bt_ctf_trace_get_name(trace_class
);
275 if (!text
->start_line
) {
276 fputs(", ", text
->out
);
278 text
->start_line
= false;
280 fputs("trace = ", text
->out
);
282 fprintf(text
->out
, "%s", name
);
285 if (text
->options
.print_trace_hostname_field
) {
286 struct bt_value
*hostname_str
;
288 hostname_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
293 if (!text
->start_line
) {
294 fputs(", ", text
->out
);
296 text
->start_line
= false;
298 fputs("trace:hostname = ", text
->out
);
300 if (bt_value_string_get(hostname_str
, &str
)
301 == BT_VALUE_STATUS_OK
) {
302 fprintf(text
->out
, "%s", str
);
304 bt_put(hostname_str
);
307 if (text
->options
.print_trace_domain_field
) {
308 struct bt_value
*domain_str
;
310 domain_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
315 if (!text
->start_line
) {
316 fputs(", ", text
->out
);
318 text
->start_line
= false;
320 fputs("trace:domain = ", text
->out
);
322 if (bt_value_string_get(domain_str
, &str
)
323 == BT_VALUE_STATUS_OK
) {
324 fprintf(text
->out
, "%s", str
);
329 if (text
->options
.print_trace_procname_field
) {
330 struct bt_value
*procname_str
;
332 procname_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
337 if (!text
->start_line
) {
338 fputs(", ", text
->out
);
340 text
->start_line
= false;
342 fputs("trace:procname = ", text
->out
);
344 if (bt_value_string_get(procname_str
, &str
)
345 == BT_VALUE_STATUS_OK
) {
346 fprintf(text
->out
, "%s", str
);
348 bt_put(procname_str
);
351 if (text
->options
.print_trace_vpid_field
) {
352 struct bt_value
*vpid_value
;
354 vpid_value
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
359 if (!text
->start_line
) {
360 fputs(", ", text
->out
);
362 text
->start_line
= false;
364 fputs("trace:vpid = ", text
->out
);
366 if (bt_value_integer_get(vpid_value
, &value
)
367 == BT_VALUE_STATUS_OK
) {
368 fprintf(text
->out
, "(%" PRId64
")", value
);
373 if (text
->options
.print_loglevel_field
) {
374 struct bt_value
*loglevel_str
, *loglevel_value
;
376 loglevel_str
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
378 loglevel_value
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
380 if (loglevel_str
|| loglevel_value
) {
381 bool has_str
= false;
383 if (!text
->start_line
) {
384 fputs(", ", text
->out
);
386 text
->start_line
= false;
388 fputs("loglevel = ", text
->out
);
393 if (bt_value_string_get(loglevel_str
, &str
)
394 == BT_VALUE_STATUS_OK
) {
395 fprintf(text
->out
, "%s", str
);
399 if (loglevel_value
) {
402 if (bt_value_integer_get(loglevel_value
, &value
)
403 == BT_VALUE_STATUS_OK
) {
404 fprintf(text
->out
, "%s(%" PRId64
")",
405 has_str
? " " : "", value
);
408 bt_put(loglevel_str
);
409 bt_put(loglevel_value
);
412 if (text
->options
.print_emf_field
) {
413 struct bt_value
*uri_str
;
415 uri_str
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
418 if (!text
->start_line
) {
419 fputs(", ", text
->out
);
421 text
->start_line
= false;
423 fputs("model.emf.uri = ", text
->out
);
428 if (bt_value_string_get(uri_str
, &str
)
429 == BT_VALUE_STATUS_OK
) {
430 fprintf(text
->out
, "%s", str
);
436 if (!text
->start_line
) {
437 fputs(", ", text
->out
);
439 text
->start_line
= false;
441 fputs("name = ", text
->out
);
443 fputs(bt_ctf_event_class_get_name(event_class
), text
->out
);
446 bt_put(stream_class
);
452 enum bt_component_status
print_integer(struct text_component
*text
,
453 struct bt_ctf_field
*field
)
455 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
456 struct bt_ctf_field_type
*field_type
= NULL
;
457 enum bt_ctf_integer_base base
;
458 enum bt_ctf_string_encoding encoding
;
465 field_type
= bt_ctf_field_get_type(field
);
467 ret
= BT_COMPONENT_STATUS_ERROR
;
470 signedness
= bt_ctf_field_type_integer_get_signed(field_type
);
471 if (signedness
< 0) {
472 ret
= BT_COMPONENT_STATUS_ERROR
;
476 if (bt_ctf_field_unsigned_integer_get_value(field
, &v
.u
) < 0) {
477 ret
= BT_COMPONENT_STATUS_ERROR
;
481 if (bt_ctf_field_signed_integer_get_value(field
, &v
.s
) < 0) {
482 ret
= BT_COMPONENT_STATUS_ERROR
;
487 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
489 case BT_CTF_STRING_ENCODING_UTF8
:
490 case BT_CTF_STRING_ENCODING_ASCII
:
491 g_string_append_c(text
->string
, (int) v
.u
);
493 case BT_CTF_STRING_ENCODING_NONE
:
494 case BT_CTF_STRING_ENCODING_UNKNOWN
:
497 ret
= BT_COMPONENT_STATUS_ERROR
;
501 base
= bt_ctf_field_type_integer_get_base(field_type
);
503 case BT_CTF_INTEGER_BASE_BINARY
:
507 len
= bt_ctf_field_type_integer_get_size(field_type
);
509 ret
= BT_COMPONENT_STATUS_ERROR
;
512 fprintf(text
->out
, "0b");
513 v
.u
= _bt_piecewise_lshift(v
.u
, 64 - len
);
514 for (bitnr
= 0; bitnr
< len
; bitnr
++) {
515 fprintf(text
->out
, "%u", (v
.u
& (1ULL << 63)) ? 1 : 0);
516 v
.u
= _bt_piecewise_lshift(v
.u
, 1);
520 case BT_CTF_INTEGER_BASE_OCTAL
:
525 len
= bt_ctf_field_type_integer_get_size(field_type
);
527 ret
= BT_COMPONENT_STATUS_ERROR
;
534 /* Round length to the nearest 3-bit */
535 rounded_len
= (((len
- 1) / 3) + 1) * 3;
536 v
.u
&= ((uint64_t) 1 << rounded_len
) - 1;
540 fprintf(text
->out
, "0%" PRIo64
, v
.u
);
543 case BT_CTF_INTEGER_BASE_DECIMAL
:
545 fprintf(text
->out
, "%" PRIu64
, v
.u
);
547 fprintf(text
->out
, "%" PRId64
, v
.s
);
550 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
554 len
= bt_ctf_field_type_integer_get_size(field_type
);
556 ret
= BT_COMPONENT_STATUS_ERROR
;
560 /* Round length to the nearest nibble */
561 uint8_t rounded_len
= ((len
+ 3) & ~0x3);
563 v
.u
&= ((uint64_t) 1 << rounded_len
) - 1;
566 fprintf(text
->out
, "0x%" PRIX64
, v
.u
);
570 ret
= BT_COMPONENT_STATUS_ERROR
;
579 enum bt_component_status
print_enum(struct text_component
*text
,
580 struct bt_ctf_field
*field
)
582 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
583 struct bt_ctf_field
*container_field
= NULL
;
584 const char *mapping_name
;
586 container_field
= bt_ctf_field_enumeration_get_container(field
);
587 if (!container_field
) {
588 ret
= BT_COMPONENT_STATUS_ERROR
;
591 mapping_name
= bt_ctf_field_enumeration_get_mapping_name(field
);
593 fprintf(text
->out
, "( \"%s\"", mapping_name
);
595 fprintf(text
->out
, "( <unknown>");
597 fprintf(text
->out
, " : container = ");
598 ret
= print_integer(text
, container_field
);
599 if (ret
!= BT_COMPONENT_STATUS_OK
) {
602 fprintf(text
->out
, " )");
604 bt_put(container_field
);
609 enum bt_component_status
print_struct_field(struct text_component
*text
,
610 struct bt_ctf_field
*_struct
,
611 struct bt_ctf_field_type
*struct_type
,
612 int i
, bool print_names
)
614 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
615 const char *field_name
;
616 struct bt_ctf_field
*field
= NULL
;
617 struct bt_ctf_field_type
*field_type
= NULL
;;
619 field
= bt_ctf_field_structure_get_field_by_index(_struct
, i
);
621 ret
= BT_COMPONENT_STATUS_ERROR
;
624 if (bt_ctf_field_type_structure_get_field(struct_type
,
625 &field_name
, &field_type
, i
) < 0) {
626 ret
= BT_COMPONENT_STATUS_ERROR
;
631 fprintf(text
->out
, ", ");
633 fprintf(text
->out
, " ");
636 fprintf(text
->out
, "%s = ", rem_(field_name
));
638 ret
= print_field(text
, field
, print_names
);
646 enum bt_component_status
print_struct(struct text_component
*text
,
647 struct bt_ctf_field
*_struct
, bool print_names
)
649 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
650 struct bt_ctf_field_type
*struct_type
= NULL
;
653 struct_type
= bt_ctf_field_get_type(_struct
);
655 ret
= BT_COMPONENT_STATUS_ERROR
;
658 nr_fields
= bt_ctf_field_type_structure_get_field_count(struct_type
);
660 ret
= BT_COMPONENT_STATUS_ERROR
;
663 fprintf(text
->out
, "{");
665 for (i
= 0; i
< nr_fields
; i
++) {
666 ret
= print_struct_field(text
, _struct
, struct_type
, i
,
668 if (ret
!= BT_COMPONENT_STATUS_OK
) {
673 fprintf(text
->out
, " }");
680 enum bt_component_status
print_array_field(struct text_component
*text
,
681 struct bt_ctf_field
*array
, uint64_t i
,
682 bool is_string
, bool print_names
)
684 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
685 struct bt_ctf_field
*field
= NULL
;
689 fprintf(text
->out
, ", ");
691 fprintf(text
->out
, " ");
694 field
= bt_ctf_field_array_get_field(array
, i
);
696 ret
= BT_COMPONENT_STATUS_ERROR
;
699 ret
= print_field(text
, field
, print_names
);
706 enum bt_component_status
print_array(struct text_component
*text
,
707 struct bt_ctf_field
*array
, bool print_names
)
709 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
710 struct bt_ctf_field_type
*array_type
= NULL
, *field_type
= NULL
;
711 enum bt_ctf_type_id type_id
;
714 bool is_string
= false;
716 array_type
= bt_ctf_field_get_type(array
);
718 ret
= BT_COMPONENT_STATUS_ERROR
;
721 field_type
= bt_ctf_field_type_array_get_element_type(array_type
);
723 ret
= BT_COMPONENT_STATUS_ERROR
;
726 len
= bt_ctf_field_type_array_get_length(array_type
);
728 ret
= BT_COMPONENT_STATUS_ERROR
;
731 type_id
= bt_ctf_field_type_get_type_id(field_type
);
732 if (type_id
== BT_CTF_TYPE_ID_INTEGER
) {
733 enum bt_ctf_string_encoding encoding
;
735 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
736 if (encoding
== BT_CTF_STRING_ENCODING_UTF8
737 || encoding
== BT_CTF_STRING_ENCODING_ASCII
) {
738 int integer_len
, integer_alignment
;
740 integer_len
= bt_ctf_field_type_integer_get_size(field_type
);
741 if (integer_len
< 0) {
742 return BT_COMPONENT_STATUS_ERROR
;
744 integer_alignment
= bt_ctf_field_type_get_alignment(field_type
);
745 if (integer_alignment
< 0) {
746 return BT_COMPONENT_STATUS_ERROR
;
748 if (integer_len
== CHAR_BIT
749 && integer_alignment
== CHAR_BIT
) {
756 g_string_assign(text
->string
, "");
758 fprintf(text
->out
, "[");
762 for (i
= 0; i
< len
; i
++) {
763 ret
= print_array_field(text
, array
, i
, is_string
, print_names
);
764 if (ret
!= BT_COMPONENT_STATUS_OK
) {
771 fprintf(text
->out
, "\"%s\"", text
->string
->str
);
773 fprintf(text
->out
, " ]");
782 enum bt_component_status
print_sequence_field(struct text_component
*text
,
783 struct bt_ctf_field
*seq
, uint64_t i
,
784 bool is_string
, bool print_names
)
786 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
787 struct bt_ctf_field
*field
= NULL
;
791 fprintf(text
->out
, ", ");
793 fprintf(text
->out
, " ");
796 field
= bt_ctf_field_sequence_get_field(seq
, i
);
798 ret
= BT_COMPONENT_STATUS_ERROR
;
801 ret
= print_field(text
, field
, print_names
);
808 enum bt_component_status
print_sequence(struct text_component
*text
,
809 struct bt_ctf_field
*seq
, bool print_names
)
811 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
812 struct bt_ctf_field_type
*seq_type
= NULL
, *field_type
= NULL
;
813 struct bt_ctf_field
*length_field
= NULL
;
814 enum bt_ctf_type_id type_id
;
817 bool is_string
= false;
819 seq_type
= bt_ctf_field_get_type(seq
);
821 ret
= BT_COMPONENT_STATUS_ERROR
;
824 length_field
= bt_ctf_field_sequence_get_length(seq
);
826 ret
= BT_COMPONENT_STATUS_ERROR
;
829 if (bt_ctf_field_unsigned_integer_get_value(length_field
, &len
) < 0) {
830 ret
= BT_COMPONENT_STATUS_ERROR
;
833 field_type
= bt_ctf_field_type_sequence_get_element_type(seq_type
);
835 ret
= BT_COMPONENT_STATUS_ERROR
;
838 type_id
= bt_ctf_field_type_get_type_id(field_type
);
839 if (type_id
== BT_CTF_TYPE_ID_INTEGER
) {
840 enum bt_ctf_string_encoding encoding
;
842 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
843 if (encoding
== BT_CTF_STRING_ENCODING_UTF8
844 || encoding
== BT_CTF_STRING_ENCODING_ASCII
) {
845 int integer_len
, integer_alignment
;
847 integer_len
= bt_ctf_field_type_integer_get_size(field_type
);
848 if (integer_len
< 0) {
849 ret
= BT_COMPONENT_STATUS_ERROR
;
852 integer_alignment
= bt_ctf_field_type_get_alignment(field_type
);
853 if (integer_alignment
< 0) {
854 ret
= BT_COMPONENT_STATUS_ERROR
;
857 if (integer_len
== CHAR_BIT
858 && integer_alignment
== CHAR_BIT
) {
865 g_string_assign(text
->string
, "");
867 fprintf(text
->out
, "[");
871 for (i
= 0; i
< len
; i
++) {
872 ret
= print_sequence_field(text
, seq
, i
,
873 is_string
, print_names
);
874 if (ret
!= BT_COMPONENT_STATUS_OK
) {
881 fprintf(text
->out
, "\"%s\"", text
->string
->str
);
883 fprintf(text
->out
, " ]");
886 bt_put(length_field
);
893 enum bt_component_status
print_variant(struct text_component
*text
,
894 struct bt_ctf_field
*variant
, bool print_names
)
896 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
897 struct bt_ctf_field
*field
= NULL
;
899 field
= bt_ctf_field_variant_get_current_field(variant
);
901 ret
= BT_COMPONENT_STATUS_ERROR
;
904 fprintf(text
->out
, "{ ");
907 struct bt_ctf_field
*tag_field
= NULL
;
908 const char *tag_choice
;
910 tag_field
= bt_ctf_field_variant_get_tag(variant
);
912 ret
= BT_COMPONENT_STATUS_ERROR
;
915 tag_choice
= bt_ctf_field_enumeration_get_mapping_name(tag_field
);
918 ret
= BT_COMPONENT_STATUS_ERROR
;
921 fprintf(text
->out
, "%s = ", rem_(tag_choice
));
924 ret
= print_field(text
, field
, print_names
);
925 if (ret
!= BT_COMPONENT_STATUS_OK
) {
929 fprintf(text
->out
, " }");
936 enum bt_component_status
print_field(struct text_component
*text
,
937 struct bt_ctf_field
*field
, bool print_names
)
939 enum bt_ctf_type_id type_id
;
941 type_id
= bt_ctf_field_get_type_id(field
);
943 case CTF_TYPE_INTEGER
:
944 return print_integer(text
, field
);
949 if (bt_ctf_field_floating_point_get_value(field
, &v
)) {
950 return BT_COMPONENT_STATUS_ERROR
;
952 fprintf(text
->out
, "%g", v
);
953 return BT_COMPONENT_STATUS_OK
;
956 return print_enum(text
, field
);
957 case CTF_TYPE_STRING
:
958 fprintf(text
->out
, "\"%s\"", bt_ctf_field_string_get_value(field
));
959 return BT_COMPONENT_STATUS_OK
;
960 case CTF_TYPE_STRUCT
:
961 return print_struct(text
, field
, print_names
);
962 case CTF_TYPE_UNTAGGED_VARIANT
:
963 case CTF_TYPE_VARIANT
:
964 return print_variant(text
, field
, print_names
);
966 return print_array(text
, field
, print_names
);
967 case CTF_TYPE_SEQUENCE
:
968 return print_sequence(text
, field
, print_names
);
970 fprintf(text
->err
, "[error] Unknown type id: %d\n", (int) type_id
);
971 return BT_COMPONENT_STATUS_ERROR
;
976 enum bt_component_status
print_stream_packet_context(struct text_component
*text
,
977 struct bt_ctf_event
*event
)
979 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
980 struct bt_ctf_packet
*packet
= NULL
;
981 struct bt_ctf_field
*main_field
= NULL
;
983 packet
= bt_ctf_event_get_packet(event
);
985 ret
= BT_COMPONENT_STATUS_ERROR
;
988 main_field
= bt_ctf_packet_get_context(packet
);
990 ret
= BT_COMPONENT_STATUS_ERROR
;
993 if (!text
->start_line
) {
994 fputs(", ", text
->out
);
996 text
->start_line
= false;
997 if (text
->options
.print_scope_field_names
) {
998 fputs("stream.packet.context = ", text
->out
);
1000 ret
= print_field(text
, main_field
,
1001 text
->options
.print_context_field_names
);
1009 enum bt_component_status
print_event_header_raw(struct text_component
*text
,
1010 struct bt_ctf_event
*event
)
1012 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1013 struct bt_ctf_field
*main_field
= NULL
;
1015 main_field
= bt_ctf_event_get_header(event
);
1017 ret
= BT_COMPONENT_STATUS_ERROR
;
1020 if (!text
->start_line
) {
1021 fputs(", ", text
->out
);
1023 text
->start_line
= false;
1024 if (text
->options
.print_scope_field_names
) {
1025 fputs("stream.event.header = ", text
->out
);
1027 ret
= print_field(text
, main_field
,
1028 text
->options
.print_header_field_names
);
1035 enum bt_component_status
print_stream_event_context(struct text_component
*text
,
1036 struct bt_ctf_event
*event
)
1038 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1039 struct bt_ctf_field
*main_field
= NULL
;
1041 main_field
= bt_ctf_event_get_stream_event_context(event
);
1043 ret
= BT_COMPONENT_STATUS_ERROR
;
1046 if (!text
->start_line
) {
1047 fputs(", ", text
->out
);
1049 text
->start_line
= false;
1050 if (text
->options
.print_scope_field_names
) {
1051 fputs("stream.event.context = ", text
->out
);
1053 ret
= print_field(text
, main_field
,
1054 text
->options
.print_context_field_names
);
1061 enum bt_component_status
print_event_context(struct text_component
*text
,
1062 struct bt_ctf_event
*event
)
1064 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1065 struct bt_ctf_field
*main_field
= NULL
;
1067 main_field
= bt_ctf_event_get_event_context(event
);
1069 ret
= BT_COMPONENT_STATUS_ERROR
;
1072 if (!text
->start_line
) {
1073 fputs(", ", text
->out
);
1075 text
->start_line
= false;
1076 if (text
->options
.print_scope_field_names
) {
1077 fputs("event.context = ", text
->out
);
1079 ret
= print_field(text
, main_field
,
1080 text
->options
.print_context_field_names
);
1087 enum bt_component_status
print_event_payload(struct text_component
*text
,
1088 struct bt_ctf_event
*event
)
1090 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1091 struct bt_ctf_field
*main_field
= NULL
;
1093 main_field
= bt_ctf_event_get_payload_field(event
);
1095 ret
= BT_COMPONENT_STATUS_ERROR
;
1098 if (!text
->start_line
) {
1099 fputs(", ", text
->out
);
1101 text
->start_line
= false;
1102 if (text
->options
.print_scope_field_names
) {
1103 fputs("event.fields = ", text
->out
);
1105 ret
= print_field(text
, main_field
,
1106 text
->options
.print_payload_field_names
);
1113 enum bt_component_status
text_print_event(struct text_component
*text
,
1114 struct bt_ctf_event
*event
)
1116 enum bt_component_status ret
;
1118 text
->start_line
= true;
1119 ret
= print_event_header(text
, event
);
1120 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1124 ret
= print_stream_packet_context(text
, event
);
1125 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1129 ret
= print_event_header_raw(text
, event
);
1130 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1134 ret
= print_stream_event_context(text
, event
);
1135 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1139 ret
= print_event_context(text
, event
);
1140 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1144 ret
= print_event_payload(text
, event
);
1145 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1149 fputc('\n', text
->out
);