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
,
208 format_uint(buf
, index
, 10);
209 g_string_append_printf(ctx
->str
, "%s[%s]%s:",
210 color
, buf
, color_reset(ctx
));
214 void write_obj_type_name(struct details_write_ctx
*ctx
, const char *name
)
216 g_string_append_printf(ctx
->str
, "%s%s%s%s",
217 color_fg_yellow(ctx
), color_bold(ctx
), name
, color_reset(ctx
));
221 void write_prop_name(struct details_write_ctx
*ctx
, const char *prop_name
)
223 g_string_append_printf(ctx
->str
, "%s%s%s",
224 color_fg_magenta(ctx
), prop_name
, color_reset(ctx
));
228 void write_prop_name_line(struct details_write_ctx
*ctx
, const char *prop_name
)
231 g_string_append_printf(ctx
->str
, "%s%s%s:",
232 color_fg_magenta(ctx
), prop_name
, color_reset(ctx
));
236 void write_str_prop_value(struct details_write_ctx
*ctx
, const char *value
)
238 g_string_append_printf(ctx
->str
, "%s%s%s",
239 color_bold(ctx
), value
, color_reset(ctx
));
243 void write_none_prop_value(struct details_write_ctx
*ctx
, const char *value
)
245 g_string_append_printf(ctx
->str
, "%s%s%s%s",
246 color_bold(ctx
), color_fg_magenta(ctx
),
247 value
, color_reset(ctx
));
251 void write_uint_str_prop_value(struct details_write_ctx
*ctx
, const char *value
)
253 write_str_prop_value(ctx
, value
);
257 void write_uint_prop_value(struct details_write_ctx
*ctx
, uint64_t value
)
261 format_uint(buf
, value
, 10);
262 write_uint_str_prop_value(ctx
, buf
);
266 void write_int_prop_value(struct details_write_ctx
*ctx
, int64_t value
)
270 format_int(buf
, value
, 10);
271 write_uint_str_prop_value(ctx
, buf
);
275 void write_float_prop_value(struct details_write_ctx
*ctx
, double value
)
277 g_string_append_printf(ctx
->str
, "%s%f%s",
278 color_bold(ctx
), value
, color_reset(ctx
));
282 void write_str_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
283 const char *prop_value
)
285 BT_ASSERT(prop_value
);
287 write_prop_name(ctx
, prop_name
);
288 g_string_append(ctx
->str
, ": ");
289 write_str_prop_value(ctx
, prop_value
);
294 void write_uint_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
298 write_prop_name(ctx
, prop_name
);
299 g_string_append(ctx
->str
, ": ");
300 write_uint_prop_value(ctx
, prop_value
);
305 void write_int_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
309 write_prop_name(ctx
, prop_name
);
310 g_string_append(ctx
->str
, ": ");
311 write_int_prop_value(ctx
, prop_value
);
316 void write_int_str_prop_value(struct details_write_ctx
*ctx
, const char *value
)
318 write_str_prop_value(ctx
, value
);
322 void write_bool_prop_value(struct details_write_ctx
*ctx
, bt_bool prop_value
)
326 g_string_append(ctx
->str
, color_bold(ctx
));
329 g_string_append(ctx
->str
, color_fg_green(ctx
));
332 g_string_append(ctx
->str
, color_fg_red(ctx
));
336 g_string_append_printf(ctx
->str
, "%s%s", str
, color_reset(ctx
));
340 void write_bool_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
344 write_prop_name(ctx
, prop_name
);
345 g_string_append(ctx
->str
, ": ");
346 write_bool_prop_value(ctx
, prop_value
);
351 void write_uuid_prop_line(struct details_write_ctx
*ctx
, const char *prop_name
,
356 write_prop_name(ctx
, prop_name
);
357 g_string_append_printf(ctx
->str
,
358 ": %s" BT_UUID_FMT
"%s\n",
360 BT_UUID_FMT_VALUES(uuid
),
365 gint
compare_strings(const char **a
, const char **b
)
367 return strcmp(*a
, *b
);
371 bt_bool
map_value_foreach_add_key_to_array(const char *key
,
372 const bt_value
*object
, void *data
)
374 GPtrArray
*keys
= data
;
377 g_ptr_array_add(keys
, (void *) key
);
382 void write_value(struct details_write_ctx
*ctx
, const bt_value
*value
,
386 bt_value_type value_type
= bt_value_get_type(value
);
387 GPtrArray
*keys
= g_ptr_array_new();
392 /* Write field's name */
394 write_prop_name_line(ctx
, name
);
397 /* Write field's value */
398 switch (value_type
) {
399 case BT_VALUE_TYPE_NULL
:
401 write_none_prop_value(ctx
, "Null");
403 case BT_VALUE_TYPE_BOOL
:
405 write_bool_prop_value(ctx
, bt_value_bool_get(value
));
407 case BT_VALUE_TYPE_UNSIGNED_INTEGER
:
408 format_uint(buf
, bt_value_integer_unsigned_get(value
), 10);
410 write_uint_str_prop_value(ctx
, buf
);
412 case BT_VALUE_TYPE_SIGNED_INTEGER
:
413 format_int(buf
, bt_value_integer_signed_get(value
), 10);
415 write_int_str_prop_value(ctx
, buf
);
417 case BT_VALUE_TYPE_REAL
:
419 write_float_prop_value(ctx
, bt_value_real_get(value
));
421 case BT_VALUE_TYPE_STRING
:
423 write_str_prop_value(ctx
, bt_value_string_get(value
));
425 case BT_VALUE_TYPE_ARRAY
:
427 uint64_t length
= bt_value_array_get_length(value
);
431 write_none_prop_value(ctx
, "Empty");
433 g_string_append(ctx
->str
, " Length ");
434 write_uint_prop_value(ctx
, length
);
435 g_string_append_c(ctx
->str
, ':');
440 for (i
= 0; i
< length
; i
++) {
441 const bt_value
*elem_value
=
442 bt_value_array_borrow_element_by_index_const(
446 write_array_index(ctx
, i
, color_fg_magenta(ctx
));
447 write_value(ctx
, elem_value
, NULL
);
453 case BT_VALUE_TYPE_MAP
:
455 bt_value_map_foreach_entry_const_status foreach_status
=
456 bt_value_map_foreach_entry_const(value
,
457 map_value_foreach_add_key_to_array
, keys
);
459 BT_ASSERT(foreach_status
==
460 BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_OK
);
461 g_ptr_array_sort(keys
, (GCompareFunc
) compare_strings
);
466 for (i
= 0; i
< keys
->len
; i
++) {
467 const char *key
= keys
->pdata
[i
];
468 const bt_value
*entry_value
=
469 bt_value_map_borrow_entry_value_const(
473 write_value(ctx
, entry_value
, key
);
479 write_none_prop_value(ctx
, "Empty");
488 g_ptr_array_free(keys
, TRUE
);
492 void write_user_attributes(struct details_write_ctx
*ctx
,
493 const bt_value
*user_attrs
, bool write_newline
, bool *written
)
495 BT_ASSERT(user_attrs
);
497 if (!bt_value_map_is_empty(user_attrs
)) {
498 write_value(ctx
, user_attrs
, "User attributes");
511 void write_int_field_class_props(struct details_write_ctx
*ctx
,
512 const bt_field_class
*fc
, bool close
)
514 g_string_append_printf(ctx
->str
, "(%s%" PRIu64
"-bit%s, Base ",
516 bt_field_class_integer_get_field_value_range(fc
),
519 switch (bt_field_class_integer_get_preferred_display_base(fc
)) {
520 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
:
521 write_uint_prop_value(ctx
, 2);
523 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
:
524 write_uint_prop_value(ctx
, 8);
526 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
:
527 write_uint_prop_value(ctx
, 10);
529 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
:
530 write_uint_prop_value(ctx
, 16);
537 g_string_append(ctx
->str
, ")");
553 struct enum_field_class_mapping
{
557 /* Array of `struct int_range` */
562 gint
compare_enum_field_class_mappings(struct enum_field_class_mapping
**a
,
563 struct enum_field_class_mapping
**b
)
565 return strcmp((*a
)->label
, (*b
)->label
);
569 gint
compare_int_ranges_signed(struct int_range
*a
, struct int_range
*b
)
572 if (a
->lower
.i
< b
->lower
.i
) {
574 } else if (a
->lower
.i
> b
->lower
.i
) {
577 if (a
->upper
.i
< b
->upper
.i
) {
579 } else if (a
->upper
.i
> b
->upper
.i
) {
588 gint
compare_int_ranges_unsigned(struct int_range
*a
, struct int_range
*b
)
590 if (a
->lower
.u
< b
->lower
.u
) {
592 } else if (a
->lower
.u
> b
->lower
.u
) {
595 if (a
->upper
.u
< b
->upper
.u
) {
597 } else if (a
->upper
.u
> b
->upper
.u
) {
606 GArray
*range_set_to_int_ranges(const void *spec_range_set
, bool is_signed
)
609 const bt_integer_range_set
*range_set
;
610 GArray
*ranges
= g_array_new(FALSE
, TRUE
, sizeof(struct int_range
));
617 range_set
= bt_integer_range_set_signed_as_range_set_const(
620 range_set
= bt_integer_range_set_unsigned_as_range_set_const(
624 for (i
= 0; i
< bt_integer_range_set_get_range_count(range_set
); i
++) {
625 struct int_range range
;
628 const bt_integer_range_signed
*orig_range
=
629 bt_integer_range_set_signed_borrow_range_by_index_const(
632 range
.lower
.i
= bt_integer_range_signed_get_lower(orig_range
);
633 range
.upper
.i
= bt_integer_range_signed_get_upper(orig_range
);
635 const bt_integer_range_unsigned
*orig_range
=
636 bt_integer_range_set_unsigned_borrow_range_by_index_const(
639 range
.lower
.u
= bt_integer_range_unsigned_get_lower(orig_range
);
640 range
.upper
.u
= bt_integer_range_unsigned_get_upper(orig_range
);
643 g_array_append_val(ranges
, range
);
647 g_array_sort(ranges
, (GCompareFunc
) compare_int_ranges_signed
);
650 (GCompareFunc
) compare_int_ranges_unsigned
);
658 void destroy_enum_field_class_mapping(struct enum_field_class_mapping
*mapping
)
660 if (mapping
->ranges
) {
661 g_array_free(mapping
->ranges
, TRUE
);
662 mapping
->ranges
= NULL
;
669 struct int_range
*int_range_at(GArray
*ranges
, uint64_t index
)
671 return &g_array_index(ranges
, struct int_range
, index
);
675 void write_int_range(struct details_write_ctx
*ctx
,
676 struct int_range
*range
, bool is_signed
)
678 g_string_append(ctx
->str
, "[");
681 write_int_prop_value(ctx
, range
->lower
.i
);
683 write_int_prop_value(ctx
, range
->lower
.u
);
686 if (range
->lower
.u
!= range
->upper
.u
) {
687 g_string_append(ctx
->str
, ", ");
690 write_int_prop_value(ctx
, range
->upper
.i
);
692 write_int_prop_value(ctx
, range
->upper
.u
);
696 g_string_append(ctx
->str
, "]");
700 void write_enum_field_class_mappings(struct details_write_ctx
*ctx
,
701 const bt_field_class
*fc
)
706 bool is_signed
= bt_field_class_get_type(fc
) ==
707 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
;
709 mappings
= g_ptr_array_new_with_free_func(
710 (GDestroyNotify
) destroy_enum_field_class_mapping
);
714 * Copy field class's mappings to our own arrays and structures
717 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(fc
); i
++) {
718 const void *fc_mapping
;
719 const void *fc_range_set
;
720 struct enum_field_class_mapping
*mapping
= g_new0(
721 struct enum_field_class_mapping
, 1);
726 fc_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
728 fc_range_set
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
731 fc_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
733 fc_range_set
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
737 mapping
->label
= bt_field_class_enumeration_mapping_get_label(
738 bt_field_class_enumeration_signed_mapping_as_mapping_const(
740 mapping
->ranges
= range_set_to_int_ranges(fc_range_set
,
742 BT_ASSERT(mapping
->ranges
);
743 g_ptr_array_add(mappings
, mapping
);
746 /* Sort mappings (ranges are already sorted within mappings) */
747 g_ptr_array_sort(mappings
,
748 (GCompareFunc
) compare_enum_field_class_mappings
);
751 for (i
= 0; i
< mappings
->len
; i
++) {
752 struct enum_field_class_mapping
*mapping
= mappings
->pdata
[i
];
755 write_prop_name_line(ctx
, mapping
->label
);
757 for (range_i
= 0; range_i
< mapping
->ranges
->len
; range_i
++) {
760 int_range_at(mapping
->ranges
, range_i
),
765 g_ptr_array_free(mappings
, TRUE
);
769 void write_field_path(struct details_write_ctx
*ctx
,
770 const bt_field_path
*field_path
)
774 g_string_append_c(ctx
->str
, '[');
776 switch (bt_field_path_get_root_scope(field_path
)) {
777 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
:
778 write_str_prop_value(ctx
, "Packet context");
780 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
:
781 write_str_prop_value(ctx
, "Event common context");
783 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
:
784 write_str_prop_value(ctx
, "Event specific context");
786 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
:
787 write_str_prop_value(ctx
, "Event payload");
793 g_string_append(ctx
->str
, ": ");
795 for (i
= 0; i
< bt_field_path_get_item_count(field_path
); i
++) {
796 const bt_field_path_item
*fp_item
=
797 bt_field_path_borrow_item_by_index_const(field_path
, i
);
800 g_string_append(ctx
->str
, ", ");
803 switch (bt_field_path_item_get_type(fp_item
)) {
804 case BT_FIELD_PATH_ITEM_TYPE_INDEX
:
805 write_uint_prop_value(ctx
,
806 bt_field_path_item_index_get_index(fp_item
));
808 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
809 write_str_prop_value(ctx
, "<current>");
816 g_string_append_c(ctx
->str
, ']');
820 void write_field_class(struct details_write_ctx
*ctx
, const bt_field_class
*fc
);
823 void write_variant_field_class_option(struct details_write_ctx
*ctx
,
824 const bt_field_class
*fc
, uint64_t index
)
826 bt_field_class_type fc_type
= bt_field_class_get_type(fc
);
827 const bt_field_class_variant_option
*option
=
828 bt_field_class_variant_borrow_option_by_index_const(
830 const void *orig_ranges
= NULL
;
831 GArray
*int_ranges
= NULL
;
833 const bt_value
*user_attrs
=
834 bt_field_class_variant_option_borrow_user_attributes_const(
836 const bt_field_class
*option_fc
=
837 bt_field_class_variant_option_borrow_field_class_const(option
);
840 write_compound_member_name(ctx
,
841 bt_field_class_variant_option_get_name(option
));
843 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
) {
844 const bt_field_class_variant_with_selector_unsigned_option
*spec_opt
=
845 bt_field_class_variant_with_selector_unsigned_borrow_option_by_index_const(
849 bt_field_class_variant_with_selector_unsigned_option_borrow_ranges_const(
852 } else if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
) {
853 const bt_field_class_variant_with_selector_signed_option
*spec_opt
=
854 bt_field_class_variant_with_selector_signed_borrow_option_by_index_const(
858 bt_field_class_variant_with_selector_signed_option_borrow_ranges_const(
866 int_ranges
= range_set_to_int_ranges(orig_ranges
, is_signed
);
867 BT_ASSERT(int_ranges
);
869 for (i
= 0; i
< int_ranges
->len
; i
++) {
870 struct int_range
*range
= int_range_at(int_ranges
, i
);
873 write_int_range(ctx
, range
, is_signed
);
876 g_string_append(ctx
->str
, ": ");
881 if (bt_value_map_is_empty(user_attrs
)) {
882 write_field_class(ctx
, option_fc
);
888 write_prop_name_line(ctx
, "Field class");
890 write_field_class(ctx
, option_fc
);
893 /* User attributes */
894 write_user_attributes(ctx
, user_attrs
,
901 g_array_free(int_ranges
, TRUE
);
906 void write_field_class(struct details_write_ctx
*ctx
, const bt_field_class
*fc
)
910 bt_field_class_type fc_type
= bt_field_class_get_type(fc
);
911 const bt_value
*user_attrs
;
912 bool wrote_user_attrs
= false;
914 /* Write field class's type */
916 case BT_FIELD_CLASS_TYPE_BOOL
:
919 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
922 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
923 type
= "Unsigned integer";
925 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
926 type
= "Signed integer";
928 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
929 type
= "Unsigned enumeration";
931 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
932 type
= "Signed enumeration";
934 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
935 type
= "Single-precision real";
937 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
938 type
= "Double-precision real";
940 case BT_FIELD_CLASS_TYPE_STRING
:
943 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
946 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
947 type
= "Static array";
949 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
950 type
= "Dynamic array";
952 case BT_FIELD_CLASS_TYPE_OPTION
:
955 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
956 type
= "Variant (no selector)";
958 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
959 type
= "Variant (unsigned selector)";
961 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
962 type
= "Variant (signed selector)";
968 g_string_append_printf(ctx
->str
, "%s%s%s",
969 color_fg_blue(ctx
), type
, color_reset(ctx
));
971 /* Write field class's single-line properties */
973 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
974 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
976 write_int_field_class_props(ctx
, fc
, true);
978 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
979 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
981 uint64_t mapping_count
=
982 bt_field_class_enumeration_get_mapping_count(fc
);
985 write_int_field_class_props(ctx
, fc
, false);
986 g_string_append(ctx
->str
, ", ");
987 write_uint_prop_value(ctx
, mapping_count
);
988 g_string_append_printf(ctx
->str
, " mapping%s)",
989 plural(mapping_count
));
992 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
994 uint64_t member_count
=
995 bt_field_class_structure_get_member_count(fc
);
997 g_string_append(ctx
->str
, " (");
998 write_uint_prop_value(ctx
, member_count
);
999 g_string_append_printf(ctx
->str
, " member%s)",
1000 plural(member_count
));
1003 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1004 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
1005 if (fc_type
== BT_FIELD_CLASS_TYPE_STATIC_ARRAY
) {
1006 g_string_append(ctx
->str
, " (Length ");
1007 write_uint_prop_value(ctx
,
1008 bt_field_class_array_static_get_length(fc
));
1009 g_string_append_c(ctx
->str
, ')');
1011 const bt_field_path
*length_field_path
=
1012 bt_field_class_array_dynamic_borrow_length_field_path_const(
1015 if (length_field_path
) {
1016 g_string_append(ctx
->str
, " (Length field path ");
1017 write_field_path(ctx
, length_field_path
);
1018 g_string_append_c(ctx
->str
, ')');
1023 case BT_FIELD_CLASS_TYPE_OPTION
:
1025 const bt_field_path
*selector_field_path
=
1026 bt_field_class_option_borrow_selector_field_path_const(fc
);
1028 if (selector_field_path
) {
1029 g_string_append(ctx
->str
, " (Selector field path ");
1030 write_field_path(ctx
, selector_field_path
);
1031 g_string_append_c(ctx
->str
, ')');
1036 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
1037 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
1038 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
1040 uint64_t option_count
=
1041 bt_field_class_variant_get_option_count(fc
);
1042 const bt_field_path
*sel_field_path
= NULL
;
1044 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
||
1045 fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
) {
1047 bt_field_class_variant_with_selector_borrow_selector_field_path_const(
1049 BT_ASSERT(sel_field_path
);
1052 g_string_append(ctx
->str
, " (");
1053 write_uint_prop_value(ctx
, option_count
);
1054 g_string_append_printf(ctx
->str
, " option%s",
1055 plural(option_count
));
1057 if (sel_field_path
) {
1058 g_string_append(ctx
->str
, ", Selector field path ");
1059 write_field_path(ctx
, sel_field_path
);
1062 g_string_append_c(ctx
->str
, ')');
1070 user_attrs
= bt_field_class_borrow_user_attributes_const(fc
);
1071 if (!bt_value_map_is_empty(user_attrs
)) {
1072 g_string_append(ctx
->str
, ":\n");
1073 write_user_attributes(ctx
, user_attrs
, false, NULL
);
1074 wrote_user_attrs
= true;
1077 /* Write field class's complex properties */
1079 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1080 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1082 uint64_t mapping_count
=
1083 bt_field_class_enumeration_get_mapping_count(fc
);
1085 if (mapping_count
> 0) {
1086 if (wrote_user_attrs
) {
1089 write_prop_name(ctx
, "Mappings");
1090 g_string_append_c(ctx
->str
, ':');
1093 /* Each mapping starts with its own newline */
1094 g_string_append_c(ctx
->str
, ':');
1097 write_enum_field_class_mappings(ctx
, fc
);
1099 if (wrote_user_attrs
) {
1106 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1108 uint64_t member_count
=
1109 bt_field_class_structure_get_member_count(fc
);
1111 if (member_count
> 0) {
1112 if (wrote_user_attrs
) {
1115 write_prop_name(ctx
, "Members");
1116 g_string_append_c(ctx
->str
, ':');
1119 /* Each member starts with its own newline */
1120 g_string_append_c(ctx
->str
, ':');
1123 for (i
= 0; i
< member_count
; i
++) {
1124 const bt_field_class_structure_member
*member
=
1125 bt_field_class_structure_borrow_member_by_index_const(
1127 const bt_value
*user_attrs
;
1128 const bt_field_class
*member_fc
=
1129 bt_field_class_structure_member_borrow_field_class_const(member
);
1132 write_compound_member_name(ctx
,
1133 bt_field_class_structure_member_get_name(member
));
1134 user_attrs
= bt_field_class_structure_member_borrow_user_attributes_const(
1137 if (bt_value_map_is_empty(user_attrs
)) {
1139 write_field_class(ctx
, member_fc
);
1145 write_prop_name_line(ctx
, "Field class");
1147 write_field_class(ctx
, member_fc
);
1150 /* User attributes */
1151 write_user_attributes(ctx
, user_attrs
,
1158 if (wrote_user_attrs
) {
1165 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1166 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
1167 if (wrote_user_attrs
) {
1170 g_string_append(ctx
->str
, ":\n");
1173 write_prop_name_line(ctx
, "Element");
1175 write_field_class(ctx
,
1176 bt_field_class_array_borrow_element_field_class_const(fc
));
1178 case BT_FIELD_CLASS_TYPE_OPTION
:
1179 if (wrote_user_attrs
) {
1182 g_string_append(ctx
->str
, ":\n");
1185 write_prop_name_line(ctx
, "Content");
1187 write_field_class(ctx
,
1188 bt_field_class_option_borrow_field_class_const(fc
));
1190 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
1191 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
1192 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
1194 uint64_t option_count
=
1195 bt_field_class_variant_get_option_count(fc
);
1197 if (option_count
> 0) {
1198 if (wrote_user_attrs
) {
1201 write_prop_name(ctx
, "Options");
1202 g_string_append_c(ctx
->str
, ':');
1205 /* Each option starts with its own newline */
1206 g_string_append_c(ctx
->str
, ':');
1209 for (i
= 0; i
< option_count
; i
++) {
1210 write_variant_field_class_option(ctx
, fc
, i
);
1213 if (wrote_user_attrs
) {
1228 void write_root_field_class(struct details_write_ctx
*ctx
, const char *name
,
1229 const bt_field_class
*fc
)
1234 write_prop_name(ctx
, name
);
1235 g_string_append(ctx
->str
, ": ");
1236 write_field_class(ctx
, fc
);
1241 void write_event_class(struct details_write_ctx
*ctx
, const bt_event_class
*ec
)
1243 const char *name
= bt_event_class_get_name(ec
);
1244 const char *emf_uri
;
1245 const bt_field_class
*fc
;
1246 bt_event_class_log_level log_level
;
1249 write_obj_type_name(ctx
, "Event class");
1251 /* Write name and ID */
1253 g_string_append_printf(ctx
->str
, " `%s%s%s`",
1254 color_fg_green(ctx
), name
, color_reset(ctx
));
1257 g_string_append(ctx
->str
, " (ID ");
1258 write_uint_prop_value(ctx
, bt_event_class_get_id(ec
));
1259 g_string_append(ctx
->str
, "):\n");
1261 /* Write properties */
1264 /* Write user attributes */
1265 write_user_attributes(ctx
,
1266 bt_event_class_borrow_user_attributes_const(ec
), true, NULL
);
1268 /* Write log level */
1269 if (bt_event_class_get_log_level(ec
, &log_level
) ==
1270 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
1271 const char *ll_str
= NULL
;
1273 switch (log_level
) {
1274 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
1275 ll_str
= "Emergency";
1277 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
1280 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
1281 ll_str
= "Critical";
1283 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
1286 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
1289 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
1292 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
1295 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
1296 ll_str
= "Debug (system)";
1298 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
1299 ll_str
= "Debug (program)";
1301 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
1302 ll_str
= "Debug (process)";
1304 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
1305 ll_str
= "Debug (module)";
1307 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
1308 ll_str
= "Debug (unit)";
1310 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
1311 ll_str
= "Debug (function)";
1313 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
1314 ll_str
= "Debug (line)";
1316 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
1323 write_str_prop_line(ctx
, "Log level", ll_str
);
1327 emf_uri
= bt_event_class_get_emf_uri(ec
);
1329 write_str_prop_line(ctx
, "EMF URI", emf_uri
);
1332 /* Write specific context field class */
1333 fc
= bt_event_class_borrow_specific_context_field_class_const(ec
);
1335 write_root_field_class(ctx
, "Specific context field class", fc
);
1338 /* Write payload field class */
1339 fc
= bt_event_class_borrow_payload_field_class_const(ec
);
1341 write_root_field_class(ctx
, "Payload field class", fc
);
1348 void write_clock_class_prop_lines(struct details_write_ctx
*ctx
,
1349 const bt_clock_class
*cc
)
1351 int64_t offset_seconds
;
1352 uint64_t offset_cycles
;
1355 str
= bt_clock_class_get_name(cc
);
1357 write_str_prop_line(ctx
, "Name", str
);
1360 write_user_attributes(ctx
,
1361 bt_clock_class_borrow_user_attributes_const(cc
), true, NULL
);
1362 str
= bt_clock_class_get_description(cc
);
1364 write_str_prop_line(ctx
, "Description", str
);
1367 write_uint_prop_line(ctx
, "Frequency (Hz)",
1368 bt_clock_class_get_frequency(cc
));
1369 write_uint_prop_line(ctx
, "Precision (cycles)",
1370 bt_clock_class_get_precision(cc
));
1371 bt_clock_class_get_offset(cc
, &offset_seconds
, &offset_cycles
);
1372 write_int_prop_line(ctx
, "Offset (s)", offset_seconds
);
1373 write_uint_prop_line(ctx
, "Offset (cycles)", offset_cycles
);
1374 write_bool_prop_line(ctx
, "Origin is Unix epoch",
1375 bt_clock_class_origin_is_unix_epoch(cc
));
1377 if (ctx
->details_comp
->cfg
.with_uuid
) {
1378 bt_uuid uuid
= bt_clock_class_get_uuid(cc
);
1381 write_uuid_prop_line(ctx
, "UUID", uuid
);
1387 gint
compare_event_classes(const bt_event_class
**a
, const bt_event_class
**b
)
1389 uint64_t id_a
= bt_event_class_get_id(*a
);
1390 uint64_t id_b
= bt_event_class_get_id(*b
);
1394 } else if (id_a
> id_b
) {
1402 void write_stream_class(struct details_write_ctx
*ctx
,
1403 const bt_stream_class
*sc
)
1405 const bt_field_class
*fc
;
1406 GPtrArray
*event_classes
= g_ptr_array_new();
1410 write_obj_type_name(ctx
, "Stream class");
1412 /* Write name and ID */
1413 if (ctx
->details_comp
->cfg
.with_stream_class_name
) {
1414 const char *name
= bt_stream_class_get_name(sc
);
1417 g_string_append(ctx
->str
, " `");
1418 write_str_prop_value(ctx
, name
);
1419 g_string_append(ctx
->str
, "`");
1423 g_string_append(ctx
->str
, " (ID ");
1424 write_uint_prop_value(ctx
, bt_stream_class_get_id(sc
));
1425 g_string_append(ctx
->str
, "):\n");
1427 /* Write properties */
1430 /* Write user attributes */
1431 write_user_attributes(ctx
,
1432 bt_stream_class_borrow_user_attributes_const(sc
), true, NULL
);
1434 /* Write configuration */
1435 write_bool_prop_line(ctx
,
1436 "Supports packets", bt_stream_class_supports_packets(sc
));
1438 if (bt_stream_class_supports_packets(sc
)) {
1439 write_bool_prop_line(ctx
,
1440 "Packets have beginning default clock snapshot",
1441 bt_stream_class_packets_have_beginning_default_clock_snapshot(sc
));
1442 write_bool_prop_line(ctx
,
1443 "Packets have end default clock snapshot",
1444 bt_stream_class_packets_have_end_default_clock_snapshot(sc
));
1447 write_bool_prop_line(ctx
,
1448 "Supports discarded events",
1449 bt_stream_class_supports_discarded_events(sc
));
1451 if (bt_stream_class_supports_discarded_events(sc
)) {
1452 write_bool_prop_line(ctx
,
1453 "Discarded events have default clock snapshots",
1454 bt_stream_class_discarded_events_have_default_clock_snapshots(sc
));
1457 write_bool_prop_line(ctx
,
1458 "Supports discarded packets",
1459 bt_stream_class_supports_discarded_packets(sc
));
1461 if (bt_stream_class_supports_discarded_packets(sc
)) {
1462 write_bool_prop_line(ctx
,
1463 "Discarded packets have default clock snapshots",
1464 bt_stream_class_discarded_packets_have_default_clock_snapshots(sc
));
1467 /* Write default clock class */
1468 if (bt_stream_class_borrow_default_clock_class_const(sc
)) {
1470 write_prop_name(ctx
, "Default clock class");
1471 g_string_append_c(ctx
->str
, ':');
1474 write_clock_class_prop_lines(ctx
,
1475 bt_stream_class_borrow_default_clock_class_const(sc
));
1479 fc
= bt_stream_class_borrow_packet_context_field_class_const(sc
);
1481 write_root_field_class(ctx
, "Packet context field class", fc
);
1484 fc
= bt_stream_class_borrow_event_common_context_field_class_const(sc
);
1486 write_root_field_class(ctx
, "Event common context field class",
1490 for (i
= 0; i
< bt_stream_class_get_event_class_count(sc
); i
++) {
1491 g_ptr_array_add(event_classes
,
1492 (gpointer
) bt_stream_class_borrow_event_class_by_index_const(
1496 g_ptr_array_sort(event_classes
, (GCompareFunc
) compare_event_classes
);
1498 for (i
= 0; i
< event_classes
->len
; i
++) {
1499 write_event_class(ctx
, event_classes
->pdata
[i
]);
1503 g_ptr_array_free(event_classes
, TRUE
);
1507 gint
compare_stream_classes(const bt_stream_class
**a
, const bt_stream_class
**b
)
1509 uint64_t id_a
= bt_stream_class_get_id(*a
);
1510 uint64_t id_b
= bt_stream_class_get_id(*b
);
1514 } else if (id_a
> id_b
) {
1522 void write_trace_class(struct details_write_ctx
*ctx
, const bt_trace_class
*tc
)
1524 GPtrArray
*stream_classes
= g_ptr_array_new();
1526 bool printed_prop
= false;
1529 write_obj_type_name(ctx
, "Trace class");
1532 for (i
= 0; i
< bt_trace_class_get_stream_class_count(tc
); i
++) {
1533 g_ptr_array_add(stream_classes
,
1534 (gpointer
) bt_trace_class_borrow_stream_class_by_index_const(
1538 g_ptr_array_sort(stream_classes
, (GCompareFunc
) compare_stream_classes
);
1540 if (stream_classes
->len
> 0) {
1541 if (!printed_prop
) {
1542 g_string_append(ctx
->str
, ":\n");
1543 printed_prop
= true;
1549 /* Write user attributes */
1550 write_user_attributes(ctx
,
1551 bt_trace_class_borrow_user_attributes_const(tc
), true,
1554 /* Write stream classes */
1555 for (i
= 0; i
< stream_classes
->len
; i
++) {
1556 write_stream_class(ctx
, stream_classes
->pdata
[i
]);
1559 if (!printed_prop
) {
1564 g_ptr_array_free(stream_classes
, TRUE
);
1568 int try_write_meta(struct details_write_ctx
*ctx
, const bt_trace_class
*tc
,
1569 const bt_stream_class
*sc
, const bt_event_class
*ec
)
1575 if (details_need_to_write_trace_class(ctx
, tc
)) {
1578 if (ctx
->details_comp
->cfg
.compact
&&
1579 ctx
->details_comp
->printed_something
) {
1581 * There are no empty line between messages in
1582 * compact mode, so write one here to decouple
1583 * the trace class from the next message.
1589 * write_trace_class() also writes all its stream
1590 * classes their event classes, so we don't need to
1593 write_trace_class(ctx
, tc
);
1596 * Mark this trace class as written, as well as all
1597 * its stream classes and their event classes.
1599 ret
= details_did_write_trace_class(ctx
, tc
);
1604 for (sc_i
= 0; sc_i
< bt_trace_class_get_stream_class_count(tc
);
1607 const bt_stream_class
*tc_sc
=
1608 bt_trace_class_borrow_stream_class_by_index_const(
1611 details_did_write_meta_object(ctx
, tc
, tc_sc
);
1613 for (ec_i
= 0; ec_i
<
1614 bt_stream_class_get_event_class_count(tc_sc
);
1616 details_did_write_meta_object(ctx
, tc
,
1617 bt_stream_class_borrow_event_class_by_index_const(
1625 if (sc
&& details_need_to_write_meta_object(ctx
, tc
, sc
)) {
1630 if (ctx
->details_comp
->cfg
.compact
&&
1631 ctx
->details_comp
->printed_something
) {
1633 * There are no empty line between messages in
1634 * compact mode, so write one here to decouple
1635 * the stream class from the next message.
1641 * write_stream_class() also writes all its event
1642 * classes, so we don't need to rewrite `ec`.
1644 write_stream_class(ctx
, sc
);
1647 * Mark this stream class as written, as well as all its
1650 details_did_write_meta_object(ctx
, tc
, sc
);
1652 for (ec_i
= 0; ec_i
<
1653 bt_stream_class_get_event_class_count(sc
);
1655 details_did_write_meta_object(ctx
, tc
,
1656 bt_stream_class_borrow_event_class_by_index_const(
1663 if (ec
&& details_need_to_write_meta_object(ctx
, tc
, ec
)) {
1666 if (ctx
->details_comp
->cfg
.compact
&&
1667 ctx
->details_comp
->printed_something
) {
1669 * There are no empty line between messages in
1670 * compact mode, so write one here to decouple
1671 * the event class from the next message.
1676 write_event_class(ctx
, ec
);
1677 details_did_write_meta_object(ctx
, tc
, ec
);
1686 void write_time_str(struct details_write_ctx
*ctx
, const char *str
)
1688 if (!ctx
->details_comp
->cfg
.with_time
) {
1692 g_string_append_printf(ctx
->str
, "[%s%s%s%s]",
1693 color_bold(ctx
), color_fg_blue(ctx
), str
, color_reset(ctx
));
1695 if (ctx
->details_comp
->cfg
.compact
) {
1706 void write_time(struct details_write_ctx
*ctx
, const bt_clock_snapshot
*cs
)
1708 bt_clock_snapshot_get_ns_from_origin_status cs_status
;
1709 int64_t ns_from_origin
;
1712 if (!ctx
->details_comp
->cfg
.with_time
) {
1716 format_uint(buf
, bt_clock_snapshot_get_value(cs
), 10);
1717 g_string_append_printf(ctx
->str
, "[%s%s%s%s%s",
1718 color_bold(ctx
), color_fg_blue(ctx
), buf
,
1720 ctx
->details_comp
->cfg
.compact
? "" : " cycles");
1721 cs_status
= bt_clock_snapshot_get_ns_from_origin(cs
, &ns_from_origin
);
1722 if (cs_status
== BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OK
) {
1723 format_int(buf
, ns_from_origin
, 10);
1724 g_string_append_printf(ctx
->str
, "%s %s%s%s%s%s",
1725 ctx
->details_comp
->cfg
.compact
? "" : ",",
1726 color_bold(ctx
), color_fg_blue(ctx
), buf
,
1728 ctx
->details_comp
->cfg
.compact
? "" : " ns from origin");
1731 g_string_append(ctx
->str
, "]");
1733 if (ctx
->details_comp
->cfg
.compact
) {
1744 int write_message_follow_tag(struct details_write_ctx
*ctx
,
1745 const bt_stream
*stream
)
1748 uint64_t unique_trace_id
;
1749 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
1750 const bt_trace
*trace
= bt_stream_borrow_trace_const(stream
);
1752 ret
= details_trace_unique_id(ctx
, trace
, &unique_trace_id
);
1757 if (ctx
->details_comp
->cfg
.compact
) {
1758 g_string_append_printf(ctx
->str
,
1759 "%s{%s%" PRIu64
" %" PRIu64
" %" PRIu64
"%s%s}%s ",
1760 color_fg_cyan(ctx
), color_bold(ctx
),
1761 unique_trace_id
, bt_stream_class_get_id(sc
),
1762 bt_stream_get_id(stream
),
1763 color_reset(ctx
), color_fg_cyan(ctx
), color_reset(ctx
));
1765 g_string_append_printf(ctx
->str
,
1766 "%s{Trace %s%" PRIu64
"%s%s, Stream class ID %s%" PRIu64
"%s%s, Stream ID %s%" PRIu64
"%s%s}%s\n",
1768 color_bold(ctx
), unique_trace_id
,
1769 color_reset(ctx
), color_fg_cyan(ctx
),
1770 color_bold(ctx
), bt_stream_class_get_id(sc
),
1771 color_reset(ctx
), color_fg_cyan(ctx
),
1772 color_bold(ctx
), bt_stream_get_id(stream
),
1773 color_reset(ctx
), color_fg_cyan(ctx
),
1782 void write_field(struct details_write_ctx
*ctx
, const bt_field
*field
,
1786 bt_field_class_type fc_type
= bt_field_get_class_type(field
);
1787 const bt_field_class
*fc
;
1790 /* Write field's name */
1792 write_compound_member_name(ctx
, name
);
1795 /* Write field's value */
1797 case BT_FIELD_CLASS_TYPE_BOOL
:
1799 write_bool_prop_value(ctx
, bt_field_bool_get_value(field
));
1801 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
1802 format_uint(buf
, bt_field_bit_array_get_value_as_integer(field
),
1805 write_uint_str_prop_value(ctx
, buf
);
1807 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
1808 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
1809 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
1810 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
1812 unsigned int fmt_base
;
1813 bt_field_class_integer_preferred_display_base base
;
1815 fc
= bt_field_borrow_class_const(field
);
1816 base
= bt_field_class_integer_get_preferred_display_base(fc
);
1819 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
:
1822 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
:
1825 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
:
1828 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
:
1835 if (fc_type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
1836 fc_type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
) {
1838 bt_field_integer_unsigned_get_value(field
),
1841 write_uint_str_prop_value(ctx
, buf
);
1844 bt_field_integer_signed_get_value(field
),
1847 write_int_str_prop_value(ctx
, buf
);
1852 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
1854 write_float_prop_value(ctx
, bt_field_real_single_precision_get_value(field
));
1856 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
1858 write_float_prop_value(ctx
, bt_field_real_double_precision_get_value(field
));
1860 case BT_FIELD_CLASS_TYPE_STRING
:
1862 write_str_prop_value(ctx
, bt_field_string_get_value(field
));
1864 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
1866 uint64_t member_count
;
1868 fc
= bt_field_borrow_class_const(field
);
1869 member_count
= bt_field_class_structure_get_member_count(fc
);
1871 if (member_count
> 0) {
1874 for (i
= 0; i
< member_count
; i
++) {
1875 const bt_field_class_structure_member
*member
=
1876 bt_field_class_structure_borrow_member_by_index_const(
1878 const bt_field
*member_field
=
1879 bt_field_structure_borrow_member_field_by_index_const(
1883 write_field(ctx
, member_field
,
1884 bt_field_class_structure_member_get_name(member
));
1890 write_none_prop_value(ctx
, "Empty");
1895 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
1896 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
1898 uint64_t length
= bt_field_array_get_length(field
);
1902 write_none_prop_value(ctx
, "Empty");
1904 g_string_append(ctx
->str
, " Length ");
1905 write_uint_prop_value(ctx
, length
);
1906 g_string_append_c(ctx
->str
, ':');
1911 for (i
= 0; i
< length
; i
++) {
1912 const bt_field
*elem_field
=
1913 bt_field_array_borrow_element_field_by_index_const(
1917 write_array_index(ctx
, i
, color_fg_cyan(ctx
));
1918 write_field(ctx
, elem_field
, NULL
);
1924 case BT_FIELD_CLASS_TYPE_OPTION
:
1926 const bt_field
*content_field
=
1927 bt_field_option_borrow_field_const(field
);
1929 if (!content_field
) {
1931 write_none_prop_value(ctx
, "None");
1933 write_field(ctx
, content_field
, NULL
);
1938 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
1939 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
1940 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
1942 bt_field_variant_borrow_selected_option_field_const(
1951 void write_root_field(struct details_write_ctx
*ctx
, const char *name
,
1952 const bt_field
*field
)
1957 write_prop_name(ctx
, name
);
1958 g_string_append(ctx
->str
, ":");
1959 write_field(ctx
, field
, NULL
);
1964 int write_event_message(struct details_write_ctx
*ctx
,
1965 const bt_message
*msg
)
1968 const bt_event
*event
= bt_message_event_borrow_event_const(msg
);
1969 const bt_stream
*stream
= bt_event_borrow_stream_const(event
);
1970 const bt_event_class
*ec
= bt_event_borrow_class_const(event
);
1971 const bt_stream_class
*sc
= bt_event_class_borrow_stream_class_const(ec
);
1972 const bt_trace_class
*tc
= bt_stream_class_borrow_trace_class_const(sc
);
1973 const char *ec_name
;
1974 const bt_field
*field
;
1976 ret
= try_write_meta(ctx
, tc
, sc
, ec
);
1981 if (!ctx
->details_comp
->cfg
.with_data
) {
1985 if (ctx
->str
->len
> 0) {
1987 * Output buffer contains metadata: separate blocks with
1994 if (bt_stream_class_borrow_default_clock_class_const(sc
)) {
1996 bt_message_event_borrow_default_clock_snapshot_const(
2000 /* Write follow tag for message */
2001 ret
= write_message_follow_tag(ctx
, stream
);
2006 /* Write object's basic properties */
2007 write_obj_type_name(ctx
, "Event");
2008 ec_name
= bt_event_class_get_name(ec
);
2010 g_string_append_printf(ctx
->str
, " `%s%s%s`",
2011 color_fg_green(ctx
), ec_name
, color_reset(ctx
));
2014 g_string_append(ctx
->str
, " (");
2016 if (!ctx
->details_comp
->cfg
.compact
) {
2017 g_string_append(ctx
->str
, "Class ID ");
2020 write_uint_prop_value(ctx
, bt_event_class_get_id(ec
));
2021 g_string_append(ctx
->str
, ")");
2023 if (ctx
->details_comp
->cfg
.compact
) {
2029 g_string_append(ctx
->str
, ":\n");
2031 field
= bt_event_borrow_common_context_field_const(event
);
2033 write_root_field(ctx
, "Common context", field
);
2036 field
= bt_event_borrow_specific_context_field_const(event
);
2038 write_root_field(ctx
, "Specific context", field
);
2041 field
= bt_event_borrow_payload_field_const(event
);
2043 write_root_field(ctx
, "Payload", field
);
2053 gint
compare_streams(const bt_stream
**a
, const bt_stream
**b
)
2055 uint64_t id_a
= bt_stream_get_id(*a
);
2056 uint64_t id_b
= bt_stream_get_id(*b
);
2060 } else if (id_a
> id_b
) {
2063 const bt_stream_class
*a_sc
= bt_stream_borrow_class_const(*a
);
2064 const bt_stream_class
*b_sc
= bt_stream_borrow_class_const(*b
);
2065 uint64_t a_sc_id
= bt_stream_class_get_id(a_sc
);
2066 uint64_t b_sc_id
= bt_stream_class_get_id(b_sc
);
2068 if (a_sc_id
< b_sc_id
) {
2070 } else if (a_sc_id
> b_sc_id
) {
2079 void write_trace(struct details_write_ctx
*ctx
, const bt_trace
*trace
)
2082 GPtrArray
*streams
= g_ptr_array_new();
2084 bool printed_prop
= false;
2085 GPtrArray
*env_names
= g_ptr_array_new();
2089 write_obj_type_name(ctx
, "Trace");
2092 if (ctx
->details_comp
->cfg
.with_trace_name
) {
2093 name
= bt_trace_get_name(trace
);
2095 g_string_append(ctx
->str
, " `");
2096 write_str_prop_value(ctx
, name
);
2097 g_string_append(ctx
->str
, "`");
2101 /* Write properties */
2105 if (ctx
->details_comp
->cfg
.with_uuid
) {
2106 bt_uuid uuid
= bt_trace_get_uuid(trace
);
2109 if (!printed_prop
) {
2110 g_string_append(ctx
->str
, ":\n");
2111 printed_prop
= true;
2114 write_uuid_prop_line(ctx
, "UUID", uuid
);
2118 /* Write environment */
2119 env_count
= bt_trace_get_environment_entry_count(trace
);
2120 if (env_count
> 0) {
2121 if (!printed_prop
) {
2122 g_string_append(ctx
->str
, ":\n");
2123 printed_prop
= true;
2127 write_prop_name(ctx
, "Environment");
2128 g_string_append(ctx
->str
, " (");
2129 write_uint_prop_value(ctx
, env_count
);
2130 g_string_append_printf(ctx
->str
, " entr%s):",
2131 env_count
== 1 ? "y" : "ies");
2135 for (i
= 0; i
< env_count
; i
++) {
2137 const bt_value
*value
;
2139 bt_trace_borrow_environment_entry_by_index_const(
2140 trace
, i
, &name
, &value
);
2141 g_ptr_array_add(env_names
, (gpointer
) name
);
2144 g_ptr_array_sort(env_names
, (GCompareFunc
) compare_strings
);
2146 for (i
= 0; i
< env_names
->len
; i
++) {
2147 const char *name
= env_names
->pdata
[i
];
2148 const bt_value
*value
=
2149 bt_trace_borrow_environment_entry_value_by_name_const(
2153 write_compound_member_name(ctx
, name
);
2156 if (bt_value_get_type(value
) ==
2157 BT_VALUE_TYPE_SIGNED_INTEGER
) {
2158 write_int_prop_value(ctx
,
2159 bt_value_integer_signed_get(value
));
2160 } else if (bt_value_get_type(value
) ==
2161 BT_VALUE_TYPE_STRING
) {
2162 write_str_prop_value(ctx
,
2163 bt_value_string_get(value
));
2174 for (i
= 0; i
< bt_trace_get_stream_count(trace
); i
++) {
2175 g_ptr_array_add(streams
,
2176 (gpointer
) bt_trace_borrow_stream_by_index_const(
2180 g_ptr_array_sort(streams
, (GCompareFunc
) compare_streams
);
2182 if (streams
->len
> 0 && !printed_prop
) {
2183 g_string_append(ctx
->str
, ":\n");
2184 printed_prop
= true;
2187 for (i
= 0; i
< streams
->len
; i
++) {
2188 const bt_stream
*stream
= streams
->pdata
[i
];
2191 write_obj_type_name(ctx
, "Stream");
2192 g_string_append(ctx
->str
, " (ID ");
2193 write_uint_prop_value(ctx
, bt_stream_get_id(stream
));
2194 g_string_append(ctx
->str
, ", Class ID ");
2195 write_uint_prop_value(ctx
, bt_stream_class_get_id(
2196 bt_stream_borrow_class_const(stream
)));
2197 g_string_append(ctx
->str
, ")");
2203 if (!printed_prop
) {
2207 g_ptr_array_free(streams
, TRUE
);
2208 g_ptr_array_free(env_names
, TRUE
);
2212 int write_stream_beginning_message(struct details_write_ctx
*ctx
,
2213 const bt_message
*msg
)
2216 const bt_stream
*stream
=
2217 bt_message_stream_beginning_borrow_stream_const(msg
);
2218 const bt_trace
*trace
= bt_stream_borrow_trace_const(stream
);
2219 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2220 const bt_clock_class
*cc
= bt_stream_class_borrow_default_clock_class_const(sc
);
2221 const bt_trace_class
*tc
= bt_stream_class_borrow_trace_class_const(sc
);
2224 ret
= try_write_meta(ctx
, tc
, sc
, NULL
);
2229 if (!ctx
->details_comp
->cfg
.with_data
) {
2233 if (ctx
->str
->len
> 0) {
2235 * Output buffer contains metadata: separate blocks with
2243 const bt_clock_snapshot
*cs
;
2244 bt_message_stream_clock_snapshot_state cs_state
=
2245 bt_message_stream_beginning_borrow_default_clock_snapshot_const(msg
, &cs
);
2247 if (cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
2248 write_time(ctx
, cs
);
2250 write_time_str(ctx
, "Unknown");
2254 /* Write follow tag for message */
2255 ret
= write_message_follow_tag(ctx
, stream
);
2260 /* Write stream properties */
2261 write_obj_type_name(ctx
, "Stream beginning");
2263 if (ctx
->details_comp
->cfg
.compact
) {
2268 g_string_append(ctx
->str
, ":\n");
2271 if (ctx
->details_comp
->cfg
.with_stream_name
) {
2272 name
= bt_stream_get_name(stream
);
2274 write_str_prop_line(ctx
, "Name", name
);
2278 if (ctx
->details_comp
->cfg
.with_stream_class_name
) {
2279 name
= bt_stream_class_get_name(sc
);
2281 write_str_prop_line(ctx
, "Class name", name
);
2285 write_trace(ctx
, trace
);
2293 int write_stream_end_message(struct details_write_ctx
*ctx
,
2294 const bt_message
*msg
)
2297 const bt_stream
*stream
=
2298 bt_message_stream_end_borrow_stream_const(msg
);
2299 const bt_stream_class
*sc
=
2300 bt_stream_borrow_class_const(stream
);
2301 const bt_clock_class
*cc
=
2302 bt_stream_class_borrow_default_clock_class_const(sc
);
2304 if (!ctx
->details_comp
->cfg
.with_data
) {
2310 const bt_clock_snapshot
*cs
;
2311 bt_message_stream_clock_snapshot_state cs_state
=
2312 bt_message_stream_end_borrow_default_clock_snapshot_const(msg
, &cs
);
2314 if (cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
2315 write_time(ctx
, cs
);
2317 write_time_str(ctx
, "Unknown");
2321 /* Write follow tag for message */
2322 ret
= write_message_follow_tag(ctx
, stream
);
2327 /* Write stream properties */
2328 write_obj_type_name(ctx
, "Stream end\n");
2335 int write_packet_beginning_message(struct details_write_ctx
*ctx
,
2336 const bt_message
*msg
)
2339 const bt_packet
*packet
=
2340 bt_message_packet_beginning_borrow_packet_const(msg
);
2341 const bt_stream
*stream
= bt_packet_borrow_stream_const(packet
);
2342 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2343 const bt_field
*field
;
2345 if (!ctx
->details_comp
->cfg
.with_data
) {
2350 if (bt_stream_class_packets_have_beginning_default_clock_snapshot(sc
)) {
2352 bt_message_packet_beginning_borrow_default_clock_snapshot_const(
2356 /* Write follow tag for message */
2357 ret
= write_message_follow_tag(ctx
, stream
);
2362 write_obj_type_name(ctx
, "Packet beginning");
2364 if (ctx
->details_comp
->cfg
.compact
) {
2370 field
= bt_packet_borrow_context_field_const(packet
);
2372 g_string_append(ctx
->str
, ":\n");
2374 write_root_field(ctx
, "Context", field
);
2385 int write_discarded_items_message(struct details_write_ctx
*ctx
,
2386 const char *name
, const bt_stream
*stream
,
2387 const bt_clock_snapshot
*beginning_cs
,
2388 const bt_clock_snapshot
*end_cs
, uint64_t count
)
2394 write_time(ctx
, beginning_cs
);
2396 write_time(ctx
, end_cs
);
2399 /* Write follow tag for message */
2400 ret
= write_message_follow_tag(ctx
, stream
);
2405 write_obj_type_name(ctx
, "Discarded ");
2406 write_obj_type_name(ctx
, name
);
2409 if (count
== UINT64_C(-1)) {
2414 g_string_append(ctx
->str
, " (");
2415 write_uint_prop_value(ctx
, count
);
2416 g_string_append_printf(ctx
->str
, " %s)\n", name
);
2423 int write_discarded_events_message(struct details_write_ctx
*ctx
,
2424 const bt_message
*msg
)
2427 const bt_stream
*stream
= bt_message_discarded_events_borrow_stream_const(
2429 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2430 const bt_clock_snapshot
*beginning_cs
= NULL
;
2431 const bt_clock_snapshot
*end_cs
= NULL
;
2434 if (!ctx
->details_comp
->cfg
.with_data
) {
2438 if (bt_stream_class_discarded_events_have_default_clock_snapshots(sc
)) {
2440 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
2443 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
2447 if (bt_message_discarded_events_get_count(msg
, &count
) !=
2448 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
2449 count
= UINT64_C(-1);
2452 ret
= write_discarded_items_message(ctx
, "events", stream
,
2453 beginning_cs
, end_cs
, count
);
2460 int write_discarded_packets_message(struct details_write_ctx
*ctx
,
2461 const bt_message
*msg
)
2464 const bt_stream
*stream
= bt_message_discarded_packets_borrow_stream_const(
2466 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2467 const bt_clock_snapshot
*beginning_cs
= NULL
;
2468 const bt_clock_snapshot
*end_cs
= NULL
;
2471 if (!ctx
->details_comp
->cfg
.with_data
) {
2475 if (bt_stream_class_discarded_packets_have_default_clock_snapshots(sc
)) {
2477 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
2480 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
2484 if (bt_message_discarded_packets_get_count(msg
, &count
) !=
2485 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
2486 count
= UINT64_C(-1);
2489 ret
= write_discarded_items_message(ctx
, "packets", stream
,
2490 beginning_cs
, end_cs
, count
);
2497 int write_packet_end_message(struct details_write_ctx
*ctx
,
2498 const bt_message
*msg
)
2501 const bt_packet
*packet
=
2502 bt_message_packet_end_borrow_packet_const(msg
);
2503 const bt_stream
*stream
= bt_packet_borrow_stream_const(packet
);
2504 const bt_stream_class
*sc
= bt_stream_borrow_class_const(stream
);
2506 if (!ctx
->details_comp
->cfg
.with_data
) {
2511 if (bt_stream_class_packets_have_end_default_clock_snapshot(sc
)) {
2513 bt_message_packet_end_borrow_default_clock_snapshot_const(
2517 /* Write follow tag for message */
2518 ret
= write_message_follow_tag(ctx
, stream
);
2523 write_obj_type_name(ctx
, "Packet end");
2531 int write_message_iterator_inactivity_message(struct details_write_ctx
*ctx
,
2532 const bt_message
*msg
)
2535 const bt_clock_snapshot
*cs
=
2536 bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
2540 write_time(ctx
, cs
);
2541 write_obj_type_name(ctx
, "Message iterator inactivity");
2543 if (ctx
->details_comp
->cfg
.compact
) {
2548 /* Write clock class properties */
2549 g_string_append(ctx
->str
, ":\n");
2552 write_prop_name(ctx
, "Clock class");
2553 g_string_append_c(ctx
->str
, ':');
2556 write_clock_class_prop_lines(ctx
,
2557 bt_clock_snapshot_borrow_clock_class_const(cs
));
2565 int details_write_message(struct details_comp
*details_comp
,
2566 const bt_message
*msg
)
2569 struct details_write_ctx ctx
= {
2570 .details_comp
= details_comp
,
2571 .str
= details_comp
->str
,
2575 /* Reset output buffer */
2576 g_string_assign(details_comp
->str
, "");
2578 switch (bt_message_get_type(msg
)) {
2579 case BT_MESSAGE_TYPE_EVENT
:
2580 ret
= write_event_message(&ctx
, msg
);
2582 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
2583 ret
= write_message_iterator_inactivity_message(&ctx
, msg
);
2585 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
2586 ret
= write_stream_beginning_message(&ctx
, msg
);
2588 case BT_MESSAGE_TYPE_STREAM_END
:
2589 ret
= write_stream_end_message(&ctx
, msg
);
2591 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
2592 ret
= write_packet_beginning_message(&ctx
, msg
);
2594 case BT_MESSAGE_TYPE_PACKET_END
:
2595 ret
= write_packet_end_message(&ctx
, msg
);
2597 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
2598 ret
= write_discarded_events_message(&ctx
, msg
);
2600 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
2601 ret
= write_discarded_packets_message(&ctx
, msg
);
2608 * If this component printed at least one character so far, and
2609 * we're not in compact mode, and there's something in the
2610 * output buffer for this message, then prepend a newline to the
2611 * output buffer to visually separate message blocks.
2613 if (details_comp
->printed_something
&& !details_comp
->cfg
.compact
&&
2614 details_comp
->str
->len
> 0) {
2615 /* TODO: Optimize this */
2616 g_string_prepend_c(details_comp
->str
, '\n');