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
);
86 if (text
->last_cycles_timestamp
!= -1ULL) {
87 text
->delta_cycles
= cycles
- text
->last_cycles_timestamp
;
89 text
->last_cycles_timestamp
= cycles
;
93 void print_timestamp_wall(struct text_component
*text
,
94 struct bt_ctf_clock
*clock
,
95 struct bt_ctf_event
*event
)
98 struct bt_ctf_clock_value
*clock_value
;
99 int64_t ts_nsec
= 0; /* add configurable offset */
100 int64_t ts_sec
= 0; /* add configurable offset */
101 uint64_t ts_sec_abs
, ts_nsec_abs
;
104 clock_value
= bt_ctf_event_get_clock_value(event
, clock
);
106 fputs("??:??:??.?????????", text
->out
);
110 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(clock_value
, &ts_nsec
);
113 fprintf(text
->out
, "Error");
117 if (text
->last_real_timestamp
!= -1ULL) {
118 text
->delta_real_timestamp
= ts_nsec
- text
->last_real_timestamp
;
120 text
->last_real_timestamp
= ts_nsec
;
122 ts_sec
+= ts_nsec
/ NSEC_PER_SEC
;
123 ts_nsec
= ts_nsec
% NSEC_PER_SEC
;
124 if (ts_sec
>= 0 && ts_nsec
>= 0) {
127 ts_nsec_abs
= ts_nsec
;
128 } else if (ts_sec
> 0 && ts_nsec
< 0) {
130 ts_sec_abs
= ts_sec
- 1;
131 ts_nsec_abs
= NSEC_PER_SEC
+ ts_nsec
;
132 } else if (ts_sec
== 0 && ts_nsec
< 0) {
135 ts_nsec_abs
= -ts_nsec
;
136 } else if (ts_sec
< 0 && ts_nsec
> 0) {
138 ts_sec_abs
= -(ts_sec
+ 1);
139 ts_nsec_abs
= NSEC_PER_SEC
- ts_nsec
;
140 } else if (ts_sec
< 0 && ts_nsec
== 0) {
142 ts_sec_abs
= -ts_sec
;
143 ts_nsec_abs
= ts_nsec
;
144 } else { /* (ts_sec < 0 && ts_nsec < 0) */
146 ts_sec_abs
= -ts_sec
;
147 ts_nsec_abs
= -ts_nsec
;
150 if (!text
->options
.clock_seconds
) {
152 time_t time_s
= (time_t) ts_sec_abs
;
155 fprintf(stderr
, "[warning] Fallback to [sec.ns] to print negative time value. Use --clock-seconds.\n");
159 if (!text
->options
.clock_gmt
) {
162 res
= localtime_r(&time_s
, &tm
);
164 fprintf(stderr
, "[warning] Unable to get localtime.\n");
170 res
= gmtime_r(&time_s
, &tm
);
172 fprintf(stderr
, "[warning] Unable to get gmtime.\n");
176 if (text
->options
.clock_date
) {
180 /* Print date and time */
181 res
= strftime(timestr
, sizeof(timestr
),
184 fprintf(stderr
, "[warning] Unable to print ascii time.\n");
187 fprintf(text
->out
, "%s", timestr
);
189 /* Print time in HH:MM:SS.ns */
190 fprintf(text
->out
, "%02d:%02d:%02d.%09" PRIu64
,
191 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
, ts_nsec_abs
);
195 fprintf(text
->out
, "%s%" PRId64
".%09" PRIu64
,
196 is_negative
? "-" : "", ts_sec_abs
, ts_nsec_abs
);
202 enum bt_component_status
print_event_timestamp(struct text_component
*text
,
203 struct bt_ctf_event
*event
, bool *start_line
)
205 bool print_names
= text
->options
.print_header_field_names
;
206 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
207 struct bt_ctf_stream
*stream
= NULL
;
208 struct bt_ctf_stream_class
*stream_class
= NULL
;
209 struct bt_ctf_trace
*trace
= NULL
;
210 struct bt_ctf_clock
*clock
= NULL
;
211 FILE *out
= text
->out
;
212 FILE *err
= text
->err
;
213 uint64_t real_timestamp
;
215 stream
= bt_ctf_event_get_stream(event
);
217 ret
= BT_COMPONENT_STATUS_ERROR
;
221 stream_class
= bt_ctf_stream_get_class(stream
);
223 ret
= BT_COMPONENT_STATUS_ERROR
;
226 trace
= bt_ctf_stream_class_get_trace(stream_class
);
228 ret
= BT_COMPONENT_STATUS_ERROR
;
231 clock
= bt_ctf_trace_get_clock(trace
, 0);
233 ret
= BT_COMPONENT_STATUS_ERROR
;
237 fputs(print_names
? "timestamp = " : "[", out
);
238 if (text
->options
.print_timestamp_cycles
) {
239 print_timestamp_cycles(text
, clock
, event
);
241 print_timestamp_wall(text
, clock
, event
);
247 if (text
->options
.print_delta_field
) {
249 fputs(", delta = ", text
->out
);
251 fputs("(", text
->out
);
252 if (text
->options
.print_timestamp_cycles
) {
253 if (text
->delta_cycles
== -1ULL) {
254 fputs("+??????????\?\?) ", text
->out
); /* Not a trigraph. */
256 fprintf(text
->out
, "+%012" PRIu64
, text
->delta_cycles
);
259 if (text
->delta_real_timestamp
!= -1ULL) {
260 uint64_t delta_sec
, delta_nsec
, delta
;
262 delta
= text
->delta_real_timestamp
;
263 delta_sec
= delta
/ NSEC_PER_SEC
;
264 delta_nsec
= delta
% NSEC_PER_SEC
;
265 fprintf(text
->out
, "+%" PRIu64
".%09" PRIu64
,
266 delta_sec
, delta_nsec
);
268 fputs("+?.?????????", text
->out
);
272 fputs(") ", text
->out
);
275 *start_line
= !print_names
;
280 bt_put(stream_class
);
286 enum bt_component_status
print_event_header(struct text_component
*text
,
287 struct bt_ctf_event
*event
)
289 bool print_names
= text
->options
.print_header_field_names
;
290 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
291 struct bt_ctf_event_class
*event_class
= NULL
;
292 struct bt_ctf_stream_class
*stream_class
= NULL
;
293 struct bt_ctf_trace
*trace_class
= NULL
;
295 event_class
= bt_ctf_event_get_class(event
);
297 ret
= BT_COMPONENT_STATUS_ERROR
;
300 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
302 ret
= BT_COMPONENT_STATUS_ERROR
;
305 trace_class
= bt_ctf_stream_class_get_trace(stream_class
);
307 ret
= BT_COMPONENT_STATUS_ERROR
;
310 if (!text
->start_line
) {
311 fputs(", ", text
->out
);
313 text
->start_line
= false;
314 ret
= print_event_timestamp(text
, event
, &text
->start_line
);
315 if (ret
!= BT_COMPONENT_STATUS_OK
) {
318 if (text
->options
.print_trace_field
) {
321 name
= bt_ctf_trace_get_name(trace_class
);
323 if (!text
->start_line
) {
324 fputs(", ", text
->out
);
326 text
->start_line
= false;
328 fputs("trace = ", text
->out
);
330 fprintf(text
->out
, "%s", name
);
333 if (text
->options
.print_trace_hostname_field
) {
334 struct bt_value
*hostname_str
;
336 hostname_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
341 if (!text
->start_line
) {
342 fputs(", ", text
->out
);
344 text
->start_line
= false;
346 fputs("trace:hostname = ", text
->out
);
348 if (bt_value_string_get(hostname_str
, &str
)
349 == BT_VALUE_STATUS_OK
) {
350 fprintf(text
->out
, "%s", str
);
352 bt_put(hostname_str
);
355 if (text
->options
.print_trace_domain_field
) {
356 struct bt_value
*domain_str
;
358 domain_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
363 if (!text
->start_line
) {
364 fputs(", ", text
->out
);
366 text
->start_line
= false;
368 fputs("trace:domain = ", text
->out
);
370 if (bt_value_string_get(domain_str
, &str
)
371 == BT_VALUE_STATUS_OK
) {
372 fprintf(text
->out
, "%s", str
);
377 if (text
->options
.print_trace_procname_field
) {
378 struct bt_value
*procname_str
;
380 procname_str
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
385 if (!text
->start_line
) {
386 fputs(", ", text
->out
);
388 text
->start_line
= false;
390 fputs("trace:procname = ", text
->out
);
392 if (bt_value_string_get(procname_str
, &str
)
393 == BT_VALUE_STATUS_OK
) {
394 fprintf(text
->out
, "%s", str
);
396 bt_put(procname_str
);
399 if (text
->options
.print_trace_vpid_field
) {
400 struct bt_value
*vpid_value
;
402 vpid_value
= bt_ctf_trace_get_environment_field_value_by_name(trace_class
,
407 if (!text
->start_line
) {
408 fputs(", ", text
->out
);
410 text
->start_line
= false;
412 fputs("trace:vpid = ", text
->out
);
414 if (bt_value_integer_get(vpid_value
, &value
)
415 == BT_VALUE_STATUS_OK
) {
416 fprintf(text
->out
, "(%" PRId64
")", value
);
421 if (text
->options
.print_loglevel_field
) {
422 struct bt_value
*loglevel_str
, *loglevel_value
;
424 loglevel_str
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
426 loglevel_value
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
428 if (loglevel_str
|| loglevel_value
) {
429 bool has_str
= false;
431 if (!text
->start_line
) {
432 fputs(", ", text
->out
);
434 text
->start_line
= false;
436 fputs("loglevel = ", text
->out
);
441 if (bt_value_string_get(loglevel_str
, &str
)
442 == BT_VALUE_STATUS_OK
) {
443 fprintf(text
->out
, "%s", str
);
447 if (loglevel_value
) {
450 if (bt_value_integer_get(loglevel_value
, &value
)
451 == BT_VALUE_STATUS_OK
) {
452 fprintf(text
->out
, "%s(%" PRId64
")",
453 has_str
? " " : "", value
);
456 bt_put(loglevel_str
);
457 bt_put(loglevel_value
);
460 if (text
->options
.print_emf_field
) {
461 struct bt_value
*uri_str
;
463 uri_str
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
466 if (!text
->start_line
) {
467 fputs(", ", text
->out
);
469 text
->start_line
= false;
471 fputs("model.emf.uri = ", text
->out
);
476 if (bt_value_string_get(uri_str
, &str
)
477 == BT_VALUE_STATUS_OK
) {
478 fprintf(text
->out
, "%s", str
);
484 if (!text
->start_line
) {
485 fputs(", ", text
->out
);
487 text
->start_line
= false;
489 fputs("name = ", text
->out
);
491 fputs(bt_ctf_event_class_get_name(event_class
), text
->out
);
494 bt_put(stream_class
);
500 enum bt_component_status
print_integer(struct text_component
*text
,
501 struct bt_ctf_field
*field
)
503 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
504 struct bt_ctf_field_type
*field_type
= NULL
;
505 enum bt_ctf_integer_base base
;
506 enum bt_ctf_string_encoding encoding
;
513 field_type
= bt_ctf_field_get_type(field
);
515 ret
= BT_COMPONENT_STATUS_ERROR
;
518 signedness
= bt_ctf_field_type_integer_get_signed(field_type
);
519 if (signedness
< 0) {
520 ret
= BT_COMPONENT_STATUS_ERROR
;
524 if (bt_ctf_field_unsigned_integer_get_value(field
, &v
.u
) < 0) {
525 ret
= BT_COMPONENT_STATUS_ERROR
;
529 if (bt_ctf_field_signed_integer_get_value(field
, &v
.s
) < 0) {
530 ret
= BT_COMPONENT_STATUS_ERROR
;
535 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
537 case BT_CTF_STRING_ENCODING_UTF8
:
538 case BT_CTF_STRING_ENCODING_ASCII
:
539 g_string_append_c(text
->string
, (int) v
.u
);
541 case BT_CTF_STRING_ENCODING_NONE
:
542 case BT_CTF_STRING_ENCODING_UNKNOWN
:
545 ret
= BT_COMPONENT_STATUS_ERROR
;
549 base
= bt_ctf_field_type_integer_get_base(field_type
);
551 case BT_CTF_INTEGER_BASE_BINARY
:
555 len
= bt_ctf_field_type_integer_get_size(field_type
);
557 ret
= BT_COMPONENT_STATUS_ERROR
;
560 fprintf(text
->out
, "0b");
561 v
.u
= _bt_piecewise_lshift(v
.u
, 64 - len
);
562 for (bitnr
= 0; bitnr
< len
; bitnr
++) {
563 fprintf(text
->out
, "%u", (v
.u
& (1ULL << 63)) ? 1 : 0);
564 v
.u
= _bt_piecewise_lshift(v
.u
, 1);
568 case BT_CTF_INTEGER_BASE_OCTAL
:
573 len
= bt_ctf_field_type_integer_get_size(field_type
);
575 ret
= BT_COMPONENT_STATUS_ERROR
;
582 /* Round length to the nearest 3-bit */
583 rounded_len
= (((len
- 1) / 3) + 1) * 3;
584 v
.u
&= ((uint64_t) 1 << rounded_len
) - 1;
588 fprintf(text
->out
, "0%" PRIo64
, v
.u
);
591 case BT_CTF_INTEGER_BASE_DECIMAL
:
593 fprintf(text
->out
, "%" PRIu64
, v
.u
);
595 fprintf(text
->out
, "%" PRId64
, v
.s
);
598 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
602 len
= bt_ctf_field_type_integer_get_size(field_type
);
604 ret
= BT_COMPONENT_STATUS_ERROR
;
608 /* Round length to the nearest nibble */
609 uint8_t rounded_len
= ((len
+ 3) & ~0x3);
611 v
.u
&= ((uint64_t) 1 << rounded_len
) - 1;
614 fprintf(text
->out
, "0x%" PRIX64
, v
.u
);
618 ret
= BT_COMPONENT_STATUS_ERROR
;
627 enum bt_component_status
print_enum(struct text_component
*text
,
628 struct bt_ctf_field
*field
)
630 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
631 struct bt_ctf_field
*container_field
= NULL
;
632 const char *mapping_name
;
634 container_field
= bt_ctf_field_enumeration_get_container(field
);
635 if (!container_field
) {
636 ret
= BT_COMPONENT_STATUS_ERROR
;
639 mapping_name
= bt_ctf_field_enumeration_get_mapping_name(field
);
641 fprintf(text
->out
, "( \"%s\"", mapping_name
);
643 fprintf(text
->out
, "( <unknown>");
645 fprintf(text
->out
, " : container = ");
646 ret
= print_integer(text
, container_field
);
647 if (ret
!= BT_COMPONENT_STATUS_OK
) {
650 fprintf(text
->out
, " )");
652 bt_put(container_field
);
657 enum bt_component_status
print_struct_field(struct text_component
*text
,
658 struct bt_ctf_field
*_struct
,
659 struct bt_ctf_field_type
*struct_type
,
660 int i
, bool print_names
)
662 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
663 const char *field_name
;
664 struct bt_ctf_field
*field
= NULL
;
665 struct bt_ctf_field_type
*field_type
= NULL
;;
667 field
= bt_ctf_field_structure_get_field_by_index(_struct
, i
);
669 ret
= BT_COMPONENT_STATUS_ERROR
;
672 if (bt_ctf_field_type_structure_get_field(struct_type
,
673 &field_name
, &field_type
, i
) < 0) {
674 ret
= BT_COMPONENT_STATUS_ERROR
;
679 fprintf(text
->out
, ", ");
681 fprintf(text
->out
, " ");
684 fprintf(text
->out
, "%s = ", rem_(field_name
));
686 ret
= print_field(text
, field
, print_names
);
694 enum bt_component_status
print_struct(struct text_component
*text
,
695 struct bt_ctf_field
*_struct
, bool print_names
)
697 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
698 struct bt_ctf_field_type
*struct_type
= NULL
;
701 struct_type
= bt_ctf_field_get_type(_struct
);
703 ret
= BT_COMPONENT_STATUS_ERROR
;
706 nr_fields
= bt_ctf_field_type_structure_get_field_count(struct_type
);
708 ret
= BT_COMPONENT_STATUS_ERROR
;
711 fprintf(text
->out
, "{");
713 for (i
= 0; i
< nr_fields
; i
++) {
714 ret
= print_struct_field(text
, _struct
, struct_type
, i
,
716 if (ret
!= BT_COMPONENT_STATUS_OK
) {
721 fprintf(text
->out
, " }");
728 enum bt_component_status
print_array_field(struct text_component
*text
,
729 struct bt_ctf_field
*array
, uint64_t i
,
730 bool is_string
, bool print_names
)
732 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
733 struct bt_ctf_field
*field
= NULL
;
737 fprintf(text
->out
, ", ");
739 fprintf(text
->out
, " ");
742 field
= bt_ctf_field_array_get_field(array
, i
);
744 ret
= BT_COMPONENT_STATUS_ERROR
;
747 ret
= print_field(text
, field
, print_names
);
754 enum bt_component_status
print_array(struct text_component
*text
,
755 struct bt_ctf_field
*array
, bool print_names
)
757 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
758 struct bt_ctf_field_type
*array_type
= NULL
, *field_type
= NULL
;
759 enum bt_ctf_type_id type_id
;
762 bool is_string
= false;
764 array_type
= bt_ctf_field_get_type(array
);
766 ret
= BT_COMPONENT_STATUS_ERROR
;
769 field_type
= bt_ctf_field_type_array_get_element_type(array_type
);
771 ret
= BT_COMPONENT_STATUS_ERROR
;
774 len
= bt_ctf_field_type_array_get_length(array_type
);
776 ret
= BT_COMPONENT_STATUS_ERROR
;
779 type_id
= bt_ctf_field_type_get_type_id(field_type
);
780 if (type_id
== BT_CTF_TYPE_ID_INTEGER
) {
781 enum bt_ctf_string_encoding encoding
;
783 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
784 if (encoding
== BT_CTF_STRING_ENCODING_UTF8
785 || encoding
== BT_CTF_STRING_ENCODING_ASCII
) {
786 int integer_len
, integer_alignment
;
788 integer_len
= bt_ctf_field_type_integer_get_size(field_type
);
789 if (integer_len
< 0) {
790 return BT_COMPONENT_STATUS_ERROR
;
792 integer_alignment
= bt_ctf_field_type_get_alignment(field_type
);
793 if (integer_alignment
< 0) {
794 return BT_COMPONENT_STATUS_ERROR
;
796 if (integer_len
== CHAR_BIT
797 && integer_alignment
== CHAR_BIT
) {
804 g_string_assign(text
->string
, "");
806 fprintf(text
->out
, "[");
810 for (i
= 0; i
< len
; i
++) {
811 ret
= print_array_field(text
, array
, i
, is_string
, print_names
);
812 if (ret
!= BT_COMPONENT_STATUS_OK
) {
819 fprintf(text
->out
, "\"%s\"", text
->string
->str
);
821 fprintf(text
->out
, " ]");
830 enum bt_component_status
print_sequence_field(struct text_component
*text
,
831 struct bt_ctf_field
*seq
, uint64_t i
,
832 bool is_string
, bool print_names
)
834 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
835 struct bt_ctf_field
*field
= NULL
;
839 fprintf(text
->out
, ", ");
841 fprintf(text
->out
, " ");
844 field
= bt_ctf_field_sequence_get_field(seq
, i
);
846 ret
= BT_COMPONENT_STATUS_ERROR
;
849 ret
= print_field(text
, field
, print_names
);
856 enum bt_component_status
print_sequence(struct text_component
*text
,
857 struct bt_ctf_field
*seq
, bool print_names
)
859 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
860 struct bt_ctf_field_type
*seq_type
= NULL
, *field_type
= NULL
;
861 struct bt_ctf_field
*length_field
= NULL
;
862 enum bt_ctf_type_id type_id
;
865 bool is_string
= false;
867 seq_type
= bt_ctf_field_get_type(seq
);
869 ret
= BT_COMPONENT_STATUS_ERROR
;
872 length_field
= bt_ctf_field_sequence_get_length(seq
);
874 ret
= BT_COMPONENT_STATUS_ERROR
;
877 if (bt_ctf_field_unsigned_integer_get_value(length_field
, &len
) < 0) {
878 ret
= BT_COMPONENT_STATUS_ERROR
;
881 field_type
= bt_ctf_field_type_sequence_get_element_type(seq_type
);
883 ret
= BT_COMPONENT_STATUS_ERROR
;
886 type_id
= bt_ctf_field_type_get_type_id(field_type
);
887 if (type_id
== BT_CTF_TYPE_ID_INTEGER
) {
888 enum bt_ctf_string_encoding encoding
;
890 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
891 if (encoding
== BT_CTF_STRING_ENCODING_UTF8
892 || encoding
== BT_CTF_STRING_ENCODING_ASCII
) {
893 int integer_len
, integer_alignment
;
895 integer_len
= bt_ctf_field_type_integer_get_size(field_type
);
896 if (integer_len
< 0) {
897 ret
= BT_COMPONENT_STATUS_ERROR
;
900 integer_alignment
= bt_ctf_field_type_get_alignment(field_type
);
901 if (integer_alignment
< 0) {
902 ret
= BT_COMPONENT_STATUS_ERROR
;
905 if (integer_len
== CHAR_BIT
906 && integer_alignment
== CHAR_BIT
) {
913 g_string_assign(text
->string
, "");
915 fprintf(text
->out
, "[");
919 for (i
= 0; i
< len
; i
++) {
920 ret
= print_sequence_field(text
, seq
, i
,
921 is_string
, print_names
);
922 if (ret
!= BT_COMPONENT_STATUS_OK
) {
929 fprintf(text
->out
, "\"%s\"", text
->string
->str
);
931 fprintf(text
->out
, " ]");
934 bt_put(length_field
);
941 enum bt_component_status
print_variant(struct text_component
*text
,
942 struct bt_ctf_field
*variant
, bool print_names
)
944 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
945 struct bt_ctf_field
*field
= NULL
;
947 field
= bt_ctf_field_variant_get_current_field(variant
);
949 ret
= BT_COMPONENT_STATUS_ERROR
;
952 fprintf(text
->out
, "{ ");
955 struct bt_ctf_field
*tag_field
= NULL
;
956 const char *tag_choice
;
958 tag_field
= bt_ctf_field_variant_get_tag(variant
);
960 ret
= BT_COMPONENT_STATUS_ERROR
;
963 tag_choice
= bt_ctf_field_enumeration_get_mapping_name(tag_field
);
966 ret
= BT_COMPONENT_STATUS_ERROR
;
969 fprintf(text
->out
, "%s = ", rem_(tag_choice
));
972 ret
= print_field(text
, field
, print_names
);
973 if (ret
!= BT_COMPONENT_STATUS_OK
) {
977 fprintf(text
->out
, " }");
984 enum bt_component_status
print_field(struct text_component
*text
,
985 struct bt_ctf_field
*field
, bool print_names
)
987 enum bt_ctf_type_id type_id
;
989 type_id
= bt_ctf_field_get_type_id(field
);
991 case CTF_TYPE_INTEGER
:
992 return print_integer(text
, field
);
997 if (bt_ctf_field_floating_point_get_value(field
, &v
)) {
998 return BT_COMPONENT_STATUS_ERROR
;
1000 fprintf(text
->out
, "%g", v
);
1001 return BT_COMPONENT_STATUS_OK
;
1004 return print_enum(text
, field
);
1005 case CTF_TYPE_STRING
:
1006 fprintf(text
->out
, "\"%s\"", bt_ctf_field_string_get_value(field
));
1007 return BT_COMPONENT_STATUS_OK
;
1008 case CTF_TYPE_STRUCT
:
1009 return print_struct(text
, field
, print_names
);
1010 case CTF_TYPE_UNTAGGED_VARIANT
:
1011 case CTF_TYPE_VARIANT
:
1012 return print_variant(text
, field
, print_names
);
1013 case CTF_TYPE_ARRAY
:
1014 return print_array(text
, field
, print_names
);
1015 case CTF_TYPE_SEQUENCE
:
1016 return print_sequence(text
, field
, print_names
);
1018 fprintf(text
->err
, "[error] Unknown type id: %d\n", (int) type_id
);
1019 return BT_COMPONENT_STATUS_ERROR
;
1024 enum bt_component_status
print_stream_packet_context(struct text_component
*text
,
1025 struct bt_ctf_event
*event
)
1027 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1028 struct bt_ctf_packet
*packet
= NULL
;
1029 struct bt_ctf_field
*main_field
= NULL
;
1031 packet
= bt_ctf_event_get_packet(event
);
1033 ret
= BT_COMPONENT_STATUS_ERROR
;
1036 main_field
= bt_ctf_packet_get_context(packet
);
1038 ret
= BT_COMPONENT_STATUS_ERROR
;
1041 if (!text
->start_line
) {
1042 fputs(", ", text
->out
);
1044 text
->start_line
= false;
1045 if (text
->options
.print_scope_field_names
) {
1046 fputs("stream.packet.context = ", text
->out
);
1048 ret
= print_field(text
, main_field
,
1049 text
->options
.print_context_field_names
);
1057 enum bt_component_status
print_event_header_raw(struct text_component
*text
,
1058 struct bt_ctf_event
*event
)
1060 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1061 struct bt_ctf_field
*main_field
= NULL
;
1063 main_field
= bt_ctf_event_get_header(event
);
1065 ret
= BT_COMPONENT_STATUS_ERROR
;
1068 if (!text
->start_line
) {
1069 fputs(", ", text
->out
);
1071 text
->start_line
= false;
1072 if (text
->options
.print_scope_field_names
) {
1073 fputs("stream.event.header = ", text
->out
);
1075 ret
= print_field(text
, main_field
,
1076 text
->options
.print_header_field_names
);
1083 enum bt_component_status
print_stream_event_context(struct text_component
*text
,
1084 struct bt_ctf_event
*event
)
1086 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1087 struct bt_ctf_field
*main_field
= NULL
;
1089 main_field
= bt_ctf_event_get_stream_event_context(event
);
1091 ret
= BT_COMPONENT_STATUS_ERROR
;
1094 if (!text
->start_line
) {
1095 fputs(", ", text
->out
);
1097 text
->start_line
= false;
1098 if (text
->options
.print_scope_field_names
) {
1099 fputs("stream.event.context = ", text
->out
);
1101 ret
= print_field(text
, main_field
,
1102 text
->options
.print_context_field_names
);
1109 enum bt_component_status
print_event_context(struct text_component
*text
,
1110 struct bt_ctf_event
*event
)
1112 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1113 struct bt_ctf_field
*main_field
= NULL
;
1115 main_field
= bt_ctf_event_get_event_context(event
);
1117 ret
= BT_COMPONENT_STATUS_ERROR
;
1120 if (!text
->start_line
) {
1121 fputs(", ", text
->out
);
1123 text
->start_line
= false;
1124 if (text
->options
.print_scope_field_names
) {
1125 fputs("event.context = ", text
->out
);
1127 ret
= print_field(text
, main_field
,
1128 text
->options
.print_context_field_names
);
1135 enum bt_component_status
print_event_payload(struct text_component
*text
,
1136 struct bt_ctf_event
*event
)
1138 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1139 struct bt_ctf_field
*main_field
= NULL
;
1141 main_field
= bt_ctf_event_get_payload_field(event
);
1143 ret
= BT_COMPONENT_STATUS_ERROR
;
1146 if (!text
->start_line
) {
1147 fputs(", ", text
->out
);
1149 text
->start_line
= false;
1150 if (text
->options
.print_scope_field_names
) {
1151 fputs("event.fields = ", text
->out
);
1153 ret
= print_field(text
, main_field
,
1154 text
->options
.print_payload_field_names
);
1161 enum bt_component_status
text_print_event(struct text_component
*text
,
1162 struct bt_ctf_event
*event
)
1164 enum bt_component_status ret
;
1166 text
->start_line
= true;
1167 ret
= print_event_header(text
, event
);
1168 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1172 ret
= print_stream_packet_context(text
, event
);
1173 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1177 ret
= print_event_header_raw(text
, event
);
1178 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1182 ret
= print_stream_event_context(text
, event
);
1183 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1187 ret
= print_event_context(text
, event
);
1188 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1192 ret
= print_event_payload(text
, event
);
1193 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1197 fputc('\n', text
->out
);