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
->options
.print_callsite_field
) {
437 if (!text
->start_line
) {
438 fputs(", ", text
->out
);
440 text
->start_line
= false;
442 fputs("callsite = ", text
->out
);
446 if (!text
->start_line
) {
447 fputs(", ", text
->out
);
449 text
->start_line
= false;
451 fputs("name = ", text
->out
);
453 fputs(bt_ctf_event_class_get_name(event_class
), text
->out
);
456 bt_put(stream_class
);
462 enum bt_component_status
print_integer(struct text_component
*text
,
463 struct bt_ctf_field
*field
)
465 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
466 struct bt_ctf_field_type
*field_type
= NULL
;
467 enum bt_ctf_integer_base base
;
468 enum bt_ctf_string_encoding encoding
;
475 field_type
= bt_ctf_field_get_type(field
);
477 ret
= BT_COMPONENT_STATUS_ERROR
;
480 signedness
= bt_ctf_field_type_integer_get_signed(field_type
);
481 if (signedness
< 0) {
482 ret
= BT_COMPONENT_STATUS_ERROR
;
486 if (bt_ctf_field_unsigned_integer_get_value(field
, &v
.u
) < 0) {
487 ret
= BT_COMPONENT_STATUS_ERROR
;
491 if (bt_ctf_field_signed_integer_get_value(field
, &v
.s
) < 0) {
492 ret
= BT_COMPONENT_STATUS_ERROR
;
497 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
499 case BT_CTF_STRING_ENCODING_UTF8
:
500 case BT_CTF_STRING_ENCODING_ASCII
:
501 g_string_append_c(text
->string
, (int) v
.u
);
503 case BT_CTF_STRING_ENCODING_NONE
:
504 case BT_CTF_STRING_ENCODING_UNKNOWN
:
507 ret
= BT_COMPONENT_STATUS_ERROR
;
511 base
= bt_ctf_field_type_integer_get_base(field_type
);
513 case BT_CTF_INTEGER_BASE_BINARY
:
517 len
= bt_ctf_field_type_integer_get_size(field_type
);
519 ret
= BT_COMPONENT_STATUS_ERROR
;
522 fprintf(text
->out
, "0b");
523 v
.u
= _bt_piecewise_lshift(v
.u
, 64 - len
);
524 for (bitnr
= 0; bitnr
< len
; bitnr
++) {
525 fprintf(text
->out
, "%u", (v
.u
& (1ULL << 63)) ? 1 : 0);
526 v
.u
= _bt_piecewise_lshift(v
.u
, 1);
530 case BT_CTF_INTEGER_BASE_OCTAL
:
535 len
= bt_ctf_field_type_integer_get_size(field_type
);
537 ret
= BT_COMPONENT_STATUS_ERROR
;
544 /* Round length to the nearest 3-bit */
545 rounded_len
= (((len
- 1) / 3) + 1) * 3;
546 v
.u
&= ((uint64_t) 1 << rounded_len
) - 1;
550 fprintf(text
->out
, "0%" PRIo64
, v
.u
);
553 case BT_CTF_INTEGER_BASE_DECIMAL
:
555 fprintf(text
->out
, "%" PRIu64
, v
.u
);
557 fprintf(text
->out
, "%" PRId64
, v
.s
);
560 case BT_CTF_INTEGER_BASE_HEXADECIMAL
:
564 len
= bt_ctf_field_type_integer_get_size(field_type
);
566 ret
= BT_COMPONENT_STATUS_ERROR
;
570 /* Round length to the nearest nibble */
571 uint8_t rounded_len
= ((len
+ 3) & ~0x3);
573 v
.u
&= ((uint64_t) 1 << rounded_len
) - 1;
576 fprintf(text
->out
, "0x%" PRIX64
, v
.u
);
580 ret
= BT_COMPONENT_STATUS_ERROR
;
589 enum bt_component_status
print_enum(struct text_component
*text
,
590 struct bt_ctf_field
*field
)
592 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
593 struct bt_ctf_field
*container_field
= NULL
;
594 const char *mapping_name
;
596 container_field
= bt_ctf_field_enumeration_get_container(field
);
597 if (!container_field
) {
598 ret
= BT_COMPONENT_STATUS_ERROR
;
601 mapping_name
= bt_ctf_field_enumeration_get_mapping_name(field
);
603 fprintf(text
->out
, "( \"%s\"", mapping_name
);
605 fprintf(text
->out
, "( <unknown>");
607 fprintf(text
->out
, " : container = ");
608 ret
= print_integer(text
, container_field
);
609 if (ret
!= BT_COMPONENT_STATUS_OK
) {
612 fprintf(text
->out
, " )");
614 bt_put(container_field
);
619 enum bt_component_status
print_struct_field(struct text_component
*text
,
620 struct bt_ctf_field
*_struct
,
621 struct bt_ctf_field_type
*struct_type
,
622 int i
, bool print_names
)
624 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
625 const char *field_name
;
626 struct bt_ctf_field
*field
= NULL
;
627 struct bt_ctf_field_type
*field_type
= NULL
;;
629 field
= bt_ctf_field_structure_get_field_by_index(_struct
, i
);
631 ret
= BT_COMPONENT_STATUS_ERROR
;
634 if (bt_ctf_field_type_structure_get_field(struct_type
,
635 &field_name
, &field_type
, i
) < 0) {
636 ret
= BT_COMPONENT_STATUS_ERROR
;
641 fprintf(text
->out
, ", ");
643 fprintf(text
->out
, " ");
646 fprintf(text
->out
, "%s = ", rem_(field_name
));
648 ret
= print_field(text
, field
, print_names
);
656 enum bt_component_status
print_struct(struct text_component
*text
,
657 struct bt_ctf_field
*_struct
, bool print_names
)
659 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
660 struct bt_ctf_field_type
*struct_type
= NULL
;
663 struct_type
= bt_ctf_field_get_type(_struct
);
665 ret
= BT_COMPONENT_STATUS_ERROR
;
668 nr_fields
= bt_ctf_field_type_structure_get_field_count(struct_type
);
670 ret
= BT_COMPONENT_STATUS_ERROR
;
673 fprintf(text
->out
, "{");
675 for (i
= 0; i
< nr_fields
; i
++) {
676 ret
= print_struct_field(text
, _struct
, struct_type
, i
,
678 if (ret
!= BT_COMPONENT_STATUS_OK
) {
683 fprintf(text
->out
, " }");
690 enum bt_component_status
print_array_field(struct text_component
*text
,
691 struct bt_ctf_field
*array
, uint64_t i
,
692 bool is_string
, bool print_names
)
694 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
695 struct bt_ctf_field
*field
= NULL
;
699 fprintf(text
->out
, ", ");
701 fprintf(text
->out
, " ");
704 field
= bt_ctf_field_array_get_field(array
, i
);
706 ret
= BT_COMPONENT_STATUS_ERROR
;
709 ret
= print_field(text
, field
, print_names
);
716 enum bt_component_status
print_array(struct text_component
*text
,
717 struct bt_ctf_field
*array
, bool print_names
)
719 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
720 struct bt_ctf_field_type
*array_type
= NULL
, *field_type
= NULL
;
721 enum bt_ctf_type_id type_id
;
724 bool is_string
= false;
726 array_type
= bt_ctf_field_get_type(array
);
728 ret
= BT_COMPONENT_STATUS_ERROR
;
731 field_type
= bt_ctf_field_type_array_get_element_type(array_type
);
733 ret
= BT_COMPONENT_STATUS_ERROR
;
736 len
= bt_ctf_field_type_array_get_length(array_type
);
738 ret
= BT_COMPONENT_STATUS_ERROR
;
741 type_id
= bt_ctf_field_type_get_type_id(field_type
);
742 if (type_id
== BT_CTF_TYPE_ID_INTEGER
) {
743 enum bt_ctf_string_encoding encoding
;
745 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
746 if (encoding
== BT_CTF_STRING_ENCODING_UTF8
747 || encoding
== BT_CTF_STRING_ENCODING_ASCII
) {
748 int integer_len
, integer_alignment
;
750 integer_len
= bt_ctf_field_type_integer_get_size(field_type
);
751 if (integer_len
< 0) {
752 return BT_COMPONENT_STATUS_ERROR
;
754 integer_alignment
= bt_ctf_field_type_get_alignment(field_type
);
755 if (integer_alignment
< 0) {
756 return BT_COMPONENT_STATUS_ERROR
;
758 if (integer_len
== CHAR_BIT
759 && integer_alignment
== CHAR_BIT
) {
766 g_string_assign(text
->string
, "");
768 fprintf(text
->out
, "[");
772 for (i
= 0; i
< len
; i
++) {
773 ret
= print_array_field(text
, array
, i
, is_string
, print_names
);
774 if (ret
!= BT_COMPONENT_STATUS_OK
) {
781 fprintf(text
->out
, "\"%s\"", text
->string
->str
);
783 fprintf(text
->out
, " ]");
792 enum bt_component_status
print_sequence_field(struct text_component
*text
,
793 struct bt_ctf_field
*seq
, uint64_t i
,
794 bool is_string
, bool print_names
)
796 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
797 struct bt_ctf_field
*field
= NULL
;
801 fprintf(text
->out
, ", ");
803 fprintf(text
->out
, " ");
806 field
= bt_ctf_field_sequence_get_field(seq
, i
);
808 ret
= BT_COMPONENT_STATUS_ERROR
;
811 ret
= print_field(text
, field
, print_names
);
818 enum bt_component_status
print_sequence(struct text_component
*text
,
819 struct bt_ctf_field
*seq
, bool print_names
)
821 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
822 struct bt_ctf_field_type
*seq_type
= NULL
, *field_type
= NULL
;
823 struct bt_ctf_field
*length_field
= NULL
;
824 enum bt_ctf_type_id type_id
;
827 bool is_string
= false;
829 seq_type
= bt_ctf_field_get_type(seq
);
831 ret
= BT_COMPONENT_STATUS_ERROR
;
834 length_field
= bt_ctf_field_sequence_get_length(seq
);
836 ret
= BT_COMPONENT_STATUS_ERROR
;
839 if (bt_ctf_field_unsigned_integer_get_value(length_field
, &len
) < 0) {
840 ret
= BT_COMPONENT_STATUS_ERROR
;
843 field_type
= bt_ctf_field_type_sequence_get_element_type(seq_type
);
845 ret
= BT_COMPONENT_STATUS_ERROR
;
848 type_id
= bt_ctf_field_type_get_type_id(field_type
);
849 if (type_id
== BT_CTF_TYPE_ID_INTEGER
) {
850 enum bt_ctf_string_encoding encoding
;
852 encoding
= bt_ctf_field_type_integer_get_encoding(field_type
);
853 if (encoding
== BT_CTF_STRING_ENCODING_UTF8
854 || encoding
== BT_CTF_STRING_ENCODING_ASCII
) {
855 int integer_len
, integer_alignment
;
857 integer_len
= bt_ctf_field_type_integer_get_size(field_type
);
858 if (integer_len
< 0) {
859 ret
= BT_COMPONENT_STATUS_ERROR
;
862 integer_alignment
= bt_ctf_field_type_get_alignment(field_type
);
863 if (integer_alignment
< 0) {
864 ret
= BT_COMPONENT_STATUS_ERROR
;
867 if (integer_len
== CHAR_BIT
868 && integer_alignment
== CHAR_BIT
) {
875 g_string_assign(text
->string
, "");
877 fprintf(text
->out
, "[");
881 for (i
= 0; i
< len
; i
++) {
882 ret
= print_sequence_field(text
, seq
, i
,
883 is_string
, print_names
);
884 if (ret
!= BT_COMPONENT_STATUS_OK
) {
891 fprintf(text
->out
, "\"%s\"", text
->string
->str
);
893 fprintf(text
->out
, " ]");
896 bt_put(length_field
);
903 enum bt_component_status
print_variant(struct text_component
*text
,
904 struct bt_ctf_field
*variant
, bool print_names
)
906 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
907 struct bt_ctf_field
*field
= NULL
;
909 field
= bt_ctf_field_variant_get_current_field(variant
);
911 ret
= BT_COMPONENT_STATUS_ERROR
;
914 fprintf(text
->out
, "{ ");
917 struct bt_ctf_field
*tag_field
= NULL
;
918 const char *tag_choice
;
920 tag_field
= bt_ctf_field_variant_get_tag(variant
);
922 ret
= BT_COMPONENT_STATUS_ERROR
;
925 tag_choice
= bt_ctf_field_enumeration_get_mapping_name(tag_field
);
928 ret
= BT_COMPONENT_STATUS_ERROR
;
931 fprintf(text
->out
, "%s = ", rem_(tag_choice
));
934 ret
= print_field(text
, field
, print_names
);
935 if (ret
!= BT_COMPONENT_STATUS_OK
) {
939 fprintf(text
->out
, " }");
946 enum bt_component_status
print_field(struct text_component
*text
,
947 struct bt_ctf_field
*field
, bool print_names
)
949 enum bt_ctf_type_id type_id
;
951 type_id
= bt_ctf_field_get_type_id(field
);
953 case CTF_TYPE_INTEGER
:
954 return print_integer(text
, field
);
959 if (bt_ctf_field_floating_point_get_value(field
, &v
)) {
960 return BT_COMPONENT_STATUS_ERROR
;
962 fprintf(text
->out
, "%g", v
);
963 return BT_COMPONENT_STATUS_OK
;
966 return print_enum(text
, field
);
967 case CTF_TYPE_STRING
:
968 fprintf(text
->out
, "\"%s\"", bt_ctf_field_string_get_value(field
));
969 return BT_COMPONENT_STATUS_OK
;
970 case CTF_TYPE_STRUCT
:
971 return print_struct(text
, field
, print_names
);
972 case CTF_TYPE_UNTAGGED_VARIANT
:
973 case CTF_TYPE_VARIANT
:
974 return print_variant(text
, field
, print_names
);
976 return print_array(text
, field
, print_names
);
977 case CTF_TYPE_SEQUENCE
:
978 return print_sequence(text
, field
, print_names
);
980 fprintf(text
->err
, "[error] Unknown type id: %d\n", (int) type_id
);
981 return BT_COMPONENT_STATUS_ERROR
;
986 enum bt_component_status
print_stream_packet_context(struct text_component
*text
,
987 struct bt_ctf_event
*event
)
989 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
990 struct bt_ctf_packet
*packet
= NULL
;
991 struct bt_ctf_field
*main_field
= NULL
;
993 packet
= bt_ctf_event_get_packet(event
);
995 ret
= BT_COMPONENT_STATUS_ERROR
;
998 main_field
= bt_ctf_packet_get_context(packet
);
1000 ret
= BT_COMPONENT_STATUS_ERROR
;
1003 if (!text
->start_line
) {
1004 fputs(", ", text
->out
);
1006 text
->start_line
= false;
1007 if (text
->options
.print_scope_field_names
) {
1008 fputs("stream.packet.context = ", text
->out
);
1010 ret
= print_field(text
, main_field
,
1011 text
->options
.print_context_field_names
);
1019 enum bt_component_status
print_event_header_raw(struct text_component
*text
,
1020 struct bt_ctf_event
*event
)
1022 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1023 struct bt_ctf_field
*main_field
= NULL
;
1025 main_field
= bt_ctf_event_get_header(event
);
1027 ret
= BT_COMPONENT_STATUS_ERROR
;
1030 if (!text
->start_line
) {
1031 fputs(", ", text
->out
);
1033 text
->start_line
= false;
1034 if (text
->options
.print_scope_field_names
) {
1035 fputs("stream.event.header = ", text
->out
);
1037 ret
= print_field(text
, main_field
,
1038 text
->options
.print_header_field_names
);
1045 enum bt_component_status
print_stream_event_context(struct text_component
*text
,
1046 struct bt_ctf_event
*event
)
1048 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1049 struct bt_ctf_field
*main_field
= NULL
;
1051 main_field
= bt_ctf_event_get_stream_event_context(event
);
1053 ret
= BT_COMPONENT_STATUS_ERROR
;
1056 if (!text
->start_line
) {
1057 fputs(", ", text
->out
);
1059 text
->start_line
= false;
1060 if (text
->options
.print_scope_field_names
) {
1061 fputs("stream.event.context = ", text
->out
);
1063 ret
= print_field(text
, main_field
,
1064 text
->options
.print_context_field_names
);
1071 enum bt_component_status
print_event_context(struct text_component
*text
,
1072 struct bt_ctf_event
*event
)
1074 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1075 struct bt_ctf_field
*main_field
= NULL
;
1077 main_field
= bt_ctf_event_get_event_context(event
);
1079 ret
= BT_COMPONENT_STATUS_ERROR
;
1082 if (!text
->start_line
) {
1083 fputs(", ", text
->out
);
1085 text
->start_line
= false;
1086 if (text
->options
.print_scope_field_names
) {
1087 fputs("event.context = ", text
->out
);
1089 ret
= print_field(text
, main_field
,
1090 text
->options
.print_context_field_names
);
1097 enum bt_component_status
print_event_payload(struct text_component
*text
,
1098 struct bt_ctf_event
*event
)
1100 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
1101 struct bt_ctf_field
*main_field
= NULL
;
1103 main_field
= bt_ctf_event_get_payload_field(event
);
1105 ret
= BT_COMPONENT_STATUS_ERROR
;
1108 if (!text
->start_line
) {
1109 fputs(", ", text
->out
);
1111 text
->start_line
= false;
1112 if (text
->options
.print_scope_field_names
) {
1113 fputs("event.fields = ", text
->out
);
1115 ret
= print_field(text
, main_field
,
1116 text
->options
.print_payload_field_names
);
1123 enum bt_component_status
text_print_event(struct text_component
*text
,
1124 struct bt_ctf_event
*event
)
1126 enum bt_component_status ret
;
1128 text
->start_line
= true;
1129 ret
= print_event_header(text
, event
);
1130 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1134 ret
= print_stream_packet_context(text
, event
);
1135 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1139 ret
= print_event_header_raw(text
, event
);
1140 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1144 ret
= print_stream_event_context(text
, event
);
1145 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1149 ret
= print_event_context(text
, event
);
1150 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1154 ret
= print_event_payload(text
, event
);
1155 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1159 fputc('\n', text
->out
);