2 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include <babeltrace2/babeltrace.h>
27 #include "common/assert.h"
28 #include "common/common.h"
29 #include "common/uuid.h"
32 #include "obj-lifetime-mgmt.h"
36 const char *plural(uint64_t value
)
38 return value
== 1 ? "" : "s";
42 void incr_indent_by(struct details_write_ctx
*ctx
, unsigned int value
)
45 ctx
->indent_level
+= value
;
49 void incr_indent(struct details_write_ctx
*ctx
)
51 incr_indent_by(ctx
, 2);
55 void decr_indent_by(struct details_write_ctx
*ctx
, unsigned int value
)
58 BT_ASSERT(ctx
->indent_level
>= value
);
59 ctx
->indent_level
-= value
;
63 void decr_indent(struct details_write_ctx
*ctx
)
65 decr_indent_by(ctx
, 2);
69 void format_uint(char *buf
, uint64_t value
, unsigned int base
)
71 const char *spec
= "%" PRIu64
;
72 char *buf_start
= buf
;
73 unsigned int digits_per_group
= 3;
75 bool sep_digits
= true;
80 /* TODO: Support binary format */
96 * Do not insert digit separators for numbers
97 * under 10,000 as it looks weird.
107 sprintf(buf_start
, spec
, value
);
110 bt_common_sep_digits(buf_start
, digits_per_group
, sep
);
115 void format_int(char *buf
, int64_t value
, unsigned int base
)
117 const char *spec
= "%" PRIu64
;
118 char *buf_start
= buf
;
119 unsigned int digits_per_group
= 3;
121 bool sep_digits
= true;
122 uint64_t abs_value
= value
< 0 ? (uint64_t) -value
: (uint64_t) value
;
132 /* TODO: Support binary format */
134 strcpy(buf_start
, "0x");
136 digits_per_group
= 4;
141 strcpy(buf_start
, "0");
146 if (value
>= -9999 && value
<= 9999) {
148 * Do not insert digit separators for numbers
149 * over -10,000 and under 10,000 as it looks
160 sprintf(buf_start
, spec
, abs_value
);
163 bt_common_sep_digits(buf_start
, digits_per_group
, sep
);
168 void write_nl(struct details_write_ctx
*ctx
)
171 g_string_append_c(ctx
->str
, '\n');
175 void write_sp(struct details_write_ctx
*ctx
)
178 g_string_append_c(ctx
->str
, ' ');
182 void write_indent(struct details_write_ctx
*ctx
)
188 for (i
= 0; i
< ctx
->indent_level
; i
++) {
194 void write_compound_member_name(struct details_write_ctx
*ctx
, const char *name
)
197 g_string_append_printf(ctx
->str
, "%s%s%s:",
198 color_fg_cyan(ctx
), name
, color_reset(ctx
));
202 void write_array_index(struct details_write_ctx
*ctx
, uint64_t index
)
207 format_uint(buf
, index
, 10);
208 g_string_append_printf(ctx
->str
, "%s[%s]%s:",
209 color_fg_cyan(ctx
), buf
, color_reset(ctx
));
213 void write_obj_type_name(struct details_write_ctx
*ctx
, const char *name
)
215 g_string_append_printf(ctx
->str
, "%s%s%s%s",
216 color_fg_yellow(ctx
), color_bold(ctx
), name
, color_reset(ctx
));
220 void write_prop_name(struct details_write_ctx
*ctx
, const char *prop_name
)
222 g_string_append_printf(ctx
->str
, "%s%s%s",
223 color_fg_magenta(ctx
), prop_name
, color_reset(ctx
));
227 void write_str_prop_value(struct details_write_ctx
*ctx
, const char *value
)
229 g_string_append_printf(ctx
->str
, "%s%s%s",
230 color_bold(ctx
), value
, color_reset(ctx
));
234 void write_uint_str_prop_value(struct details_write_ctx
*ctx
, const char *value
)
236 write_str_prop_value(ctx
, value
);
240 void write_uint_prop_value(struct details_write_ctx
*ctx
, uint64_t value
)
244 format_uint(buf
, value
, 10);
245 write_uint_str_prop_value(ctx
, buf
);
249 void write_int_prop_value(struct details_write_ctx
*ctx
, int64_t value
)
253 format_int(buf
, value
, 10);
254 write_uint_str_prop_value(ctx
, buf
);
258 void write_float_prop_value(struct details_write_ctx
*ctx
, double value
)
260 g_string_append_printf(ctx
->str
, "%s%f%s",
261 color_bold(ctx
), value
, color_reset(ctx
));
265 void write_str_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
266 const char *prop_value
)
268 BT_ASSERT(prop_value
);
270 write_prop_name(ctx
, prop_name
);
271 g_string_append(ctx
->str
, ": ");
272 write_str_prop_value(ctx
, prop_value
);
277 void write_uint_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
281 write_prop_name(ctx
, prop_name
);
282 g_string_append(ctx
->str
, ": ");
283 write_uint_prop_value(ctx
, prop_value
);
288 void write_int_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
292 write_prop_name(ctx
, prop_name
);
293 g_string_append(ctx
->str
, ": ");
294 write_int_prop_value(ctx
, prop_value
);
299 void write_int_str_prop_value(struct details_write_ctx
*ctx
, const char *value
)
301 write_str_prop_value(ctx
, value
);
305 void write_bool_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
311 write_prop_name(ctx
, prop_name
);
312 g_string_append_printf(ctx
->str
, ": %s", color_bold(ctx
));
315 g_string_append(ctx
->str
, color_fg_green(ctx
));
318 g_string_append(ctx
->str
, color_fg_red(ctx
));
322 g_string_append_printf(ctx
->str
, "%s%s\n", str
, color_reset(ctx
));
326 void write_uuid_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
331 write_prop_name(ctx
, prop_name
);
332 g_string_append_printf(ctx
->str
,
333 ": %s" BT_UUID_FMT
"%s\n",
335 BT_UUID_FMT_VALUES(uuid
),
340 void write_int_field_class_props(struct details_write_ctx
*ctx
,
341 const bt_field_class
*fc
, bool close
)
343 g_string_append_printf(ctx
->str
, "(%s%" PRIu64
"-bit%s, Base ",
345 bt_field_class_integer_get_field_value_range(fc
),
348 switch (bt_field_class_integer_get_preferred_display_base(fc
)) {
349 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
:
350 write_uint_prop_value(ctx
, 2);
352 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
:
353 write_uint_prop_value(ctx
, 8);
355 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
:
356 write_uint_prop_value(ctx
, 10);
358 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
:
359 write_uint_prop_value(ctx
, 16);
366 g_string_append(ctx
->str
, ")");
370 struct enum_field_class_mapping_range
{
382 struct enum_field_class_mapping
{
386 /* Array of `struct enum_field_class_mapping_range` */
391 gint
compare_enum_field_class_mappings(struct enum_field_class_mapping
**a
,
392 struct enum_field_class_mapping
**b
)
394 return strcmp((*a
)->label
, (*b
)->label
);
398 gint
compare_enum_field_class_mapping_ranges_signed(
399 struct enum_field_class_mapping_range
*a
,
400 struct enum_field_class_mapping_range
*b
)
403 if (a
->lower
.i
< b
->lower
.i
) {
405 } else if (a
->lower
.i
> b
->lower
.i
) {
408 if (a
->upper
.i
< b
->upper
.i
) {
410 } else if (a
->upper
.i
> b
->upper
.i
) {
419 gint
compare_enum_field_class_mapping_ranges_unsigned(
420 struct enum_field_class_mapping_range
*a
,
421 struct enum_field_class_mapping_range
*b
)
423 if (a
->lower
.u
< b
->lower
.u
) {
425 } else if (a
->lower
.u
> b
->lower
.u
) {
428 if (a
->upper
.u
< b
->upper
.u
) {
430 } else if (a
->upper
.u
> b
->upper
.u
) {
439 void destroy_enum_field_class_mapping(struct enum_field_class_mapping
*mapping
)
441 if (mapping
->ranges
) {
442 g_array_free(mapping
->ranges
, TRUE
);
443 mapping
->ranges
= NULL
;
450 void write_enum_field_class_mapping_range(struct details_write_ctx
*ctx
,
451 struct enum_field_class_mapping_range
*range
, bool is_signed
)
453 g_string_append(ctx
->str
, "[");
456 write_int_prop_value(ctx
, range
->lower
.i
);
458 write_int_prop_value(ctx
, range
->lower
.u
);
461 g_string_append(ctx
->str
, ", ");
464 write_int_prop_value(ctx
, range
->upper
.i
);
466 write_int_prop_value(ctx
, range
->upper
.u
);
469 g_string_append(ctx
->str
, "]");
473 void write_enum_field_class_mappings(struct details_write_ctx
*ctx
,
474 const bt_field_class
*fc
)
479 bool is_signed
= bt_field_class_get_type(fc
) ==
480 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
;
482 mappings
= g_ptr_array_new_with_free_func(
483 (GDestroyNotify
) destroy_enum_field_class_mapping
);
487 * Copy field class's mappings to our own arrays and structures
490 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(fc
); i
++) {
491 const void *fc_mapping
;
492 struct enum_field_class_mapping
*mapping
= g_new0(
493 struct enum_field_class_mapping
, 1);
496 mapping
->ranges
= g_array_new(FALSE
, TRUE
,
497 sizeof(struct enum_field_class_mapping_range
));
498 BT_ASSERT(mapping
->ranges
);
501 fc_mapping
= bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
504 fc_mapping
= bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
508 mapping
->label
= bt_field_class_enumeration_mapping_get_label(
509 bt_field_class_signed_enumeration_mapping_as_mapping_const(
513 range_i
< bt_field_class_enumeration_mapping_get_range_count(
514 bt_field_class_signed_enumeration_mapping_as_mapping_const(fc_mapping
));
516 struct enum_field_class_mapping_range range
;
519 bt_field_class_signed_enumeration_mapping_get_range_by_index(
521 &range
.lower
.i
, &range
.upper
.i
);
523 bt_field_class_unsigned_enumeration_mapping_get_range_by_index(
525 &range
.lower
.u
, &range
.upper
.u
);
528 g_array_append_val(mapping
->ranges
, range
);
531 g_ptr_array_add(mappings
, mapping
);
534 /* Sort mappings, and for each mapping, sort ranges */
535 g_ptr_array_sort(mappings
,
536 (GCompareFunc
) compare_enum_field_class_mappings
);
538 for (i
= 0; i
< mappings
->len
; i
++) {
539 struct enum_field_class_mapping
*mapping
= mappings
->pdata
[i
];
542 g_array_sort(mapping
->ranges
,
544 compare_enum_field_class_mapping_ranges_signed
);
546 g_array_sort(mapping
->ranges
,
548 compare_enum_field_class_mapping_ranges_unsigned
);
553 for (i
= 0; i
< mappings
->len
; i
++) {
554 struct enum_field_class_mapping
*mapping
= mappings
->pdata
[i
];
557 write_compound_member_name(ctx
, mapping
->label
);
559 if (mapping
->ranges
->len
== 1) {
560 /* Single one: write on same line */
562 write_enum_field_class_mapping_range(ctx
,
563 &g_array_index(mapping
->ranges
,
564 struct enum_field_class_mapping_range
,
571 for (range_i
= 0; range_i
< mapping
->ranges
->len
; range_i
++) {
574 write_enum_field_class_mapping_range(ctx
,
575 &g_array_index(mapping
->ranges
,
576 struct enum_field_class_mapping_range
,
577 range_i
), is_signed
);
583 g_ptr_array_free(mappings
, TRUE
);
587 void write_field_path(struct details_write_ctx
*ctx
,
588 const bt_field_path
*field_path
)
592 g_string_append_c(ctx
->str
, '[');
594 switch (bt_field_path_get_root_scope(field_path
)) {
595 case BT_SCOPE_PACKET_CONTEXT
:
596 write_str_prop_value(ctx
, "Packet context");
598 case BT_SCOPE_EVENT_COMMON_CONTEXT
:
599 write_str_prop_value(ctx
, "Event common context");
601 case BT_SCOPE_EVENT_SPECIFIC_CONTEXT
:
602 write_str_prop_value(ctx
, "Event specific context");
604 case BT_SCOPE_EVENT_PAYLOAD
:
605 write_str_prop_value(ctx
, "Event payload");
611 g_string_append(ctx
->str
, ": ");
613 for (i
= 0; i
< bt_field_path_get_item_count(field_path
); i
++) {
614 const bt_field_path_item
*fp_item
=
615 bt_field_path_borrow_item_by_index_const(field_path
, i
);
618 g_string_append(ctx
->str
, ", ");
621 switch (bt_field_path_item_get_type(fp_item
)) {
622 case BT_FIELD_PATH_ITEM_TYPE_INDEX
:
623 write_uint_prop_value(ctx
,
624 bt_field_path_item_index_get_index(fp_item
));
626 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
627 write_str_prop_value(ctx
, "<current>");
634 g_string_append_c(ctx
->str
, ']');
638 void write_field_class(struct details_write_ctx
*ctx
, const bt_field_class
*fc
,
643 bt_field_class_type fc_type
= bt_field_class_get_type(fc
);
645 /* Write field class's name */
647 write_compound_member_name(ctx
, name
);
651 /* Write field class's type */
653 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
654 type
= "Unsigned integer";
656 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
657 type
= "Signed integer";
659 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
660 type
= "Unsigned enumeration";
662 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
663 type
= "Signed enumeration";
665 case BT_FIELD_CLASS_TYPE_REAL
:
668 case BT_FIELD_CLASS_TYPE_STRING
:
671 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
674 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
675 type
= "Static array";
677 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
678 type
= "Dynamic array";
680 case BT_FIELD_CLASS_TYPE_VARIANT
:
687 g_string_append_printf(ctx
->str
, "%s%s%s",
688 color_fg_blue(ctx
), type
, color_reset(ctx
));
690 /* Write field class's properties */
692 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
693 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
695 write_int_field_class_props(ctx
, fc
, true);
697 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
698 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
700 uint64_t mapping_count
=
701 bt_field_class_enumeration_get_mapping_count(fc
);
704 write_int_field_class_props(ctx
, fc
, false);
705 g_string_append(ctx
->str
, ", ");
706 write_uint_prop_value(ctx
, mapping_count
);
707 g_string_append_printf(ctx
->str
, " mapping%s)",
708 plural(mapping_count
));
710 if (mapping_count
> 0) {
711 g_string_append_c(ctx
->str
, ':');
713 write_enum_field_class_mappings(ctx
, fc
);
719 case BT_FIELD_CLASS_TYPE_REAL
:
720 if (bt_field_class_real_is_single_precision(fc
)) {
721 g_string_append(ctx
->str
, " (Single precision)");
723 g_string_append(ctx
->str
, " (Double precision)");
727 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
729 uint64_t member_count
=
730 bt_field_class_structure_get_member_count(fc
);
732 g_string_append(ctx
->str
, " (");
733 write_uint_prop_value(ctx
, member_count
);
734 g_string_append_printf(ctx
->str
, " member%s)",
735 plural(member_count
));
737 if (member_count
> 0) {
738 g_string_append_c(ctx
->str
, ':');
741 for (i
= 0; i
< member_count
; i
++) {
742 const bt_field_class_structure_member
*member
=
743 bt_field_class_structure_borrow_member_by_index_const(
747 write_field_class(ctx
,
748 bt_field_class_structure_member_borrow_field_class_const(member
),
749 bt_field_class_structure_member_get_name(member
));
757 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
758 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
759 if (fc_type
== BT_FIELD_CLASS_TYPE_STATIC_ARRAY
) {
760 g_string_append(ctx
->str
, " (Length ");
761 write_uint_prop_value(ctx
,
762 bt_field_class_static_array_get_length(fc
));
763 g_string_append_c(ctx
->str
, ')');
765 const bt_field_path
*length_field_path
=
766 bt_field_class_dynamic_array_borrow_length_field_path_const(
769 if (length_field_path
) {
770 g_string_append(ctx
->str
, " (Length field path ");
771 write_field_path(ctx
, length_field_path
);
772 g_string_append_c(ctx
->str
, ')');
776 g_string_append_c(ctx
->str
, ':');
779 write_field_class(ctx
,
780 bt_field_class_array_borrow_element_field_class_const(fc
),
784 case BT_FIELD_CLASS_TYPE_VARIANT
:
786 uint64_t option_count
=
787 bt_field_class_variant_get_option_count(fc
);
788 const bt_field_path
*sel_field_path
=
789 bt_field_class_variant_borrow_selector_field_path_const(
792 g_string_append(ctx
->str
, " (");
793 write_uint_prop_value(ctx
, option_count
);
794 g_string_append_printf(ctx
->str
, " option%s, ",
795 plural(option_count
));
797 if (sel_field_path
) {
798 g_string_append(ctx
->str
, "Selector field path ");
799 write_field_path(ctx
, sel_field_path
);
802 g_string_append_c(ctx
->str
, ')');
804 if (option_count
> 0) {
805 g_string_append_c(ctx
->str
, ':');
808 for (i
= 0; i
< option_count
; i
++) {
809 const bt_field_class_variant_option
*option
=
810 bt_field_class_variant_borrow_option_by_index_const(
814 write_field_class(ctx
,
815 bt_field_class_variant_option_borrow_field_class_const(option
),
816 bt_field_class_variant_option_get_name(option
));
830 void write_root_field_class(struct details_write_ctx
*ctx
, const char *name
,
831 const bt_field_class
*fc
)
836 write_prop_name(ctx
, name
);
837 g_string_append(ctx
->str
, ": ");
838 write_field_class(ctx
, fc
, NULL
);
843 void write_event_class(struct details_write_ctx
*ctx
, const bt_event_class
*ec
)
845 const char *name
= bt_event_class_get_name(ec
);
847 const bt_field_class
*fc
;
848 bt_event_class_log_level log_level
;
851 write_obj_type_name(ctx
, "Event class");
853 /* Write name and ID */
855 g_string_append_printf(ctx
->str
, " `%s%s%s`",
856 color_fg_green(ctx
), name
, color_reset(ctx
));
859 g_string_append(ctx
->str
, " (ID ");
860 write_uint_prop_value(ctx
, bt_event_class_get_id(ec
));
861 g_string_append(ctx
->str
, "):\n");
863 /* Write properties */
866 /* Write log level */
867 if (bt_event_class_get_log_level(ec
, &log_level
) ==
868 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
869 const char *ll_str
= NULL
;
872 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
873 ll_str
= "Emergency";
875 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
878 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
881 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
884 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
887 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
890 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
893 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
894 ll_str
= "Debug (system)";
896 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
897 ll_str
= "Debug (program)";
899 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
900 ll_str
= "Debug (process)";
902 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
903 ll_str
= "Debug (module)";
905 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
906 ll_str
= "Debug (unit)";
908 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
909 ll_str
= "Debug (function)";
911 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
912 ll_str
= "Debug (line)";
914 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
921 write_str_prop_line(ctx
, "Log level", ll_str
);
925 emf_uri
= bt_event_class_get_emf_uri(ec
);
927 write_str_prop_line(ctx
, "EMF URI", emf_uri
);
930 /* Write specific context field class */
931 fc
= bt_event_class_borrow_specific_context_field_class_const(ec
);
933 write_root_field_class(ctx
, "Specific context field class", fc
);
936 /* Write payload field class */
937 fc
= bt_event_class_borrow_payload_field_class_const(ec
);
939 write_root_field_class(ctx
, "Payload field class", fc
);
946 void write_clock_class_prop_lines(struct details_write_ctx
*ctx
,
947 const bt_clock_class
*cc
)
949 int64_t offset_seconds
;
950 uint64_t offset_cycles
;
953 str
= bt_clock_class_get_name(cc
);
955 write_str_prop_line(ctx
, "Name", str
);
958 str
= bt_clock_class_get_description(cc
);
960 write_str_prop_line(ctx
, "Description", str
);
963 write_uint_prop_line(ctx
, "Frequency (Hz)",
964 bt_clock_class_get_frequency(cc
));
965 write_uint_prop_line(ctx
, "Precision (cycles)",
966 bt_clock_class_get_precision(cc
));
967 bt_clock_class_get_offset(cc
, &offset_seconds
, &offset_cycles
);
968 write_int_prop_line(ctx
, "Offset (s)", offset_seconds
);
969 write_uint_prop_line(ctx
, "Offset (cycles)", offset_cycles
);
970 write_bool_prop_line(ctx
, "Origin is Unix epoch",
971 bt_clock_class_origin_is_unix_epoch(cc
));
973 if (ctx
->details_comp
->cfg
.with_uuid
) {
974 bt_uuid uuid
= bt_clock_class_get_uuid(cc
);
977 write_uuid_prop_line(ctx
, "UUID", uuid
);
983 gint
compare_event_classes(const bt_event_class
**a
, const bt_event_class
**b
)
985 uint64_t id_a
= bt_event_class_get_id(*a
);
986 uint64_t id_b
= bt_event_class_get_id(*b
);
990 } else if (id_a
> id_b
) {
998 void write_stream_class(struct details_write_ctx
*ctx
,
999 const bt_stream_class
*sc
)
1001 const bt_field_class
*fc
;
1002 GPtrArray
*event_classes
= g_ptr_array_new();
1006 write_obj_type_name(ctx
, "Stream class");
1008 /* Write name and ID */
1009 if (ctx
->details_comp
->cfg
.with_stream_class_name
) {
1010 const char *name
= bt_stream_class_get_name(sc
);
1013 g_string_append(ctx
->str
, " `");
1014 write_str_prop_value(ctx
, name
);
1015 g_string_append(ctx
->str
, "`");
1019 g_string_append(ctx
->str
, " (ID ");
1020 write_uint_prop_value(ctx
, bt_stream_class_get_id(sc
));
1021 g_string_append(ctx
->str
, "):\n");
1023 /* Write properties */
1026 /* Write configuration */
1027 write_bool_prop_line(ctx
,
1028 "Packets have beginning default clock snapshot",
1029 bt_stream_class_packets_have_beginning_default_clock_snapshot(sc
));
1030 write_bool_prop_line(ctx
,
1031 "Packets have end default clock snapshot",
1032 bt_stream_class_packets_have_end_default_clock_snapshot(sc
));
1033 write_bool_prop_line(ctx
,
1034 "Supports discarded events",
1035 bt_stream_class_supports_discarded_events(sc
));
1037 if (bt_stream_class_supports_discarded_events(sc
)) {
1038 write_bool_prop_line(ctx
,
1039 "Discarded events have default clock snapshots",
1040 bt_stream_class_discarded_events_have_default_clock_snapshots(sc
));
1043 write_bool_prop_line(ctx
,
1044 "Supports discarded packets",
1045 bt_stream_class_supports_discarded_packets(sc
));
1047 if (bt_stream_class_supports_discarded_packets(sc
)) {
1048 write_bool_prop_line(ctx
,
1049 "Discarded packets have default clock snapshots",
1050 bt_stream_class_discarded_packets_have_default_clock_snapshots(sc
));
1053 /* Write default clock class */
1054 if (bt_stream_class_borrow_default_clock_class_const(sc
)) {
1056 write_prop_name(ctx
, "Default clock class");
1057 g_string_append_c(ctx
->str
, ':');
1060 write_clock_class_prop_lines(ctx
,
1061 bt_stream_class_borrow_default_clock_class_const(sc
));
1065 fc
= bt_stream_class_borrow_packet_context_field_class_const(sc
);
1067 write_root_field_class(ctx
, "Packet context field class", fc
);
1070 fc
= bt_stream_class_borrow_event_common_context_field_class_const(sc
);
1072 write_root_field_class(ctx
, "Event common context field class",
1076 for (i
= 0; i
< bt_stream_class_get_event_class_count(sc
); i
++) {
1077 g_ptr_array_add(event_classes
,
1078 (gpointer
) bt_stream_class_borrow_event_class_by_index_const(
1082 g_ptr_array_sort(event_classes
, (GCompareFunc
) compare_event_classes
);
1084 for (i
= 0; i
< event_classes
->len
; i
++) {
1085 write_event_class(ctx
, event_classes
->pdata
[i
]);
1089 g_ptr_array_free(event_classes
, TRUE
);
1093 gint
compare_stream_classes(const bt_stream_class
**a
, const bt_stream_class
**b
)
1095 uint64_t id_a
= bt_stream_class_get_id(*a
);
1096 uint64_t id_b
= bt_stream_class_get_id(*b
);
1100 } else if (id_a
> id_b
) {
1108 gint
compare_strings(const char **a
, const char **b
)
1110 return strcmp(*a
, *b
);
1114 void write_trace_class(struct details_write_ctx
*ctx
, const bt_trace_class
*tc
)
1116 GPtrArray
*stream_classes
= g_ptr_array_new();
1118 bool printed_prop
= false;
1121 write_obj_type_name(ctx
, "Trace class");
1123 for (i
= 0; i
< bt_trace_class_get_stream_class_count(tc
); i
++) {
1124 g_ptr_array_add(stream_classes
,
1125 (gpointer
) bt_trace_class_borrow_stream_class_by_index_const(
1129 g_ptr_array_sort(stream_classes
, (GCompareFunc
) compare_stream_classes
);
1131 if (stream_classes
->len
> 0) {
1132 if (!printed_prop
) {
1133 g_string_append(ctx
->str
, ":\n");
1134 printed_prop
= true;
1140 for (i
= 0; i
< stream_classes
->len
; i
++) {
1141 write_stream_class(ctx
, stream_classes
->pdata
[i
]);
1144 if (!printed_prop
) {
1149 g_ptr_array_free(stream_classes
, TRUE
);
1153 int try_write_meta(struct details_write_ctx
*ctx
, const bt_trace_class
*tc
,
1154 const bt_stream_class
*sc
, const bt_event_class
*ec
)
1160 if (details_need_to_write_trace_class(ctx
, tc
)) {
1163 if (ctx
->details_comp
->cfg
.compact
&&
1164 ctx
->details_comp
->printed_something
) {
1166 * There are no empty line between messages in
1167 * compact mode, so write one here to decouple
1168 * the trace class from the next message.
1174 * write_trace_class() also writes all its stream
1175 * classes their event classes, so we don't need to
1178 write_trace_class(ctx
, tc
);
1182 * Mark this trace class as written, as well as all
1183 * its stream classes and their event classes.
1185 ret
= details_did_write_trace_class(ctx
, tc
);
1190 for (sc_i
= 0; sc_i
< bt_trace_class_get_stream_class_count(tc
);
1193 const bt_stream_class
*tc_sc
=
1194 bt_trace_class_borrow_stream_class_by_index_const(
1197 details_did_write_meta_object(ctx
, tc
, tc_sc
);
1199 for (ec_i
= 0; ec_i
<
1200 bt_stream_class_get_event_class_count(tc_sc
);
1202 details_did_write_meta_object(ctx
, tc
,
1203 bt_stream_class_borrow_event_class_by_index_const(
1211 if (sc
&& details_need_to_write_meta_object(ctx
, tc
, sc
)) {
1216 if (ctx
->details_comp
->cfg
.compact
&&
1217 ctx
->details_comp
->printed_something
) {
1219 * There are no empty line between messages in
1220 * compact mode, so write one here to decouple
1221 * the stream class from the next message.
1227 * write_stream_class() also writes all its event
1228 * classes, so we don't need to rewrite `ec`.
1230 write_stream_class(ctx
, sc
);
1234 * Mark this stream class as written, as well as all its
1237 details_did_write_meta_object(ctx
, tc
, sc
);
1239 for (ec_i
= 0; ec_i
<
1240 bt_stream_class_get_event_class_count(sc
);
1242 details_did_write_meta_object(ctx
, tc
,
1243 bt_stream_class_borrow_event_class_by_index_const(
1250 if (ec
&& details_need_to_write_meta_object(ctx
, tc
, ec
)) {
1253 if (ctx
->details_comp
->cfg
.compact
&&
1254 ctx
->details_comp
->printed_something
) {
1256 * There are no empty line between messages in
1257 * compact mode, so write one here to decouple
1258 * the event class from the next message.
1263 write_event_class(ctx
, ec
);
1265 details_did_write_meta_object(ctx
, tc
, ec
);
1274 void write_time_str(struct details_write_ctx
*ctx
, const char *str
)
1276 if (!ctx
->details_comp
->cfg
.with_time
) {
1280 g_string_append_printf(ctx
->str
, "[%s%s%s%s]",
1281 color_bold(ctx
), color_fg_blue(ctx
), str
, color_reset(ctx
));
1283 if (ctx
->details_comp
->cfg
.compact
) {
1294 void write_time(struct details_write_ctx
*ctx
, const bt_clock_snapshot
*cs
)
1296 bt_clock_snapshot_get_ns_from_origin_status cs_status
;
1297 int64_t ns_from_origin
;
1300 if (!ctx
->details_comp
->cfg
.with_time
) {
1304 format_uint(buf
, bt_clock_snapshot_get_value(cs
), 10);
1305 g_string_append_printf(ctx
->str
, "[%s%s%s%s%s",
1306 color_bold(ctx
), color_fg_blue(ctx
), buf
,
1308 ctx
->details_comp
->cfg
.compact
? "" : " cycles");
1309 cs_status
= bt_clock_snapshot_get_ns_from_origin(cs
, &ns_from_origin
);
1310 if (cs_status
== BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OK
) {
1311 format_int(buf
, ns_from_origin
, 10);
1312 g_string_append_printf(ctx
->str
, "%s %s%s%s%s%s",
1313 ctx
->details_comp
->cfg
.compact
? "" : ",",
1314 color_bold(ctx
), color_fg_blue(ctx
), buf
,
1316 ctx
->details_comp
->cfg
.compact
? "" : " ns from origin");
1319 g_string_append(ctx
->str
, "]");
1321 if (ctx
->details_comp
->cfg
.compact
) {
1332 int write_message_follow_tag(struct details_write_ctx
*ctx
,
1333 const bt_stream
*stream
)
1336 uint64_t unique_trace_id
;
1337 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
1338 const bt_trace
*trace
= bt_stream_borrow_trace_const(stream
);
1340 ret
= details_trace_unique_id(ctx
, trace
, &unique_trace_id
);
1345 if (ctx
->details_comp
->cfg
.compact
) {
1346 g_string_append_printf(ctx
->str
,
1347 "%s{%s%" PRIu64
" %" PRIu64
" %" PRIu64
"%s%s}%s ",
1348 color_fg_cyan(ctx
), color_bold(ctx
),
1349 unique_trace_id
, bt_stream_class_get_id(sc
),
1350 bt_stream_get_id(stream
),
1351 color_reset(ctx
), color_fg_cyan(ctx
), color_reset(ctx
));
1353 g_string_append_printf(ctx
->str
,
1354 "%s{Trace %s%" PRIu64
"%s%s, Stream class ID %s%" PRIu64
"%s%s, Stream ID %s%" PRIu64
"%s%s}%s\n",
1356 color_bold(ctx
), unique_trace_id
,
1357 color_reset(ctx
), color_fg_cyan(ctx
),
1358 color_bold(ctx
), bt_stream_class_get_id(sc
),
1359 color_reset(ctx
), color_fg_cyan(ctx
),
1360 color_bold(ctx
), bt_stream_get_id(stream
),
1361 color_reset(ctx
), color_fg_cyan(ctx
),
1370 void write_field(struct details_write_ctx
*ctx
, const bt_field
*field
,
1374 bt_field_class_type fc_type
= bt_field_get_class_type(field
);
1375 const bt_field_class
*fc
;
1378 /* Write field's name */
1380 write_compound_member_name(ctx
, name
);
1383 /* Write field's value */
1385 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
1386 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1387 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
1388 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1390 unsigned int fmt_base
;
1391 bt_field_class_integer_preferred_display_base base
;
1393 fc
= bt_field_borrow_class_const(field
);
1394 base
= bt_field_class_integer_get_preferred_display_base(fc
);
1397 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
:
1400 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
:
1403 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
:
1406 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
:
1413 if (fc_type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
1414 fc_type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
) {
1416 bt_field_unsigned_integer_get_value(field
),
1419 write_uint_str_prop_value(ctx
, buf
);
1422 bt_field_signed_integer_get_value(field
),
1425 write_int_str_prop_value(ctx
, buf
);
1430 case BT_FIELD_CLASS_TYPE_REAL
:
1432 write_float_prop_value(ctx
, bt_field_real_get_value(field
));
1434 case BT_FIELD_CLASS_TYPE_STRING
:
1436 write_str_prop_value(ctx
, bt_field_string_get_value(field
));
1438 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1440 uint64_t member_count
;
1442 fc
= bt_field_borrow_class_const(field
);
1443 member_count
= bt_field_class_structure_get_member_count(fc
);
1445 if (member_count
> 0) {
1448 for (i
= 0; i
< member_count
; i
++) {
1449 const bt_field_class_structure_member
*member
=
1450 bt_field_class_structure_borrow_member_by_index_const(
1452 const bt_field
*member_field
=
1453 bt_field_structure_borrow_member_field_by_index_const(
1457 write_field(ctx
, member_field
,
1458 bt_field_class_structure_member_get_name(member
));
1463 g_string_append(ctx
->str
, " Empty");
1468 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1469 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
1471 uint64_t length
= bt_field_array_get_length(field
);
1474 g_string_append(ctx
->str
, " Empty");
1476 g_string_append(ctx
->str
, " Length ");
1477 write_uint_prop_value(ctx
, length
);
1478 g_string_append_c(ctx
->str
, ':');
1483 for (i
= 0; i
< length
; i
++) {
1484 const bt_field
*elem_field
=
1485 bt_field_array_borrow_element_field_by_index_const(
1489 write_array_index(ctx
, i
);
1490 write_field(ctx
, elem_field
, NULL
);
1496 case BT_FIELD_CLASS_TYPE_VARIANT
:
1498 bt_field_variant_borrow_selected_option_field_const(
1507 void write_root_field(struct details_write_ctx
*ctx
, const char *name
,
1508 const bt_field
*field
)
1513 write_prop_name(ctx
, name
);
1514 g_string_append(ctx
->str
, ":");
1515 write_field(ctx
, field
, NULL
);
1520 int write_event_message(struct details_write_ctx
*ctx
,
1521 const bt_message
*msg
)
1524 const bt_event
*event
= bt_message_event_borrow_event_const(msg
);
1525 const bt_stream
*stream
= bt_event_borrow_stream_const(event
);
1526 const bt_event_class
*ec
= bt_event_borrow_class_const(event
);
1527 const bt_stream_class
*sc
= bt_event_class_borrow_stream_class_const(ec
);
1528 const bt_trace_class
*tc
= bt_stream_class_borrow_trace_class_const(sc
);
1529 const char *ec_name
;
1530 const bt_field
*field
;
1532 ret
= try_write_meta(ctx
, tc
, sc
, ec
);
1538 if (bt_stream_class_borrow_default_clock_class_const(sc
)) {
1540 bt_message_event_borrow_default_clock_snapshot_const(
1544 /* Write follow tag for message */
1545 ret
= write_message_follow_tag(ctx
, stream
);
1550 /* Write object's basic properties */
1551 write_obj_type_name(ctx
, "Event");
1552 ec_name
= bt_event_class_get_name(ec
);
1554 g_string_append_printf(ctx
->str
, " `%s%s%s`",
1555 color_fg_green(ctx
), ec_name
, color_reset(ctx
));
1558 g_string_append(ctx
->str
, " (");
1560 if (!ctx
->details_comp
->cfg
.compact
) {
1561 g_string_append(ctx
->str
, "Class ID ");
1564 write_uint_prop_value(ctx
, bt_event_class_get_id(ec
));
1565 g_string_append(ctx
->str
, ")");
1567 if (ctx
->details_comp
->cfg
.compact
) {
1573 g_string_append(ctx
->str
, ":\n");
1575 field
= bt_event_borrow_common_context_field_const(event
);
1577 write_root_field(ctx
, "Common context", field
);
1580 field
= bt_event_borrow_specific_context_field_const(event
);
1582 write_root_field(ctx
, "Specific context", field
);
1585 field
= bt_event_borrow_payload_field_const(event
);
1587 write_root_field(ctx
, "Payload", field
);
1598 gint
compare_streams(const bt_stream
**a
, const bt_stream
**b
)
1600 uint64_t id_a
= bt_stream_get_id(*a
);
1601 uint64_t id_b
= bt_stream_get_id(*b
);
1605 } else if (id_a
> id_b
) {
1608 const bt_stream_class
*a_sc
= bt_stream_borrow_class_const(*a
);
1609 const bt_stream_class
*b_sc
= bt_stream_borrow_class_const(*b
);
1610 uint64_t a_sc_id
= bt_stream_class_get_id(a_sc
);
1611 uint64_t b_sc_id
= bt_stream_class_get_id(b_sc
);
1613 if (a_sc_id
< b_sc_id
) {
1615 } else if (a_sc_id
> b_sc_id
) {
1624 void write_trace(struct details_write_ctx
*ctx
, const bt_trace
*trace
)
1627 GPtrArray
*streams
= g_ptr_array_new();
1629 bool printed_prop
= false;
1630 GPtrArray
*env_names
= g_ptr_array_new();
1634 write_obj_type_name(ctx
, "Trace");
1637 if (ctx
->details_comp
->cfg
.with_trace_name
) {
1638 name
= bt_trace_get_name(trace
);
1640 g_string_append(ctx
->str
, " `");
1641 write_str_prop_value(ctx
, name
);
1642 g_string_append(ctx
->str
, "`");
1646 /* Write properties */
1650 if (ctx
->details_comp
->cfg
.with_uuid
) {
1651 bt_uuid uuid
= bt_trace_get_uuid(trace
);
1654 if (!printed_prop
) {
1655 g_string_append(ctx
->str
, ":\n");
1656 printed_prop
= true;
1659 write_uuid_prop_line(ctx
, "UUID", uuid
);
1663 /* Write environment */
1664 env_count
= bt_trace_get_environment_entry_count(trace
);
1665 if (env_count
> 0) {
1666 if (!printed_prop
) {
1667 g_string_append(ctx
->str
, ":\n");
1668 printed_prop
= true;
1672 write_prop_name(ctx
, "Environment");
1673 g_string_append(ctx
->str
, " (");
1674 write_uint_prop_value(ctx
, env_count
);
1675 g_string_append_printf(ctx
->str
, " entr%s):",
1676 env_count
== 1 ? "y" : "ies");
1680 for (i
= 0; i
< env_count
; i
++) {
1682 const bt_value
*value
;
1684 bt_trace_borrow_environment_entry_by_index_const(
1685 trace
, i
, &name
, &value
);
1686 g_ptr_array_add(env_names
, (gpointer
) name
);
1689 g_ptr_array_sort(env_names
, (GCompareFunc
) compare_strings
);
1691 for (i
= 0; i
< env_names
->len
; i
++) {
1692 const char *name
= env_names
->pdata
[i
];
1693 const bt_value
*value
=
1694 bt_trace_borrow_environment_entry_value_by_name_const(
1698 write_compound_member_name(ctx
, name
);
1701 if (bt_value_get_type(value
) ==
1702 BT_VALUE_TYPE_SIGNED_INTEGER
) {
1703 write_int_prop_value(ctx
,
1704 bt_value_signed_integer_get(value
));
1705 } else if (bt_value_get_type(value
) ==
1706 BT_VALUE_TYPE_STRING
) {
1707 write_str_prop_value(ctx
,
1708 bt_value_string_get(value
));
1719 for (i
= 0; i
< bt_trace_get_stream_count(trace
); i
++) {
1720 g_ptr_array_add(streams
,
1721 (gpointer
) bt_trace_borrow_stream_by_index_const(
1725 g_ptr_array_sort(streams
, (GCompareFunc
) compare_streams
);
1727 if (streams
->len
> 0 && !printed_prop
) {
1728 g_string_append(ctx
->str
, ":\n");
1729 printed_prop
= true;
1732 for (i
= 0; i
< streams
->len
; i
++) {
1733 const bt_stream
*stream
= streams
->pdata
[i
];
1736 write_obj_type_name(ctx
, "Stream");
1737 g_string_append(ctx
->str
, " (ID ");
1738 write_uint_prop_value(ctx
, bt_stream_get_id(stream
));
1739 g_string_append(ctx
->str
, ", Class ID ");
1740 write_uint_prop_value(ctx
, bt_stream_class_get_id(
1741 bt_stream_borrow_class_const(stream
)));
1742 g_string_append(ctx
->str
, ")");
1748 if (!printed_prop
) {
1752 g_ptr_array_free(streams
, TRUE
);
1753 g_ptr_array_free(env_names
, TRUE
);
1757 int write_stream_beginning_message(struct details_write_ctx
*ctx
,
1758 const bt_message
*msg
)
1761 const bt_stream
*stream
=
1762 bt_message_stream_beginning_borrow_stream_const(msg
);
1763 const bt_trace
*trace
= bt_stream_borrow_trace_const(stream
);
1764 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
1765 const bt_clock_class
*cc
= bt_stream_class_borrow_default_clock_class_const(sc
);
1766 const bt_trace_class
*tc
= bt_stream_class_borrow_trace_class_const(sc
);
1769 ret
= try_write_meta(ctx
, tc
, sc
, NULL
);
1776 const bt_clock_snapshot
*cs
;
1777 bt_message_stream_clock_snapshot_state cs_state
=
1778 bt_message_stream_beginning_borrow_default_clock_snapshot_const(msg
, &cs
);
1780 if (cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1781 write_time(ctx
, cs
);
1783 write_time_str(ctx
, "Unknown");
1787 /* Write follow tag for message */
1788 ret
= write_message_follow_tag(ctx
, stream
);
1793 /* Write stream properties */
1794 write_obj_type_name(ctx
, "Stream beginning");
1796 if (ctx
->details_comp
->cfg
.compact
) {
1801 g_string_append(ctx
->str
, ":\n");
1804 if (ctx
->details_comp
->cfg
.with_stream_name
) {
1805 name
= bt_stream_get_name(stream
);
1807 write_str_prop_line(ctx
, "Name", name
);
1811 if (ctx
->details_comp
->cfg
.with_stream_class_name
) {
1812 name
= bt_stream_class_get_name(sc
);
1814 write_str_prop_line(ctx
, "Class name", name
);
1818 write_trace(ctx
, trace
);
1826 int write_stream_end_message(struct details_write_ctx
*ctx
,
1827 const bt_message
*msg
)
1830 const bt_stream
*stream
=
1831 bt_message_stream_end_borrow_stream_const(msg
);
1832 const bt_stream_class
*sc
=
1833 bt_stream_borrow_class_const(stream
);
1834 const bt_clock_class
*cc
=
1835 bt_stream_class_borrow_default_clock_class_const(sc
);
1839 const bt_clock_snapshot
*cs
;
1840 bt_message_stream_clock_snapshot_state cs_state
=
1841 bt_message_stream_end_borrow_default_clock_snapshot_const(msg
, &cs
);
1843 if (cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1844 write_time(ctx
, cs
);
1846 write_time_str(ctx
, "Unknown");
1850 /* Write follow tag for message */
1851 ret
= write_message_follow_tag(ctx
, stream
);
1856 /* Write stream properties */
1857 write_obj_type_name(ctx
, "Stream end\n");
1864 int write_packet_beginning_message(struct details_write_ctx
*ctx
,
1865 const bt_message
*msg
)
1868 const bt_packet
*packet
=
1869 bt_message_packet_beginning_borrow_packet_const(msg
);
1870 const bt_stream
*stream
= bt_packet_borrow_stream_const(packet
);
1871 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
1872 const bt_field
*field
;
1875 if (bt_stream_class_packets_have_beginning_default_clock_snapshot(sc
)) {
1877 bt_message_packet_beginning_borrow_default_clock_snapshot_const(
1881 /* Write follow tag for message */
1882 ret
= write_message_follow_tag(ctx
, stream
);
1887 write_obj_type_name(ctx
, "Packet beginning");
1889 if (ctx
->details_comp
->cfg
.compact
) {
1895 g_string_append(ctx
->str
, ":\n");
1897 field
= bt_packet_borrow_context_field_const(packet
);
1899 write_root_field(ctx
, "Context", field
);
1909 int write_discarded_items_message(struct details_write_ctx
*ctx
,
1910 const char *name
, const bt_stream
*stream
,
1911 const bt_clock_snapshot
*beginning_cs
,
1912 const bt_clock_snapshot
*end_cs
, uint64_t count
)
1918 write_time(ctx
, beginning_cs
);
1920 write_time(ctx
, end_cs
);
1923 /* Write follow tag for message */
1924 ret
= write_message_follow_tag(ctx
, stream
);
1929 write_obj_type_name(ctx
, "Discarded ");
1930 write_obj_type_name(ctx
, name
);
1933 if (count
== UINT64_C(-1)) {
1938 g_string_append(ctx
->str
, " (");
1939 write_uint_prop_value(ctx
, count
);
1940 g_string_append_printf(ctx
->str
, " %s)\n", name
);
1947 int write_discarded_events_message(struct details_write_ctx
*ctx
,
1948 const bt_message
*msg
)
1950 const bt_stream
*stream
= bt_message_discarded_events_borrow_stream_const(
1952 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
1953 const bt_clock_snapshot
*beginning_cs
= NULL
;
1954 const bt_clock_snapshot
*end_cs
= NULL
;
1957 if (bt_stream_class_discarded_events_have_default_clock_snapshots(sc
)) {
1959 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
1962 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
1966 if (bt_message_discarded_events_get_count(msg
, &count
) !=
1967 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
1968 count
= UINT64_C(-1);
1971 return write_discarded_items_message(ctx
, "events", stream
,
1972 beginning_cs
, end_cs
, count
);
1976 int write_discarded_packets_message(struct details_write_ctx
*ctx
,
1977 const bt_message
*msg
)
1979 const bt_stream
*stream
= bt_message_discarded_packets_borrow_stream_const(
1981 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
1982 const bt_clock_snapshot
*beginning_cs
= NULL
;
1983 const bt_clock_snapshot
*end_cs
= NULL
;
1986 if (bt_stream_class_discarded_packets_have_default_clock_snapshots(sc
)) {
1988 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
1991 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
1995 if (bt_message_discarded_packets_get_count(msg
, &count
) !=
1996 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
1997 count
= UINT64_C(-1);
2000 return write_discarded_items_message(ctx
, "packets", stream
,
2001 beginning_cs
, end_cs
, count
);
2005 int write_packet_end_message(struct details_write_ctx
*ctx
,
2006 const bt_message
*msg
)
2009 const bt_packet
*packet
=
2010 bt_message_packet_end_borrow_packet_const(msg
);
2011 const bt_stream
*stream
= bt_packet_borrow_stream_const(packet
);
2012 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2015 if (bt_stream_class_packets_have_end_default_clock_snapshot(sc
)) {
2017 bt_message_packet_end_borrow_default_clock_snapshot_const(
2021 /* Write follow tag for message */
2022 ret
= write_message_follow_tag(ctx
, stream
);
2027 write_obj_type_name(ctx
, "Packet end");
2035 int write_message_iterator_inactivity_message(struct details_write_ctx
*ctx
,
2036 const bt_message
*msg
)
2039 const bt_clock_snapshot
*cs
=
2040 bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
2044 write_time(ctx
, cs
);
2045 write_obj_type_name(ctx
, "Message iterator inactivity");
2047 if (ctx
->details_comp
->cfg
.compact
) {
2052 /* Write clock class properties */
2053 g_string_append(ctx
->str
, ":\n");
2056 write_prop_name(ctx
, "Clock class");
2057 g_string_append_c(ctx
->str
, ':');
2060 write_clock_class_prop_lines(ctx
,
2061 bt_clock_snapshot_borrow_clock_class_const(cs
));
2069 int details_write_message(struct details_comp
*details_comp
,
2070 const bt_message
*msg
)
2073 struct details_write_ctx ctx
= {
2074 .details_comp
= details_comp
,
2075 .str
= details_comp
->str
,
2079 /* Reset output buffer */
2080 g_string_assign(details_comp
->str
, "");
2082 if (details_comp
->printed_something
&& !details_comp
->cfg
.compact
) {
2086 switch (bt_message_get_type(msg
)) {
2087 case BT_MESSAGE_TYPE_EVENT
:
2088 ret
= write_event_message(&ctx
, msg
);
2090 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
2091 ret
= write_message_iterator_inactivity_message(&ctx
, msg
);
2093 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
2094 ret
= write_stream_beginning_message(&ctx
, msg
);
2096 case BT_MESSAGE_TYPE_STREAM_END
:
2097 ret
= write_stream_end_message(&ctx
, msg
);
2099 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
2100 ret
= write_packet_beginning_message(&ctx
, msg
);
2102 case BT_MESSAGE_TYPE_PACKET_END
:
2103 ret
= write_packet_end_message(&ctx
, msg
);
2105 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
2106 ret
= write_discarded_events_message(&ctx
, msg
);
2108 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
2109 ret
= write_discarded_packets_message(&ctx
, msg
);