4 * Babeltrace CTF Text Output Plugin Event Printing
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
30 #include <babeltrace/ctf-ir/event.h>
31 #include <babeltrace/ctf-ir/event-class.h>
32 #include <babeltrace/ctf-ir/packet.h>
33 #include <babeltrace/ctf-ir/stream.h>
34 #include <babeltrace/ctf-ir/stream-class.h>
35 #include <babeltrace/ctf-ir/clock.h>
36 #include <babeltrace/ctf-ir/field-types.h>
37 #include <babeltrace/ctf-ir/fields.h>
38 #include <babeltrace/ctf-ir/trace.h>
39 #include <babeltrace/bitfield.h>
43 #define NSEC_PER_SEC 1000000000LL
46 const char *rem_(const char *str
)
55 int64_t real_timestamp
; /* Relative to UNIX epoch. */
56 uint64_t clock_value
; /* In cycles. */
60 enum bt_component_status
print_field(struct text_component
*text
,
61 struct bt_ctf_field
*field
, bool print_names
);
64 void print_timestamp_cycles(struct text_component
*text
,
65 struct bt_ctf_clock
*clock
,
66 struct bt_ctf_event
*event
)
69 struct bt_ctf_clock_value
*clock_value
;
72 clock_value
= bt_ctf_event_get_clock_value(event
, clock
);
74 fputs("????????????????????", text
->out
);
78 ret
= bt_ctf_clock_value_get_value(clock_value
, &cycles
);
81 fprintf(text
->out
, "Error");
84 fprintf(text
->out
, "%020" PRIu64
, cycles
);
88 void print_timestamp_wall(struct text_component
*text
,
89 struct bt_ctf_clock
*clock
,
90 struct bt_ctf_event
*event
)
93 struct bt_ctf_clock_value
*clock_value
;
94 int64_t ts_nsec
= 0; /* add configurable offset */
95 int64_t ts_sec
= 0; /* add configurable offset */
96 uint64_t ts_sec_abs
, ts_nsec_abs
;
99 clock_value
= bt_ctf_event_get_clock_value(event
, clock
);
101 fputs("??:??:??.?????????", text
->out
);
105 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(clock_value
, &ts_nsec
);
108 fprintf(text
->out
, "Error");
112 ts_sec
+= ts_nsec
/ NSEC_PER_SEC
;
113 ts_nsec
= ts_nsec
% NSEC_PER_SEC
;
114 if (ts_sec
>= 0 && ts_nsec
>= 0) {
117 ts_nsec_abs
= ts_nsec
;
118 } else if (ts_sec
> 0 && ts_nsec
< 0) {
120 ts_sec_abs
= ts_sec
- 1;
121 ts_nsec_abs
= NSEC_PER_SEC
+ ts_nsec
;
122 } else if (ts_sec
== 0 && ts_nsec
< 0) {
125 ts_nsec_abs
= -ts_nsec
;
126 } else if (ts_sec
< 0 && ts_nsec
> 0) {
128 ts_sec_abs
= -(ts_sec
+ 1);
129 ts_nsec_abs
= NSEC_PER_SEC
- ts_nsec
;
130 } else if (ts_sec
< 0 && ts_nsec
== 0) {
132 ts_sec_abs
= -ts_sec
;
133 ts_nsec_abs
= ts_nsec
;
134 } else { /* (ts_sec < 0 && ts_nsec < 0) */
136 ts_sec_abs
= -ts_sec
;
137 ts_nsec_abs
= -ts_nsec
;
140 if (!text
->options
.clock_seconds
) {
142 time_t time_s
= (time_t) ts_sec_abs
;
145 fprintf(stderr
, "[warning] Fallback to [sec.ns] to print negative time value. Use --clock-seconds.\n");
149 if (!text
->options
.clock_gmt
) {
152 res
= localtime_r(&time_s
, &tm
);
154 fprintf(stderr
, "[warning] Unable to get localtime.\n");
160 res
= gmtime_r(&time_s
, &tm
);
162 fprintf(stderr
, "[warning] Unable to get gmtime.\n");
166 if (text
->options
.clock_date
) {
170 /* Print date and time */
171 res
= strftime(timestr
, sizeof(timestr
),
174 fprintf(stderr
, "[warning] Unable to print ascii time.\n");
177 fprintf(text
->out
, "%s", timestr
);
179 /* Print time in HH:MM:SS.ns */
180 fprintf(text
->out
, "%02d:%02d:%02d.%09" PRIu64
,
181 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
, ts_nsec_abs
);
185 fprintf(text
->out
, "%s%" PRId64
".%09" PRIu64
,
186 is_negative
? "-" : "", ts_sec_abs
, ts_nsec_abs
);
192 enum bt_component_status
print_event_timestamp(struct text_component
*text
,
193 struct bt_ctf_event
*event
, bool *start_line
)
195 bool print_names
= text
->options
.print_header_field_names
;
196 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
197 struct bt_ctf_stream
*stream
= NULL
;
198 struct bt_ctf_stream_class
*stream_class
= NULL
;
199 struct bt_ctf_trace
*trace
= NULL
;
200 struct bt_ctf_clock
*clock
= NULL
;
201 FILE *out
= text
->out
;
202 FILE *err
= text
->err
;
203 uint64_t real_timestamp
;
205 stream
= bt_ctf_event_get_stream(event
);
207 ret
= BT_COMPONENT_STATUS_ERROR
;
211 stream_class
= bt_ctf_stream_get_class(stream
);
213 ret
= BT_COMPONENT_STATUS_ERROR
;
216 trace
= bt_ctf_stream_class_get_trace(stream_class
);
218 ret
= BT_COMPONENT_STATUS_ERROR
;
221 clock
= bt_ctf_trace_get_clock(trace
, 0);
223 ret
= BT_COMPONENT_STATUS_ERROR
;
227 fputs(print_names
? "timestamp = " : "[", out
);
228 if (text
->options
.print_timestamp_cycles
) {
229 print_timestamp_cycles(text
, clock
, event
);
231 print_timestamp_wall(text
, clock
, event
);
236 *start_line
= !print_names
;
238 if (!text
->options
.print_delta_field
) {
247 bt_put(stream_class
);
253 enum bt_component_status
print_event_header(struct text_component
*text
,
254 struct bt_ctf_event
*event
)
256 bool print_names
= text
->options
.print_header_field_names
;
257 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
258 struct bt_ctf_event_class
*event_class
= NULL
;
259 struct bt_ctf_stream_class
*stream_class
= NULL
;
260 struct bt_ctf_trace
*trace_class
= NULL
;
262 event_class
= bt_ctf_event_get_class(event
);
264 ret
= BT_COMPONENT_STATUS_ERROR
;
267 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
269 ret
= BT_COMPONENT_STATUS_ERROR
;
272 trace_class
= bt_ctf_stream_class_get_trace(stream_class
);
274 ret
= BT_COMPONENT_STATUS_ERROR
;
277 if (!text
->start_line
) {
278 fputs(", ", text
->out
);
280 text
->start_line
= false;
281 ret
= print_event_timestamp(text
, event
, &text
->start_line
);
282 if (ret
!= BT_COMPONENT_STATUS_OK
) {
285 if (text
->options
.print_trace_field
) {
288 name
= bt_ctf_trace_get_name(trace_class
);
290 if (!text
->start_line
) {
291 fputs(", ", text
->out
);
293 text
->start_line
= false;
295 fputs("trace = ", text
->out
);
297 fprintf(text
->out
, "%s", name
);
300 if (text
->options
.print_trace_hostname_field
) {
301 struct bt_value
*hostname_str
;
303 hostname_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
308 if (!text
->start_line
) {
309 fputs(", ", text
->out
);
311 text
->start_line
= false;
313 fputs("trace:hostname = ", text
->out
);
315 if (bt_value_string_get(hostname_str
, &str
)
316 == BT_VALUE_STATUS_OK
) {
317 fprintf(text
->out
, "%s", str
);
319 bt_put(hostname_str
);
322 if (text
->options
.print_trace_domain_field
) {
323 struct bt_value
*domain_str
;
325 domain_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
330 if (!text
->start_line
) {
331 fputs(", ", text
->out
);
333 text
->start_line
= false;
335 fputs("trace:domain = ", text
->out
);
337 if (bt_value_string_get(domain_str
, &str
)
338 == BT_VALUE_STATUS_OK
) {
339 fprintf(text
->out
, "%s", str
);
344 if (text
->options
.print_trace_procname_field
) {
345 struct bt_value
*procname_str
;
347 procname_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
352 if (!text
->start_line
) {
353 fputs(", ", text
->out
);
355 text
->start_line
= false;
357 fputs("trace:procname = ", text
->out
);
359 if (bt_value_string_get(procname_str
, &str
)
360 == BT_VALUE_STATUS_OK
) {
361 fprintf(text
->out
, "%s", str
);
363 bt_put(procname_str
);
366 if (text
->options
.print_trace_vpid_field
) {
367 struct bt_value
*vpid_value
;
369 vpid_value
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
374 if (!text
->start_line
) {
375 fputs(", ", text
->out
);
377 text
->start_line
= false;
379 fputs("trace:vpid = ", text
->out
);
381 if (bt_value_integer_get(vpid_value
, &value
)
382 == BT_VALUE_STATUS_OK
) {
383 fprintf(text
->out
, "(%" PRId64
")", value
);
388 if (text
->options
.print_loglevel_field
) {
389 struct bt_value
*loglevel_str
, *loglevel_value
;
391 loglevel_str
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
393 loglevel_value
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
395 if (loglevel_str
|| loglevel_value
) {
396 bool has_str
= false;
398 if (!text
->start_line
) {
399 fputs(", ", text
->out
);
401 text
->start_line
= false;
403 fputs("loglevel = ", text
->out
);
408 if (bt_value_string_get(loglevel_str
, &str
)
409 == BT_VALUE_STATUS_OK
) {
410 fprintf(text
->out
, "%s", str
);
414 if (loglevel_value
) {
417 if (bt_value_integer_get(loglevel_value
, &value
)
418 == BT_VALUE_STATUS_OK
) {
419 fprintf(text
->out
, "%s(%" PRId64
")",
420 has_str
? " " : "", value
);
423 bt_put(loglevel_str
);
424 bt_put(loglevel_value
);
427 if (text
->options
.print_emf_field
) {
428 struct bt_value
*uri_str
;
430 uri_str
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
433 if (!text
->start_line
) {
434 fputs(", ", text
->out
);
436 text
->start_line
= false;
438 fputs("model.emf.uri = ", text
->out
);
443 if (bt_value_string_get(uri_str
, &str
)
444 == BT_VALUE_STATUS_OK
) {
445 fprintf(text
->out
, "%s", str
);
451 if (!text
->start_line
) {
452 fputs(", ", text
->out
);
454 text
->start_line
= false;
456 fputs("name = ", text
->out
);
458 fputs(bt_ctf_event_class_get_name(event_class
), text
->out
);
461 bt_put(stream_class
);
467 enum bt_component_status
print_integer(struct text_component
*text
,
468 struct bt_ctf_field
*field
)
470 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
471 struct bt_ctf_field_type
*field_type
= NULL
;
472 enum bt_ctf_integer_base base
;
473 enum bt_ctf_string_encoding encoding
;
480 field_type
= bt_ctf_field_get_type(field
);
482 ret
= BT_COMPONENT_STATUS_ERROR
;
485 signedness
= bt_ctf_field_type_integer_get_signed(field_type
);
486 if (signedness
< 0) {
487 ret
= BT_COMPONENT_STATUS_ERROR
;
491 if (bt_ctf_field_unsigned_integer_get_value(field
, &v
.u
) < 0) {
492 ret
= BT_COMPONENT_STATUS_ERROR
;
496 if (bt_ctf_field_signed_integer_get_value(field
, &v
.s
) < 0) {
497 ret
= BT_COMPONENT_STATUS_ERROR
;
502 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
504 case BT_CTF_STRING_ENCODING_UTF8
:
505 case BT_CTF_STRING_ENCODING_ASCII
:
506 g_string_append_c(text
->string
, (int) v
.u
);
508 case BT_CTF_STRING_ENCODING_NONE
:
509 case BT_CTF_STRING_ENCODING_UNKNOWN
:
512 ret
= BT_COMPONENT_STATUS_ERROR
;
516 base
= bt_ctf_field_type_integer_get_base(field_type
);
518 case BT_CTF_INTEGER_BASE_BINARY
:
522 len
= bt_ctf_field_type_integer_get_size(field_type
);
524 ret
= BT_COMPONENT_STATUS_ERROR
;
527 fprintf(text
->out
, "0b");
528 v
.u
= _bt_piecewise_lshift(v
.u
, 64 - len
);
529 for (bitnr
= 0; bitnr
< len
; bitnr
++) {
530 fprintf(text
->out
, "%u", (v
.u
& (1ULL << 63)) ? 1 : 0);
531 v
.u
= _bt_piecewise_lshift(v
.u
, 1);
535 case BT_CTF_INTEGER_BASE_OCTAL
:
540 len
= bt_ctf_field_type_integer_get_size(field_type
);
542 ret
= BT_COMPONENT_STATUS_ERROR
;
549 /* Round length to the nearest 3-bit */
550 rounded_len
= (((len
- 1) / 3) + 1) * 3;
551 v
.u
&= ((uint64_t) 1 << rounded_len
) - 1;
555 fprintf(text
->out
, "0%" PRIo64
, v
.u
);
558 case BT_CTF_INTEGER_BASE_DECIMAL
:
560 fprintf(text
->out
, "%" PRIu64
, v
.u
);
562 fprintf(text
->out
, "%" PRId64
, v
.s
);
565 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
569 len
= bt_ctf_field_type_integer_get_size(field_type
);
571 ret
= BT_COMPONENT_STATUS_ERROR
;
575 /* Round length to the nearest nibble */
576 uint8_t rounded_len
= ((len
+ 3) & ~0x3);
578 v
.u
&= ((uint64_t) 1 << rounded_len
) - 1;
581 fprintf(text
->out
, "0x%" PRIX64
, v
.u
);
585 ret
= BT_COMPONENT_STATUS_ERROR
;
594 enum bt_component_status
print_enum(struct text_component
*text
,
595 struct bt_ctf_field
*field
)
597 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
598 struct bt_ctf_field
*container_field
= NULL
;
599 const char *mapping_name
;
601 container_field
= bt_ctf_field_enumeration_get_container(field
);
602 if (!container_field
) {
603 ret
= BT_COMPONENT_STATUS_ERROR
;
606 mapping_name
= bt_ctf_field_enumeration_get_mapping_name(field
);
608 fprintf(text
->out
, "( \"%s\"", mapping_name
);
610 fprintf(text
->out
, "( <unknown>");
612 fprintf(text
->out
, " : container = ");
613 ret
= print_integer(text
, container_field
);
614 if (ret
!= BT_COMPONENT_STATUS_OK
) {
617 fprintf(text
->out
, " )");
619 bt_put(container_field
);
624 enum bt_component_status
print_struct_field(struct text_component
*text
,
625 struct bt_ctf_field
*_struct
,
626 struct bt_ctf_field_type
*struct_type
,
627 int i
, bool print_names
)
629 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
630 const char *field_name
;
631 struct bt_ctf_field
*field
= NULL
;
632 struct bt_ctf_field_type
*field_type
= NULL
;;
634 field
= bt_ctf_field_structure_get_field_by_index(_struct
, i
);
636 ret
= BT_COMPONENT_STATUS_ERROR
;
639 if (bt_ctf_field_type_structure_get_field(struct_type
,
640 &field_name
, &field_type
, i
) < 0) {
641 ret
= BT_COMPONENT_STATUS_ERROR
;
646 fprintf(text
->out
, ", ");
648 fprintf(text
->out
, " ");
651 fprintf(text
->out
, "%s = ", rem_(field_name
));
653 ret
= print_field(text
, field
, print_names
);
661 enum bt_component_status
print_struct(struct text_component
*text
,
662 struct bt_ctf_field
*_struct
, bool print_names
)
664 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
665 struct bt_ctf_field_type
*struct_type
= NULL
;
668 struct_type
= bt_ctf_field_get_type(_struct
);
670 ret
= BT_COMPONENT_STATUS_ERROR
;
673 nr_fields
= bt_ctf_field_type_structure_get_field_count(struct_type
);
675 ret
= BT_COMPONENT_STATUS_ERROR
;
678 fprintf(text
->out
, "{");
680 for (i
= 0; i
< nr_fields
; i
++) {
681 ret
= print_struct_field(text
, _struct
, struct_type
, i
,
683 if (ret
!= BT_COMPONENT_STATUS_OK
) {
688 fprintf(text
->out
, " }");
695 enum bt_component_status
print_array_field(struct text_component
*text
,
696 struct bt_ctf_field
*array
, uint64_t i
,
697 bool is_string
, bool print_names
)
699 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
700 struct bt_ctf_field
*field
= NULL
;
704 fprintf(text
->out
, ", ");
706 fprintf(text
->out
, " ");
709 field
= bt_ctf_field_array_get_field(array
, i
);
711 ret
= BT_COMPONENT_STATUS_ERROR
;
714 ret
= print_field(text
, field
, print_names
);
721 enum bt_component_status
print_array(struct text_component
*text
,
722 struct bt_ctf_field
*array
, bool print_names
)
724 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
725 struct bt_ctf_field_type
*array_type
= NULL
, *field_type
= NULL
;
726 enum bt_ctf_type_id type_id
;
729 bool is_string
= false;
731 array_type
= bt_ctf_field_get_type(array
);
733 ret
= BT_COMPONENT_STATUS_ERROR
;
736 field_type
= bt_ctf_field_type_array_get_element_type(array_type
);
738 ret
= BT_COMPONENT_STATUS_ERROR
;
741 len
= bt_ctf_field_type_array_get_length(array_type
);
743 ret
= BT_COMPONENT_STATUS_ERROR
;
746 type_id
= bt_ctf_field_type_get_type_id(field_type
);
747 if (type_id
== BT_CTF_TYPE_ID_INTEGER
) {
748 enum bt_ctf_string_encoding encoding
;
750 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
751 if (encoding
== BT_CTF_STRING_ENCODING_UTF8
752 || encoding
== BT_CTF_STRING_ENCODING_ASCII
) {
753 int integer_len
, integer_alignment
;
755 integer_len
= bt_ctf_field_type_integer_get_size(field_type
);
756 if (integer_len
< 0) {
757 return BT_COMPONENT_STATUS_ERROR
;
759 integer_alignment
= bt_ctf_field_type_get_alignment(field_type
);
760 if (integer_alignment
< 0) {
761 return BT_COMPONENT_STATUS_ERROR
;
763 if (integer_len
== CHAR_BIT
764 && integer_alignment
== CHAR_BIT
) {
771 g_string_assign(text
->string
, "");
773 fprintf(text
->out
, "[");
777 for (i
= 0; i
< len
; i
++) {
778 ret
= print_array_field(text
, array
, i
, is_string
, print_names
);
779 if (ret
!= BT_COMPONENT_STATUS_OK
) {
786 fprintf(text
->out
, "\"%s\"", text
->string
->str
);
788 fprintf(text
->out
, " ]");
797 enum bt_component_status
print_sequence_field(struct text_component
*text
,
798 struct bt_ctf_field
*seq
, uint64_t i
,
799 bool is_string
, bool print_names
)
801 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
802 struct bt_ctf_field
*field
= NULL
;
806 fprintf(text
->out
, ", ");
808 fprintf(text
->out
, " ");
811 field
= bt_ctf_field_sequence_get_field(seq
, i
);
813 ret
= BT_COMPONENT_STATUS_ERROR
;
816 ret
= print_field(text
, field
, print_names
);
823 enum bt_component_status
print_sequence(struct text_component
*text
,
824 struct bt_ctf_field
*seq
, bool print_names
)
826 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
827 struct bt_ctf_field_type
*seq_type
= NULL
, *field_type
= NULL
;
828 struct bt_ctf_field
*length_field
= NULL
;
829 enum bt_ctf_type_id type_id
;
832 bool is_string
= false;
834 seq_type
= bt_ctf_field_get_type(seq
);
836 ret
= BT_COMPONENT_STATUS_ERROR
;
839 length_field
= bt_ctf_field_sequence_get_length(seq
);
841 ret
= BT_COMPONENT_STATUS_ERROR
;
844 if (bt_ctf_field_unsigned_integer_get_value(length_field
, &len
) < 0) {
845 ret
= BT_COMPONENT_STATUS_ERROR
;
848 field_type
= bt_ctf_field_type_sequence_get_element_type(seq_type
);
850 ret
= BT_COMPONENT_STATUS_ERROR
;
853 type_id
= bt_ctf_field_type_get_type_id(field_type
);
854 if (type_id
== BT_CTF_TYPE_ID_INTEGER
) {
855 enum bt_ctf_string_encoding encoding
;
857 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
858 if (encoding
== BT_CTF_STRING_ENCODING_UTF8
859 || encoding
== BT_CTF_STRING_ENCODING_ASCII
) {
860 int integer_len
, integer_alignment
;
862 integer_len
= bt_ctf_field_type_integer_get_size(field_type
);
863 if (integer_len
< 0) {
864 ret
= BT_COMPONENT_STATUS_ERROR
;
867 integer_alignment
= bt_ctf_field_type_get_alignment(field_type
);
868 if (integer_alignment
< 0) {
869 ret
= BT_COMPONENT_STATUS_ERROR
;
872 if (integer_len
== CHAR_BIT
873 && integer_alignment
== CHAR_BIT
) {
880 g_string_assign(text
->string
, "");
882 fprintf(text
->out
, "[");
886 for (i
= 0; i
< len
; i
++) {
887 ret
= print_sequence_field(text
, seq
, i
,
888 is_string
, print_names
);
889 if (ret
!= BT_COMPONENT_STATUS_OK
) {
896 fprintf(text
->out
, "\"%s\"", text
->string
->str
);
898 fprintf(text
->out
, " ]");
901 bt_put(length_field
);
908 enum bt_component_status
print_variant(struct text_component
*text
,
909 struct bt_ctf_field
*variant
, bool print_names
)
911 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
912 struct bt_ctf_field
*field
= NULL
;
914 field
= bt_ctf_field_variant_get_current_field(variant
);
916 ret
= BT_COMPONENT_STATUS_ERROR
;
919 fprintf(text
->out
, "{ ");
922 struct bt_ctf_field
*tag_field
= NULL
;
923 const char *tag_choice
;
925 tag_field
= bt_ctf_field_variant_get_tag(variant
);
927 ret
= BT_COMPONENT_STATUS_ERROR
;
930 tag_choice
= bt_ctf_field_enumeration_get_mapping_name(tag_field
);
933 ret
= BT_COMPONENT_STATUS_ERROR
;
936 fprintf(text
->out
, "%s = ", rem_(tag_choice
));
939 ret
= print_field(text
, field
, print_names
);
940 if (ret
!= BT_COMPONENT_STATUS_OK
) {
944 fprintf(text
->out
, " }");
951 enum bt_component_status
print_field(struct text_component
*text
,
952 struct bt_ctf_field
*field
, bool print_names
)
954 enum bt_ctf_type_id type_id
;
956 type_id
= bt_ctf_field_get_type_id(field
);
958 case CTF_TYPE_INTEGER
:
959 return print_integer(text
, field
);
964 if (bt_ctf_field_floating_point_get_value(field
, &v
)) {
965 return BT_COMPONENT_STATUS_ERROR
;
967 fprintf(text
->out
, "%g", v
);
968 return BT_COMPONENT_STATUS_OK
;
971 return print_enum(text
, field
);
972 case CTF_TYPE_STRING
:
973 fprintf(text
->out
, "\"%s\"", bt_ctf_field_string_get_value(field
));
974 return BT_COMPONENT_STATUS_OK
;
975 case CTF_TYPE_STRUCT
:
976 return print_struct(text
, field
, print_names
);
977 case CTF_TYPE_UNTAGGED_VARIANT
:
978 case CTF_TYPE_VARIANT
:
979 return print_variant(text
, field
, print_names
);
981 return print_array(text
, field
, print_names
);
982 case CTF_TYPE_SEQUENCE
:
983 return print_sequence(text
, field
, print_names
);
985 fprintf(text
->err
, "[error] Unknown type id: %d\n", (int) type_id
);
986 return BT_COMPONENT_STATUS_ERROR
;
991 enum bt_component_status
print_stream_packet_context(struct text_component
*text
,
992 struct bt_ctf_event
*event
)
994 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
995 struct bt_ctf_packet
*packet
= NULL
;
996 struct bt_ctf_field
*main_field
= NULL
;
998 packet
= bt_ctf_event_get_packet(event
);
1000 ret
= BT_COMPONENT_STATUS_ERROR
;
1003 main_field
= bt_ctf_packet_get_context(packet
);
1005 ret
= BT_COMPONENT_STATUS_ERROR
;
1008 if (!text
->start_line
) {
1009 fputs(", ", text
->out
);
1011 text
->start_line
= false;
1012 if (text
->options
.print_scope_field_names
) {
1013 fputs("stream.packet.context = ", text
->out
);
1015 ret
= print_field(text
, main_field
,
1016 text
->options
.print_context_field_names
);
1024 enum bt_component_status
print_event_header_raw(struct text_component
*text
,
1025 struct bt_ctf_event
*event
)
1027 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1028 struct bt_ctf_field
*main_field
= NULL
;
1030 main_field
= bt_ctf_event_get_header(event
);
1032 ret
= BT_COMPONENT_STATUS_ERROR
;
1035 if (!text
->start_line
) {
1036 fputs(", ", text
->out
);
1038 text
->start_line
= false;
1039 if (text
->options
.print_scope_field_names
) {
1040 fputs("stream.event.header = ", text
->out
);
1042 ret
= print_field(text
, main_field
,
1043 text
->options
.print_header_field_names
);
1050 enum bt_component_status
print_stream_event_context(struct text_component
*text
,
1051 struct bt_ctf_event
*event
)
1053 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1054 struct bt_ctf_field
*main_field
= NULL
;
1056 main_field
= bt_ctf_event_get_stream_event_context(event
);
1058 ret
= BT_COMPONENT_STATUS_ERROR
;
1061 if (!text
->start_line
) {
1062 fputs(", ", text
->out
);
1064 text
->start_line
= false;
1065 if (text
->options
.print_scope_field_names
) {
1066 fputs("stream.event.context = ", text
->out
);
1068 ret
= print_field(text
, main_field
,
1069 text
->options
.print_context_field_names
);
1076 enum bt_component_status
print_event_context(struct text_component
*text
,
1077 struct bt_ctf_event
*event
)
1079 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1080 struct bt_ctf_field
*main_field
= NULL
;
1082 main_field
= bt_ctf_event_get_event_context(event
);
1084 ret
= BT_COMPONENT_STATUS_ERROR
;
1087 if (!text
->start_line
) {
1088 fputs(", ", text
->out
);
1090 text
->start_line
= false;
1091 if (text
->options
.print_scope_field_names
) {
1092 fputs("event.context = ", text
->out
);
1094 ret
= print_field(text
, main_field
,
1095 text
->options
.print_context_field_names
);
1102 enum bt_component_status
print_event_payload(struct text_component
*text
,
1103 struct bt_ctf_event
*event
)
1105 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1106 struct bt_ctf_field
*main_field
= NULL
;
1108 main_field
= bt_ctf_event_get_payload_field(event
);
1110 ret
= BT_COMPONENT_STATUS_ERROR
;
1113 if (!text
->start_line
) {
1114 fputs(", ", text
->out
);
1116 text
->start_line
= false;
1117 if (text
->options
.print_scope_field_names
) {
1118 fputs("event.fields = ", text
->out
);
1120 ret
= print_field(text
, main_field
,
1121 text
->options
.print_payload_field_names
);
1128 enum bt_component_status
text_print_event(struct text_component
*text
,
1129 struct bt_ctf_event
*event
)
1131 enum bt_component_status ret
;
1133 text
->start_line
= true;
1134 ret
= print_event_header(text
, event
);
1135 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1139 ret
= print_stream_packet_context(text
, event
);
1140 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1144 ret
= print_event_header_raw(text
, event
);
1145 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1149 ret
= print_stream_event_context(text
, event
);
1150 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1154 ret
= print_event_context(text
, event
);
1155 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1159 ret
= print_event_payload(text
, event
);
1160 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1164 fputc('\n', text
->out
);