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_none_prop_value(struct details_write_ctx
*ctx
, const char *value
)
236 g_string_append_printf(ctx
->str
, "%s%s%s%s",
237 color_bold(ctx
), color_fg_magenta(ctx
),
238 value
, color_reset(ctx
));
242 void write_uint_str_prop_value(struct details_write_ctx
*ctx
, const char *value
)
244 write_str_prop_value(ctx
, value
);
248 void write_uint_prop_value(struct details_write_ctx
*ctx
, uint64_t value
)
252 format_uint(buf
, value
, 10);
253 write_uint_str_prop_value(ctx
, buf
);
257 void write_int_prop_value(struct details_write_ctx
*ctx
, int64_t value
)
261 format_int(buf
, value
, 10);
262 write_uint_str_prop_value(ctx
, buf
);
266 void write_float_prop_value(struct details_write_ctx
*ctx
, double value
)
268 g_string_append_printf(ctx
->str
, "%s%f%s",
269 color_bold(ctx
), value
, color_reset(ctx
));
273 void write_str_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
274 const char *prop_value
)
276 BT_ASSERT(prop_value
);
278 write_prop_name(ctx
, prop_name
);
279 g_string_append(ctx
->str
, ": ");
280 write_str_prop_value(ctx
, prop_value
);
285 void write_uint_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
289 write_prop_name(ctx
, prop_name
);
290 g_string_append(ctx
->str
, ": ");
291 write_uint_prop_value(ctx
, prop_value
);
296 void write_int_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
300 write_prop_name(ctx
, prop_name
);
301 g_string_append(ctx
->str
, ": ");
302 write_int_prop_value(ctx
, prop_value
);
307 void write_int_str_prop_value(struct details_write_ctx
*ctx
, const char *value
)
309 write_str_prop_value(ctx
, value
);
313 void write_bool_prop_value(struct details_write_ctx
*ctx
, bt_bool prop_value
)
317 g_string_append(ctx
->str
, color_bold(ctx
));
320 g_string_append(ctx
->str
, color_fg_green(ctx
));
323 g_string_append(ctx
->str
, color_fg_red(ctx
));
327 g_string_append_printf(ctx
->str
, "%s%s", str
, color_reset(ctx
));
331 void write_bool_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
335 write_prop_name(ctx
, prop_name
);
336 g_string_append(ctx
->str
, ": ");
337 write_bool_prop_value(ctx
, prop_value
);
342 void write_uuid_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
347 write_prop_name(ctx
, prop_name
);
348 g_string_append_printf(ctx
->str
,
349 ": %s" BT_UUID_FMT
"%s\n",
351 BT_UUID_FMT_VALUES(uuid
),
356 void write_int_field_class_props(struct details_write_ctx
*ctx
,
357 const bt_field_class
*fc
, bool close
)
359 g_string_append_printf(ctx
->str
, "(%s%" PRIu64
"-bit%s, Base ",
361 bt_field_class_integer_get_field_value_range(fc
),
364 switch (bt_field_class_integer_get_preferred_display_base(fc
)) {
365 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
:
366 write_uint_prop_value(ctx
, 2);
368 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
:
369 write_uint_prop_value(ctx
, 8);
371 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
:
372 write_uint_prop_value(ctx
, 10);
374 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
:
375 write_uint_prop_value(ctx
, 16);
382 g_string_append(ctx
->str
, ")");
398 struct enum_field_class_mapping
{
402 /* Array of `struct int_range` */
407 gint
compare_enum_field_class_mappings(struct enum_field_class_mapping
**a
,
408 struct enum_field_class_mapping
**b
)
410 return strcmp((*a
)->label
, (*b
)->label
);
414 gint
compare_int_ranges_signed(struct int_range
*a
, struct int_range
*b
)
417 if (a
->lower
.i
< b
->lower
.i
) {
419 } else if (a
->lower
.i
> b
->lower
.i
) {
422 if (a
->upper
.i
< b
->upper
.i
) {
424 } else if (a
->upper
.i
> b
->upper
.i
) {
433 gint
compare_int_ranges_unsigned(struct int_range
*a
, struct int_range
*b
)
435 if (a
->lower
.u
< b
->lower
.u
) {
437 } else if (a
->lower
.u
> b
->lower
.u
) {
440 if (a
->upper
.u
< b
->upper
.u
) {
442 } else if (a
->upper
.u
> b
->upper
.u
) {
451 GArray
*range_set_to_int_ranges(const void *spec_range_set
, bool is_signed
)
454 const bt_integer_range_set
*range_set
;
455 GArray
*ranges
= g_array_new(FALSE
, TRUE
, sizeof(struct int_range
));
462 range_set
= bt_integer_range_set_signed_as_range_set_const(
465 range_set
= bt_integer_range_set_unsigned_as_range_set_const(
469 for (i
= 0; i
< bt_integer_range_set_get_range_count(range_set
); i
++) {
470 struct int_range range
;
473 const bt_integer_range_signed
*orig_range
=
474 bt_integer_range_set_signed_borrow_range_by_index_const(
477 range
.lower
.i
= bt_integer_range_signed_get_lower(orig_range
);
478 range
.upper
.i
= bt_integer_range_signed_get_upper(orig_range
);
480 const bt_integer_range_unsigned
*orig_range
=
481 bt_integer_range_set_unsigned_borrow_range_by_index_const(
484 range
.lower
.u
= bt_integer_range_unsigned_get_lower(orig_range
);
485 range
.upper
.u
= bt_integer_range_unsigned_get_upper(orig_range
);
488 g_array_append_val(ranges
, range
);
492 g_array_sort(ranges
, (GCompareFunc
) compare_int_ranges_signed
);
495 (GCompareFunc
) compare_int_ranges_unsigned
);
503 void destroy_enum_field_class_mapping(struct enum_field_class_mapping
*mapping
)
505 if (mapping
->ranges
) {
506 g_array_free(mapping
->ranges
, TRUE
);
507 mapping
->ranges
= NULL
;
514 struct int_range
*int_range_at(GArray
*ranges
, uint64_t index
)
516 return &g_array_index(ranges
, struct int_range
, index
);
520 void write_int_range(struct details_write_ctx
*ctx
,
521 struct int_range
*range
, bool is_signed
)
523 g_string_append(ctx
->str
, "[");
526 write_int_prop_value(ctx
, range
->lower
.i
);
528 write_int_prop_value(ctx
, range
->lower
.u
);
531 if (range
->lower
.u
!= range
->upper
.u
) {
532 g_string_append(ctx
->str
, ", ");
535 write_int_prop_value(ctx
, range
->upper
.i
);
537 write_int_prop_value(ctx
, range
->upper
.u
);
541 g_string_append(ctx
->str
, "]");
545 void write_enum_field_class_mappings(struct details_write_ctx
*ctx
,
546 const bt_field_class
*fc
)
551 bool is_signed
= bt_field_class_get_type(fc
) ==
552 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
;
554 mappings
= g_ptr_array_new_with_free_func(
555 (GDestroyNotify
) destroy_enum_field_class_mapping
);
559 * Copy field class's mappings to our own arrays and structures
562 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(fc
); i
++) {
563 const void *fc_mapping
;
564 const void *fc_range_set
;
565 struct enum_field_class_mapping
*mapping
= g_new0(
566 struct enum_field_class_mapping
, 1);
571 fc_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
573 fc_range_set
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
576 fc_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
578 fc_range_set
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
582 mapping
->label
= bt_field_class_enumeration_mapping_get_label(
583 bt_field_class_enumeration_signed_mapping_as_mapping_const(
585 mapping
->ranges
= range_set_to_int_ranges(fc_range_set
,
587 BT_ASSERT(mapping
->ranges
);
588 g_ptr_array_add(mappings
, mapping
);
591 /* Sort mappings (ranges are already sorted within mappings) */
592 g_ptr_array_sort(mappings
,
593 (GCompareFunc
) compare_enum_field_class_mappings
);
596 for (i
= 0; i
< mappings
->len
; i
++) {
597 struct enum_field_class_mapping
*mapping
= mappings
->pdata
[i
];
600 write_compound_member_name(ctx
, mapping
->label
);
602 for (range_i
= 0; range_i
< mapping
->ranges
->len
; range_i
++) {
605 int_range_at(mapping
->ranges
, range_i
),
610 g_ptr_array_free(mappings
, TRUE
);
614 void write_field_path(struct details_write_ctx
*ctx
,
615 const bt_field_path
*field_path
)
619 g_string_append_c(ctx
->str
, '[');
621 switch (bt_field_path_get_root_scope(field_path
)) {
622 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
:
623 write_str_prop_value(ctx
, "Packet context");
625 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
:
626 write_str_prop_value(ctx
, "Event common context");
628 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
:
629 write_str_prop_value(ctx
, "Event specific context");
631 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
:
632 write_str_prop_value(ctx
, "Event payload");
638 g_string_append(ctx
->str
, ": ");
640 for (i
= 0; i
< bt_field_path_get_item_count(field_path
); i
++) {
641 const bt_field_path_item
*fp_item
=
642 bt_field_path_borrow_item_by_index_const(field_path
, i
);
645 g_string_append(ctx
->str
, ", ");
648 switch (bt_field_path_item_get_type(fp_item
)) {
649 case BT_FIELD_PATH_ITEM_TYPE_INDEX
:
650 write_uint_prop_value(ctx
,
651 bt_field_path_item_index_get_index(fp_item
));
653 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
654 write_str_prop_value(ctx
, "<current>");
661 g_string_append_c(ctx
->str
, ']');
665 void write_field_class(struct details_write_ctx
*ctx
, const bt_field_class
*fc
);
668 void write_variant_field_class_option(struct details_write_ctx
*ctx
,
669 const bt_field_class
*fc
, uint64_t index
)
671 bt_field_class_type fc_type
= bt_field_class_get_type(fc
);
672 const bt_field_class_variant_option
*option
=
673 bt_field_class_variant_borrow_option_by_index_const(
675 const void *orig_ranges
;
676 GArray
*int_ranges
= NULL
;
680 write_compound_member_name(ctx
,
681 bt_field_class_variant_option_get_name(option
));
683 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
) {
684 const bt_field_class_variant_with_selector_unsigned_option
*spec_opt
=
685 bt_field_class_variant_with_selector_unsigned_borrow_option_by_index_const(
689 bt_field_class_variant_with_selector_unsigned_option_borrow_ranges_const(
693 const bt_field_class_variant_with_selector_signed_option
*spec_opt
=
694 bt_field_class_variant_with_selector_signed_borrow_option_by_index_const(
698 bt_field_class_variant_with_selector_signed_option_borrow_ranges_const(
706 int_ranges
= range_set_to_int_ranges(orig_ranges
, is_signed
);
707 BT_ASSERT(int_ranges
);
709 for (i
= 0; i
< int_ranges
->len
; i
++) {
710 struct int_range
*range
= int_range_at(int_ranges
, i
);
713 write_int_range(ctx
, range
, is_signed
);
716 g_string_append(ctx
->str
, ": ");
721 write_field_class(ctx
,
722 bt_field_class_variant_option_borrow_field_class_const(option
));
725 g_array_free(int_ranges
, TRUE
);
730 void write_variant_field_class(struct details_write_ctx
*ctx
,
731 const bt_field_class
*fc
)
733 bt_field_class_type fc_type
= bt_field_class_get_type(fc
);
734 uint64_t option_count
=
735 bt_field_class_variant_get_option_count(fc
);
736 const bt_field_path
*sel_field_path
= NULL
;
738 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
) {
740 bt_field_class_variant_with_selector_borrow_selector_field_path_const(
742 BT_ASSERT(sel_field_path
);
745 g_string_append(ctx
->str
, " (");
746 write_uint_prop_value(ctx
, option_count
);
747 g_string_append_printf(ctx
->str
, " option%s, ",
748 plural(option_count
));
750 if (sel_field_path
) {
751 g_string_append(ctx
->str
, "Selector field path ");
752 write_field_path(ctx
, sel_field_path
);
755 g_string_append_c(ctx
->str
, ')');
757 if (option_count
> 0) {
760 g_string_append_c(ctx
->str
, ':');
763 for (i
= 0; i
< option_count
; i
++) {
764 write_variant_field_class_option(ctx
, fc
, i
);
772 void write_field_class(struct details_write_ctx
*ctx
, const bt_field_class
*fc
)
776 bt_field_class_type fc_type
= bt_field_class_get_type(fc
);
778 /* Write field class's type */
780 case BT_FIELD_CLASS_TYPE_BOOL
:
783 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
784 type
= "Unsigned integer";
786 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
787 type
= "Signed integer";
789 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
790 type
= "Unsigned enumeration";
792 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
793 type
= "Signed enumeration";
795 case BT_FIELD_CLASS_TYPE_REAL
:
798 case BT_FIELD_CLASS_TYPE_STRING
:
801 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
804 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
805 type
= "Static array";
807 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
808 type
= "Dynamic array";
810 case BT_FIELD_CLASS_TYPE_OPTION
:
813 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
814 type
= "Variant (no selector)";
816 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
817 type
= "Variant (unsigned selector)";
819 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
820 type
= "Variant (signed selector)";
826 g_string_append_printf(ctx
->str
, "%s%s%s",
827 color_fg_blue(ctx
), type
, color_reset(ctx
));
829 /* Write field class's properties */
831 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
832 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
834 write_int_field_class_props(ctx
, fc
, true);
836 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
837 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
839 uint64_t mapping_count
=
840 bt_field_class_enumeration_get_mapping_count(fc
);
843 write_int_field_class_props(ctx
, fc
, false);
844 g_string_append(ctx
->str
, ", ");
845 write_uint_prop_value(ctx
, mapping_count
);
846 g_string_append_printf(ctx
->str
, " mapping%s)",
847 plural(mapping_count
));
849 if (mapping_count
> 0) {
850 g_string_append_c(ctx
->str
, ':');
852 write_enum_field_class_mappings(ctx
, fc
);
858 case BT_FIELD_CLASS_TYPE_REAL
:
859 if (bt_field_class_real_is_single_precision(fc
)) {
860 g_string_append(ctx
->str
, " (Single precision)");
862 g_string_append(ctx
->str
, " (Double precision)");
866 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
868 uint64_t member_count
=
869 bt_field_class_structure_get_member_count(fc
);
871 g_string_append(ctx
->str
, " (");
872 write_uint_prop_value(ctx
, member_count
);
873 g_string_append_printf(ctx
->str
, " member%s)",
874 plural(member_count
));
876 if (member_count
> 0) {
877 g_string_append_c(ctx
->str
, ':');
880 for (i
= 0; i
< member_count
; i
++) {
881 const bt_field_class_structure_member
*member
=
882 bt_field_class_structure_borrow_member_by_index_const(
886 write_compound_member_name(ctx
,
887 bt_field_class_structure_member_get_name(member
));
889 write_field_class(ctx
,
890 bt_field_class_structure_member_borrow_field_class_const(member
));
898 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
899 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
900 if (fc_type
== BT_FIELD_CLASS_TYPE_STATIC_ARRAY
) {
901 g_string_append(ctx
->str
, " (Length ");
902 write_uint_prop_value(ctx
,
903 bt_field_class_array_static_get_length(fc
));
904 g_string_append_c(ctx
->str
, ')');
906 const bt_field_path
*length_field_path
=
907 bt_field_class_array_dynamic_borrow_length_field_path_const(
910 if (length_field_path
) {
911 g_string_append(ctx
->str
, " (Length field path ");
912 write_field_path(ctx
, length_field_path
);
913 g_string_append_c(ctx
->str
, ')');
917 g_string_append_c(ctx
->str
, ':');
920 write_compound_member_name(ctx
, "Element");
922 write_field_class(ctx
,
923 bt_field_class_array_borrow_element_field_class_const(fc
));
926 case BT_FIELD_CLASS_TYPE_OPTION
:
928 const bt_field_path
*selector_field_path
=
929 bt_field_class_option_borrow_selector_field_path_const(fc
);
931 if (selector_field_path
) {
932 g_string_append(ctx
->str
, " (Selector field path ");
933 write_field_path(ctx
, selector_field_path
);
934 g_string_append_c(ctx
->str
, ')');
937 g_string_append_c(ctx
->str
, ':');
940 write_compound_member_name(ctx
, "Content");
942 write_field_class(ctx
,
943 bt_field_class_option_borrow_field_class_const(fc
));
947 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
948 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
949 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
950 write_variant_field_class(ctx
, fc
);
958 void write_root_field_class(struct details_write_ctx
*ctx
, const char *name
,
959 const bt_field_class
*fc
)
964 write_prop_name(ctx
, name
);
965 g_string_append(ctx
->str
, ": ");
966 write_field_class(ctx
, fc
);
971 void write_event_class(struct details_write_ctx
*ctx
, const bt_event_class
*ec
)
973 const char *name
= bt_event_class_get_name(ec
);
975 const bt_field_class
*fc
;
976 bt_event_class_log_level log_level
;
979 write_obj_type_name(ctx
, "Event class");
981 /* Write name and ID */
983 g_string_append_printf(ctx
->str
, " `%s%s%s`",
984 color_fg_green(ctx
), name
, color_reset(ctx
));
987 g_string_append(ctx
->str
, " (ID ");
988 write_uint_prop_value(ctx
, bt_event_class_get_id(ec
));
989 g_string_append(ctx
->str
, "):\n");
991 /* Write properties */
994 /* Write log level */
995 if (bt_event_class_get_log_level(ec
, &log_level
) ==
996 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
997 const char *ll_str
= NULL
;
1000 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
1001 ll_str
= "Emergency";
1003 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
1006 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
1007 ll_str
= "Critical";
1009 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
1012 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
1015 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
1018 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
1021 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
1022 ll_str
= "Debug (system)";
1024 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
1025 ll_str
= "Debug (program)";
1027 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
1028 ll_str
= "Debug (process)";
1030 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
1031 ll_str
= "Debug (module)";
1033 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
1034 ll_str
= "Debug (unit)";
1036 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
1037 ll_str
= "Debug (function)";
1039 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
1040 ll_str
= "Debug (line)";
1042 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
1049 write_str_prop_line(ctx
, "Log level", ll_str
);
1053 emf_uri
= bt_event_class_get_emf_uri(ec
);
1055 write_str_prop_line(ctx
, "EMF URI", emf_uri
);
1058 /* Write specific context field class */
1059 fc
= bt_event_class_borrow_specific_context_field_class_const(ec
);
1061 write_root_field_class(ctx
, "Specific context field class", fc
);
1064 /* Write payload field class */
1065 fc
= bt_event_class_borrow_payload_field_class_const(ec
);
1067 write_root_field_class(ctx
, "Payload field class", fc
);
1074 void write_clock_class_prop_lines(struct details_write_ctx
*ctx
,
1075 const bt_clock_class
*cc
)
1077 int64_t offset_seconds
;
1078 uint64_t offset_cycles
;
1081 str
= bt_clock_class_get_name(cc
);
1083 write_str_prop_line(ctx
, "Name", str
);
1086 str
= bt_clock_class_get_description(cc
);
1088 write_str_prop_line(ctx
, "Description", str
);
1091 write_uint_prop_line(ctx
, "Frequency (Hz)",
1092 bt_clock_class_get_frequency(cc
));
1093 write_uint_prop_line(ctx
, "Precision (cycles)",
1094 bt_clock_class_get_precision(cc
));
1095 bt_clock_class_get_offset(cc
, &offset_seconds
, &offset_cycles
);
1096 write_int_prop_line(ctx
, "Offset (s)", offset_seconds
);
1097 write_uint_prop_line(ctx
, "Offset (cycles)", offset_cycles
);
1098 write_bool_prop_line(ctx
, "Origin is Unix epoch",
1099 bt_clock_class_origin_is_unix_epoch(cc
));
1101 if (ctx
->details_comp
->cfg
.with_uuid
) {
1102 bt_uuid uuid
= bt_clock_class_get_uuid(cc
);
1105 write_uuid_prop_line(ctx
, "UUID", uuid
);
1111 gint
compare_event_classes(const bt_event_class
**a
, const bt_event_class
**b
)
1113 uint64_t id_a
= bt_event_class_get_id(*a
);
1114 uint64_t id_b
= bt_event_class_get_id(*b
);
1118 } else if (id_a
> id_b
) {
1126 void write_stream_class(struct details_write_ctx
*ctx
,
1127 const bt_stream_class
*sc
)
1129 const bt_field_class
*fc
;
1130 GPtrArray
*event_classes
= g_ptr_array_new();
1134 write_obj_type_name(ctx
, "Stream class");
1136 /* Write name and ID */
1137 if (ctx
->details_comp
->cfg
.with_stream_class_name
) {
1138 const char *name
= bt_stream_class_get_name(sc
);
1141 g_string_append(ctx
->str
, " `");
1142 write_str_prop_value(ctx
, name
);
1143 g_string_append(ctx
->str
, "`");
1147 g_string_append(ctx
->str
, " (ID ");
1148 write_uint_prop_value(ctx
, bt_stream_class_get_id(sc
));
1149 g_string_append(ctx
->str
, "):\n");
1151 /* Write properties */
1154 /* Write configuration */
1155 write_bool_prop_line(ctx
,
1156 "Supports packets", bt_stream_class_supports_packets(sc
));
1158 if (bt_stream_class_supports_packets(sc
)) {
1159 write_bool_prop_line(ctx
,
1160 "Packets have beginning default clock snapshot",
1161 bt_stream_class_packets_have_beginning_default_clock_snapshot(sc
));
1162 write_bool_prop_line(ctx
,
1163 "Packets have end default clock snapshot",
1164 bt_stream_class_packets_have_end_default_clock_snapshot(sc
));
1167 write_bool_prop_line(ctx
,
1168 "Supports discarded events",
1169 bt_stream_class_supports_discarded_events(sc
));
1171 if (bt_stream_class_supports_discarded_events(sc
)) {
1172 write_bool_prop_line(ctx
,
1173 "Discarded events have default clock snapshots",
1174 bt_stream_class_discarded_events_have_default_clock_snapshots(sc
));
1177 write_bool_prop_line(ctx
,
1178 "Supports discarded packets",
1179 bt_stream_class_supports_discarded_packets(sc
));
1181 if (bt_stream_class_supports_discarded_packets(sc
)) {
1182 write_bool_prop_line(ctx
,
1183 "Discarded packets have default clock snapshots",
1184 bt_stream_class_discarded_packets_have_default_clock_snapshots(sc
));
1187 /* Write default clock class */
1188 if (bt_stream_class_borrow_default_clock_class_const(sc
)) {
1190 write_prop_name(ctx
, "Default clock class");
1191 g_string_append_c(ctx
->str
, ':');
1194 write_clock_class_prop_lines(ctx
,
1195 bt_stream_class_borrow_default_clock_class_const(sc
));
1199 fc
= bt_stream_class_borrow_packet_context_field_class_const(sc
);
1201 write_root_field_class(ctx
, "Packet context field class", fc
);
1204 fc
= bt_stream_class_borrow_event_common_context_field_class_const(sc
);
1206 write_root_field_class(ctx
, "Event common context field class",
1210 for (i
= 0; i
< bt_stream_class_get_event_class_count(sc
); i
++) {
1211 g_ptr_array_add(event_classes
,
1212 (gpointer
) bt_stream_class_borrow_event_class_by_index_const(
1216 g_ptr_array_sort(event_classes
, (GCompareFunc
) compare_event_classes
);
1218 for (i
= 0; i
< event_classes
->len
; i
++) {
1219 write_event_class(ctx
, event_classes
->pdata
[i
]);
1223 g_ptr_array_free(event_classes
, TRUE
);
1227 gint
compare_stream_classes(const bt_stream_class
**a
, const bt_stream_class
**b
)
1229 uint64_t id_a
= bt_stream_class_get_id(*a
);
1230 uint64_t id_b
= bt_stream_class_get_id(*b
);
1234 } else if (id_a
> id_b
) {
1242 gint
compare_strings(const char **a
, const char **b
)
1244 return strcmp(*a
, *b
);
1248 void write_trace_class(struct details_write_ctx
*ctx
, const bt_trace_class
*tc
)
1250 GPtrArray
*stream_classes
= g_ptr_array_new();
1252 bool printed_prop
= false;
1255 write_obj_type_name(ctx
, "Trace class");
1257 for (i
= 0; i
< bt_trace_class_get_stream_class_count(tc
); i
++) {
1258 g_ptr_array_add(stream_classes
,
1259 (gpointer
) bt_trace_class_borrow_stream_class_by_index_const(
1263 g_ptr_array_sort(stream_classes
, (GCompareFunc
) compare_stream_classes
);
1265 if (stream_classes
->len
> 0) {
1266 if (!printed_prop
) {
1267 g_string_append(ctx
->str
, ":\n");
1268 printed_prop
= true;
1274 for (i
= 0; i
< stream_classes
->len
; i
++) {
1275 write_stream_class(ctx
, stream_classes
->pdata
[i
]);
1278 if (!printed_prop
) {
1283 g_ptr_array_free(stream_classes
, TRUE
);
1287 int try_write_meta(struct details_write_ctx
*ctx
, const bt_trace_class
*tc
,
1288 const bt_stream_class
*sc
, const bt_event_class
*ec
)
1294 if (details_need_to_write_trace_class(ctx
, tc
)) {
1297 if (ctx
->details_comp
->cfg
.compact
&&
1298 ctx
->details_comp
->printed_something
) {
1300 * There are no empty line between messages in
1301 * compact mode, so write one here to decouple
1302 * the trace class from the next message.
1308 * write_trace_class() also writes all its stream
1309 * classes their event classes, so we don't need to
1312 write_trace_class(ctx
, tc
);
1316 * Mark this trace class as written, as well as all
1317 * its stream classes and their event classes.
1319 ret
= details_did_write_trace_class(ctx
, tc
);
1324 for (sc_i
= 0; sc_i
< bt_trace_class_get_stream_class_count(tc
);
1327 const bt_stream_class
*tc_sc
=
1328 bt_trace_class_borrow_stream_class_by_index_const(
1331 details_did_write_meta_object(ctx
, tc
, tc_sc
);
1333 for (ec_i
= 0; ec_i
<
1334 bt_stream_class_get_event_class_count(tc_sc
);
1336 details_did_write_meta_object(ctx
, tc
,
1337 bt_stream_class_borrow_event_class_by_index_const(
1345 if (sc
&& details_need_to_write_meta_object(ctx
, tc
, sc
)) {
1350 if (ctx
->details_comp
->cfg
.compact
&&
1351 ctx
->details_comp
->printed_something
) {
1353 * There are no empty line between messages in
1354 * compact mode, so write one here to decouple
1355 * the stream class from the next message.
1361 * write_stream_class() also writes all its event
1362 * classes, so we don't need to rewrite `ec`.
1364 write_stream_class(ctx
, sc
);
1368 * Mark this stream class as written, as well as all its
1371 details_did_write_meta_object(ctx
, tc
, sc
);
1373 for (ec_i
= 0; ec_i
<
1374 bt_stream_class_get_event_class_count(sc
);
1376 details_did_write_meta_object(ctx
, tc
,
1377 bt_stream_class_borrow_event_class_by_index_const(
1384 if (ec
&& details_need_to_write_meta_object(ctx
, tc
, ec
)) {
1387 if (ctx
->details_comp
->cfg
.compact
&&
1388 ctx
->details_comp
->printed_something
) {
1390 * There are no empty line between messages in
1391 * compact mode, so write one here to decouple
1392 * the event class from the next message.
1397 write_event_class(ctx
, ec
);
1399 details_did_write_meta_object(ctx
, tc
, ec
);
1408 void write_time_str(struct details_write_ctx
*ctx
, const char *str
)
1410 if (!ctx
->details_comp
->cfg
.with_time
) {
1414 g_string_append_printf(ctx
->str
, "[%s%s%s%s]",
1415 color_bold(ctx
), color_fg_blue(ctx
), str
, color_reset(ctx
));
1417 if (ctx
->details_comp
->cfg
.compact
) {
1428 void write_time(struct details_write_ctx
*ctx
, const bt_clock_snapshot
*cs
)
1430 bt_clock_snapshot_get_ns_from_origin_status cs_status
;
1431 int64_t ns_from_origin
;
1434 if (!ctx
->details_comp
->cfg
.with_time
) {
1438 format_uint(buf
, bt_clock_snapshot_get_value(cs
), 10);
1439 g_string_append_printf(ctx
->str
, "[%s%s%s%s%s",
1440 color_bold(ctx
), color_fg_blue(ctx
), buf
,
1442 ctx
->details_comp
->cfg
.compact
? "" : " cycles");
1443 cs_status
= bt_clock_snapshot_get_ns_from_origin(cs
, &ns_from_origin
);
1444 if (cs_status
== BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OK
) {
1445 format_int(buf
, ns_from_origin
, 10);
1446 g_string_append_printf(ctx
->str
, "%s %s%s%s%s%s",
1447 ctx
->details_comp
->cfg
.compact
? "" : ",",
1448 color_bold(ctx
), color_fg_blue(ctx
), buf
,
1450 ctx
->details_comp
->cfg
.compact
? "" : " ns from origin");
1453 g_string_append(ctx
->str
, "]");
1455 if (ctx
->details_comp
->cfg
.compact
) {
1466 int write_message_follow_tag(struct details_write_ctx
*ctx
,
1467 const bt_stream
*stream
)
1470 uint64_t unique_trace_id
;
1471 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
1472 const bt_trace
*trace
= bt_stream_borrow_trace_const(stream
);
1474 ret
= details_trace_unique_id(ctx
, trace
, &unique_trace_id
);
1479 if (ctx
->details_comp
->cfg
.compact
) {
1480 g_string_append_printf(ctx
->str
,
1481 "%s{%s%" PRIu64
" %" PRIu64
" %" PRIu64
"%s%s}%s ",
1482 color_fg_cyan(ctx
), color_bold(ctx
),
1483 unique_trace_id
, bt_stream_class_get_id(sc
),
1484 bt_stream_get_id(stream
),
1485 color_reset(ctx
), color_fg_cyan(ctx
), color_reset(ctx
));
1487 g_string_append_printf(ctx
->str
,
1488 "%s{Trace %s%" PRIu64
"%s%s, Stream class ID %s%" PRIu64
"%s%s, Stream ID %s%" PRIu64
"%s%s}%s\n",
1490 color_bold(ctx
), unique_trace_id
,
1491 color_reset(ctx
), color_fg_cyan(ctx
),
1492 color_bold(ctx
), bt_stream_class_get_id(sc
),
1493 color_reset(ctx
), color_fg_cyan(ctx
),
1494 color_bold(ctx
), bt_stream_get_id(stream
),
1495 color_reset(ctx
), color_fg_cyan(ctx
),
1504 void write_field(struct details_write_ctx
*ctx
, const bt_field
*field
,
1508 bt_field_class_type fc_type
= bt_field_get_class_type(field
);
1509 const bt_field_class
*fc
;
1512 /* Write field's name */
1514 write_compound_member_name(ctx
, name
);
1517 /* Write field's value */
1519 case BT_FIELD_CLASS_TYPE_BOOL
:
1521 write_bool_prop_value(ctx
, bt_field_bool_get_value(field
));
1523 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
1524 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1525 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
1526 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1528 unsigned int fmt_base
;
1529 bt_field_class_integer_preferred_display_base base
;
1531 fc
= bt_field_borrow_class_const(field
);
1532 base
= bt_field_class_integer_get_preferred_display_base(fc
);
1535 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
:
1538 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
:
1541 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
:
1544 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
:
1551 if (fc_type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
1552 fc_type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
) {
1554 bt_field_integer_unsigned_get_value(field
),
1557 write_uint_str_prop_value(ctx
, buf
);
1560 bt_field_integer_signed_get_value(field
),
1563 write_int_str_prop_value(ctx
, buf
);
1568 case BT_FIELD_CLASS_TYPE_REAL
:
1570 write_float_prop_value(ctx
, bt_field_real_get_value(field
));
1572 case BT_FIELD_CLASS_TYPE_STRING
:
1574 write_str_prop_value(ctx
, bt_field_string_get_value(field
));
1576 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1578 uint64_t member_count
;
1580 fc
= bt_field_borrow_class_const(field
);
1581 member_count
= bt_field_class_structure_get_member_count(fc
);
1583 if (member_count
> 0) {
1586 for (i
= 0; i
< member_count
; i
++) {
1587 const bt_field_class_structure_member
*member
=
1588 bt_field_class_structure_borrow_member_by_index_const(
1590 const bt_field
*member_field
=
1591 bt_field_structure_borrow_member_field_by_index_const(
1595 write_field(ctx
, member_field
,
1596 bt_field_class_structure_member_get_name(member
));
1602 write_none_prop_value(ctx
, "Empty");
1607 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1608 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
1610 uint64_t length
= bt_field_array_get_length(field
);
1614 write_none_prop_value(ctx
, "Empty");
1616 g_string_append(ctx
->str
, " Length ");
1617 write_uint_prop_value(ctx
, length
);
1618 g_string_append_c(ctx
->str
, ':');
1623 for (i
= 0; i
< length
; i
++) {
1624 const bt_field
*elem_field
=
1625 bt_field_array_borrow_element_field_by_index_const(
1629 write_array_index(ctx
, i
);
1630 write_field(ctx
, elem_field
, NULL
);
1636 case BT_FIELD_CLASS_TYPE_OPTION
:
1638 const bt_field
*content_field
=
1639 bt_field_option_borrow_field_const(field
);
1641 if (!content_field
) {
1643 write_none_prop_value(ctx
, "None");
1645 write_field(ctx
, content_field
, NULL
);
1650 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
1651 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
1652 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
1654 bt_field_variant_borrow_selected_option_field_const(
1663 void write_root_field(struct details_write_ctx
*ctx
, const char *name
,
1664 const bt_field
*field
)
1669 write_prop_name(ctx
, name
);
1670 g_string_append(ctx
->str
, ":");
1671 write_field(ctx
, field
, NULL
);
1676 int write_event_message(struct details_write_ctx
*ctx
,
1677 const bt_message
*msg
)
1680 const bt_event
*event
= bt_message_event_borrow_event_const(msg
);
1681 const bt_stream
*stream
= bt_event_borrow_stream_const(event
);
1682 const bt_event_class
*ec
= bt_event_borrow_class_const(event
);
1683 const bt_stream_class
*sc
= bt_event_class_borrow_stream_class_const(ec
);
1684 const bt_trace_class
*tc
= bt_stream_class_borrow_trace_class_const(sc
);
1685 const char *ec_name
;
1686 const bt_field
*field
;
1688 ret
= try_write_meta(ctx
, tc
, sc
, ec
);
1694 if (bt_stream_class_borrow_default_clock_class_const(sc
)) {
1696 bt_message_event_borrow_default_clock_snapshot_const(
1700 /* Write follow tag for message */
1701 ret
= write_message_follow_tag(ctx
, stream
);
1706 /* Write object's basic properties */
1707 write_obj_type_name(ctx
, "Event");
1708 ec_name
= bt_event_class_get_name(ec
);
1710 g_string_append_printf(ctx
->str
, " `%s%s%s`",
1711 color_fg_green(ctx
), ec_name
, color_reset(ctx
));
1714 g_string_append(ctx
->str
, " (");
1716 if (!ctx
->details_comp
->cfg
.compact
) {
1717 g_string_append(ctx
->str
, "Class ID ");
1720 write_uint_prop_value(ctx
, bt_event_class_get_id(ec
));
1721 g_string_append(ctx
->str
, ")");
1723 if (ctx
->details_comp
->cfg
.compact
) {
1729 g_string_append(ctx
->str
, ":\n");
1731 field
= bt_event_borrow_common_context_field_const(event
);
1733 write_root_field(ctx
, "Common context", field
);
1736 field
= bt_event_borrow_specific_context_field_const(event
);
1738 write_root_field(ctx
, "Specific context", field
);
1741 field
= bt_event_borrow_payload_field_const(event
);
1743 write_root_field(ctx
, "Payload", field
);
1754 gint
compare_streams(const bt_stream
**a
, const bt_stream
**b
)
1756 uint64_t id_a
= bt_stream_get_id(*a
);
1757 uint64_t id_b
= bt_stream_get_id(*b
);
1761 } else if (id_a
> id_b
) {
1764 const bt_stream_class
*a_sc
= bt_stream_borrow_class_const(*a
);
1765 const bt_stream_class
*b_sc
= bt_stream_borrow_class_const(*b
);
1766 uint64_t a_sc_id
= bt_stream_class_get_id(a_sc
);
1767 uint64_t b_sc_id
= bt_stream_class_get_id(b_sc
);
1769 if (a_sc_id
< b_sc_id
) {
1771 } else if (a_sc_id
> b_sc_id
) {
1780 void write_trace(struct details_write_ctx
*ctx
, const bt_trace
*trace
)
1783 GPtrArray
*streams
= g_ptr_array_new();
1785 bool printed_prop
= false;
1786 GPtrArray
*env_names
= g_ptr_array_new();
1790 write_obj_type_name(ctx
, "Trace");
1793 if (ctx
->details_comp
->cfg
.with_trace_name
) {
1794 name
= bt_trace_get_name(trace
);
1796 g_string_append(ctx
->str
, " `");
1797 write_str_prop_value(ctx
, name
);
1798 g_string_append(ctx
->str
, "`");
1802 /* Write properties */
1806 if (ctx
->details_comp
->cfg
.with_uuid
) {
1807 bt_uuid uuid
= bt_trace_get_uuid(trace
);
1810 if (!printed_prop
) {
1811 g_string_append(ctx
->str
, ":\n");
1812 printed_prop
= true;
1815 write_uuid_prop_line(ctx
, "UUID", uuid
);
1819 /* Write environment */
1820 env_count
= bt_trace_get_environment_entry_count(trace
);
1821 if (env_count
> 0) {
1822 if (!printed_prop
) {
1823 g_string_append(ctx
->str
, ":\n");
1824 printed_prop
= true;
1828 write_prop_name(ctx
, "Environment");
1829 g_string_append(ctx
->str
, " (");
1830 write_uint_prop_value(ctx
, env_count
);
1831 g_string_append_printf(ctx
->str
, " entr%s):",
1832 env_count
== 1 ? "y" : "ies");
1836 for (i
= 0; i
< env_count
; i
++) {
1838 const bt_value
*value
;
1840 bt_trace_borrow_environment_entry_by_index_const(
1841 trace
, i
, &name
, &value
);
1842 g_ptr_array_add(env_names
, (gpointer
) name
);
1845 g_ptr_array_sort(env_names
, (GCompareFunc
) compare_strings
);
1847 for (i
= 0; i
< env_names
->len
; i
++) {
1848 const char *name
= env_names
->pdata
[i
];
1849 const bt_value
*value
=
1850 bt_trace_borrow_environment_entry_value_by_name_const(
1854 write_compound_member_name(ctx
, name
);
1857 if (bt_value_get_type(value
) ==
1858 BT_VALUE_TYPE_SIGNED_INTEGER
) {
1859 write_int_prop_value(ctx
,
1860 bt_value_integer_signed_get(value
));
1861 } else if (bt_value_get_type(value
) ==
1862 BT_VALUE_TYPE_STRING
) {
1863 write_str_prop_value(ctx
,
1864 bt_value_string_get(value
));
1875 for (i
= 0; i
< bt_trace_get_stream_count(trace
); i
++) {
1876 g_ptr_array_add(streams
,
1877 (gpointer
) bt_trace_borrow_stream_by_index_const(
1881 g_ptr_array_sort(streams
, (GCompareFunc
) compare_streams
);
1883 if (streams
->len
> 0 && !printed_prop
) {
1884 g_string_append(ctx
->str
, ":\n");
1885 printed_prop
= true;
1888 for (i
= 0; i
< streams
->len
; i
++) {
1889 const bt_stream
*stream
= streams
->pdata
[i
];
1892 write_obj_type_name(ctx
, "Stream");
1893 g_string_append(ctx
->str
, " (ID ");
1894 write_uint_prop_value(ctx
, bt_stream_get_id(stream
));
1895 g_string_append(ctx
->str
, ", Class ID ");
1896 write_uint_prop_value(ctx
, bt_stream_class_get_id(
1897 bt_stream_borrow_class_const(stream
)));
1898 g_string_append(ctx
->str
, ")");
1904 if (!printed_prop
) {
1908 g_ptr_array_free(streams
, TRUE
);
1909 g_ptr_array_free(env_names
, TRUE
);
1913 int write_stream_beginning_message(struct details_write_ctx
*ctx
,
1914 const bt_message
*msg
)
1917 const bt_stream
*stream
=
1918 bt_message_stream_beginning_borrow_stream_const(msg
);
1919 const bt_trace
*trace
= bt_stream_borrow_trace_const(stream
);
1920 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
1921 const bt_clock_class
*cc
= bt_stream_class_borrow_default_clock_class_const(sc
);
1922 const bt_trace_class
*tc
= bt_stream_class_borrow_trace_class_const(sc
);
1925 ret
= try_write_meta(ctx
, tc
, sc
, NULL
);
1932 const bt_clock_snapshot
*cs
;
1933 bt_message_stream_clock_snapshot_state cs_state
=
1934 bt_message_stream_beginning_borrow_default_clock_snapshot_const(msg
, &cs
);
1936 if (cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1937 write_time(ctx
, cs
);
1939 write_time_str(ctx
, "Unknown");
1943 /* Write follow tag for message */
1944 ret
= write_message_follow_tag(ctx
, stream
);
1949 /* Write stream properties */
1950 write_obj_type_name(ctx
, "Stream beginning");
1952 if (ctx
->details_comp
->cfg
.compact
) {
1957 g_string_append(ctx
->str
, ":\n");
1960 if (ctx
->details_comp
->cfg
.with_stream_name
) {
1961 name
= bt_stream_get_name(stream
);
1963 write_str_prop_line(ctx
, "Name", name
);
1967 if (ctx
->details_comp
->cfg
.with_stream_class_name
) {
1968 name
= bt_stream_class_get_name(sc
);
1970 write_str_prop_line(ctx
, "Class name", name
);
1974 write_trace(ctx
, trace
);
1982 int write_stream_end_message(struct details_write_ctx
*ctx
,
1983 const bt_message
*msg
)
1986 const bt_stream
*stream
=
1987 bt_message_stream_end_borrow_stream_const(msg
);
1988 const bt_stream_class
*sc
=
1989 bt_stream_borrow_class_const(stream
);
1990 const bt_clock_class
*cc
=
1991 bt_stream_class_borrow_default_clock_class_const(sc
);
1995 const bt_clock_snapshot
*cs
;
1996 bt_message_stream_clock_snapshot_state cs_state
=
1997 bt_message_stream_end_borrow_default_clock_snapshot_const(msg
, &cs
);
1999 if (cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
2000 write_time(ctx
, cs
);
2002 write_time_str(ctx
, "Unknown");
2006 /* Write follow tag for message */
2007 ret
= write_message_follow_tag(ctx
, stream
);
2012 /* Write stream properties */
2013 write_obj_type_name(ctx
, "Stream end\n");
2020 int write_packet_beginning_message(struct details_write_ctx
*ctx
,
2021 const bt_message
*msg
)
2024 const bt_packet
*packet
=
2025 bt_message_packet_beginning_borrow_packet_const(msg
);
2026 const bt_stream
*stream
= bt_packet_borrow_stream_const(packet
);
2027 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2028 const bt_field
*field
;
2031 if (bt_stream_class_packets_have_beginning_default_clock_snapshot(sc
)) {
2033 bt_message_packet_beginning_borrow_default_clock_snapshot_const(
2037 /* Write follow tag for message */
2038 ret
= write_message_follow_tag(ctx
, stream
);
2043 write_obj_type_name(ctx
, "Packet beginning");
2045 if (ctx
->details_comp
->cfg
.compact
) {
2051 g_string_append(ctx
->str
, ":\n");
2053 field
= bt_packet_borrow_context_field_const(packet
);
2055 write_root_field(ctx
, "Context", field
);
2065 int write_discarded_items_message(struct details_write_ctx
*ctx
,
2066 const char *name
, const bt_stream
*stream
,
2067 const bt_clock_snapshot
*beginning_cs
,
2068 const bt_clock_snapshot
*end_cs
, uint64_t count
)
2074 write_time(ctx
, beginning_cs
);
2076 write_time(ctx
, end_cs
);
2079 /* Write follow tag for message */
2080 ret
= write_message_follow_tag(ctx
, stream
);
2085 write_obj_type_name(ctx
, "Discarded ");
2086 write_obj_type_name(ctx
, name
);
2089 if (count
== UINT64_C(-1)) {
2094 g_string_append(ctx
->str
, " (");
2095 write_uint_prop_value(ctx
, count
);
2096 g_string_append_printf(ctx
->str
, " %s)\n", name
);
2103 int write_discarded_events_message(struct details_write_ctx
*ctx
,
2104 const bt_message
*msg
)
2106 const bt_stream
*stream
= bt_message_discarded_events_borrow_stream_const(
2108 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2109 const bt_clock_snapshot
*beginning_cs
= NULL
;
2110 const bt_clock_snapshot
*end_cs
= NULL
;
2113 if (bt_stream_class_discarded_events_have_default_clock_snapshots(sc
)) {
2115 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
2118 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
2122 if (bt_message_discarded_events_get_count(msg
, &count
) !=
2123 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
2124 count
= UINT64_C(-1);
2127 return write_discarded_items_message(ctx
, "events", stream
,
2128 beginning_cs
, end_cs
, count
);
2132 int write_discarded_packets_message(struct details_write_ctx
*ctx
,
2133 const bt_message
*msg
)
2135 const bt_stream
*stream
= bt_message_discarded_packets_borrow_stream_const(
2137 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2138 const bt_clock_snapshot
*beginning_cs
= NULL
;
2139 const bt_clock_snapshot
*end_cs
= NULL
;
2142 if (bt_stream_class_discarded_packets_have_default_clock_snapshots(sc
)) {
2144 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
2147 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
2151 if (bt_message_discarded_packets_get_count(msg
, &count
) !=
2152 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
2153 count
= UINT64_C(-1);
2156 return write_discarded_items_message(ctx
, "packets", stream
,
2157 beginning_cs
, end_cs
, count
);
2161 int write_packet_end_message(struct details_write_ctx
*ctx
,
2162 const bt_message
*msg
)
2165 const bt_packet
*packet
=
2166 bt_message_packet_end_borrow_packet_const(msg
);
2167 const bt_stream
*stream
= bt_packet_borrow_stream_const(packet
);
2168 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2171 if (bt_stream_class_packets_have_end_default_clock_snapshot(sc
)) {
2173 bt_message_packet_end_borrow_default_clock_snapshot_const(
2177 /* Write follow tag for message */
2178 ret
= write_message_follow_tag(ctx
, stream
);
2183 write_obj_type_name(ctx
, "Packet end");
2191 int write_message_iterator_inactivity_message(struct details_write_ctx
*ctx
,
2192 const bt_message
*msg
)
2195 const bt_clock_snapshot
*cs
=
2196 bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
2200 write_time(ctx
, cs
);
2201 write_obj_type_name(ctx
, "Message iterator inactivity");
2203 if (ctx
->details_comp
->cfg
.compact
) {
2208 /* Write clock class properties */
2209 g_string_append(ctx
->str
, ":\n");
2212 write_prop_name(ctx
, "Clock class");
2213 g_string_append_c(ctx
->str
, ':');
2216 write_clock_class_prop_lines(ctx
,
2217 bt_clock_snapshot_borrow_clock_class_const(cs
));
2225 int details_write_message(struct details_comp
*details_comp
,
2226 const bt_message
*msg
)
2229 struct details_write_ctx ctx
= {
2230 .details_comp
= details_comp
,
2231 .str
= details_comp
->str
,
2235 /* Reset output buffer */
2236 g_string_assign(details_comp
->str
, "");
2238 if (details_comp
->printed_something
&& !details_comp
->cfg
.compact
) {
2242 switch (bt_message_get_type(msg
)) {
2243 case BT_MESSAGE_TYPE_EVENT
:
2244 ret
= write_event_message(&ctx
, msg
);
2246 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
2247 ret
= write_message_iterator_inactivity_message(&ctx
, msg
);
2249 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
2250 ret
= write_stream_beginning_message(&ctx
, msg
);
2252 case BT_MESSAGE_TYPE_STREAM_END
:
2253 ret
= write_stream_end_message(&ctx
, msg
);
2255 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
2256 ret
= write_packet_beginning_message(&ctx
, msg
);
2258 case BT_MESSAGE_TYPE_PACKET_END
:
2259 ret
= write_packet_end_message(&ctx
, msg
);
2261 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
2262 ret
= write_discarded_events_message(&ctx
, msg
);
2264 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
2265 ret
= write_discarded_packets_message(&ctx
, msg
);