X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Ftext%2Fpretty%2Fprint.c;h=78e8fdbbf49e835dba5be21ab96f8fde849c20df;hb=b8ddb4f036272e30030202637201d11baf5f20a5;hp=2c9ae83da3d7709809405b8c9d63f256601566dd;hpb=60bbfc7c8b30e092afdf97554a72cc25706ef8e9;p=babeltrace.git diff --git a/src/plugins/text/pretty/print.c b/src/plugins/text/pretty/print.c index 2c9ae83d..78e8fdbb 100644 --- a/src/plugins/text/pretty/print.c +++ b/src/plugins/text/pretty/print.c @@ -53,29 +53,32 @@ struct timestamp { static int print_field(struct pretty_component *pretty, - const bt_field *field, bool print_names, - GQuark *filters_fields, int filter_array_len); + const bt_field *field, bool print_names); static void print_name_equal(struct pretty_component *pretty, const char *name) { if (pretty->use_colors) { - g_string_append_printf(pretty->string, "%s%s%s = ", COLOR_NAME, - name, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_NAME); + bt_common_g_string_append(pretty->string, name); + bt_common_g_string_append(pretty->string, COLOR_RST); } else { - g_string_append_printf(pretty->string, "%s = ", name); + bt_common_g_string_append(pretty->string, name); } + bt_common_g_string_append(pretty->string, " = "); } static void print_field_name_equal(struct pretty_component *pretty, const char *name) { if (pretty->use_colors) { - g_string_append_printf(pretty->string, "%s%s%s = ", - COLOR_FIELD_NAME, name, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_FIELD_NAME); + bt_common_g_string_append(pretty->string, name); + bt_common_g_string_append(pretty->string, COLOR_RST); } else { - g_string_append_printf(pretty->string, "%s = ", name); + bt_common_g_string_append(pretty->string, name); } + bt_common_g_string_append(pretty->string, " = "); } static @@ -85,7 +88,7 @@ void print_timestamp_cycles(struct pretty_component *pretty, uint64_t cycles; cycles = bt_clock_snapshot_get_value(clock_snapshot); - g_string_append_printf(pretty->string, "%020" PRIu64, cycles); + bt_common_g_string_append_printf(pretty->string, "%020" PRIu64, cycles); if (update_last) { if (pretty->last_cycles_timestamp != -1ULL) { @@ -107,14 +110,14 @@ void print_timestamp_wall(struct pretty_component *pretty, bool is_negative; if (!clock_snapshot) { - g_string_append(pretty->string, "??:??:??.?????????"); + bt_common_g_string_append(pretty->string, "??:??:??.?????????"); return; } ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &ts_nsec); if (ret) { // TODO: log, this is unexpected - g_string_append(pretty->string, "Error"); + bt_common_g_string_append(pretty->string, "Error"); return; } @@ -198,17 +201,17 @@ void print_timestamp_wall(struct pretty_component *pretty, goto seconds; } - g_string_append(pretty->string, timestr); + bt_common_g_string_append(pretty->string, timestr); } /* Print time in HH:MM:SS.ns */ - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "%02d:%02d:%02d.%09" PRIu64, tm.tm_hour, tm.tm_min, tm.tm_sec, ts_nsec_abs); goto end; } seconds: - g_string_append_printf(pretty->string, "%s%" PRId64 ".%09" PRIu64, + bt_common_g_string_append_printf(pretty->string, "%s%" PRId64 ".%09" PRIu64, is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs); end: return; @@ -233,10 +236,10 @@ int print_event_timestamp(struct pretty_component *pretty, if (print_names) { print_name_equal(pretty, "timestamp"); } else { - g_string_append(pretty->string, "["); + bt_common_g_string_append(pretty->string, "["); } if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_TIMESTAMP); + bt_common_g_string_append(pretty->string, COLOR_TIMESTAMP); } if (pretty->options.print_timestamp_cycles) { print_timestamp_cycles(pretty, clock_snapshot, true); @@ -244,25 +247,25 @@ int print_event_timestamp(struct pretty_component *pretty, print_timestamp_wall(pretty, clock_snapshot, true); } if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_RST); } if (!print_names) - g_string_append(pretty->string, "] "); + bt_common_g_string_append(pretty->string, "] "); if (pretty->options.print_delta_field) { if (print_names) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); print_name_equal(pretty, "delta"); } else { - g_string_append(pretty->string, "("); + bt_common_g_string_append(pretty->string, "("); } if (pretty->options.print_timestamp_cycles) { if (pretty->delta_cycles == -1ULL) { - g_string_append(pretty->string, + bt_common_g_string_append(pretty->string, "+??????????\?\?"); /* Not a trigraph. */ } else { - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "+%012" PRIu64, pretty->delta_cycles); } } else { @@ -272,15 +275,15 @@ int print_event_timestamp(struct pretty_component *pretty, delta = pretty->delta_real_timestamp; delta_sec = delta / NSEC_PER_SEC; delta_nsec = delta % NSEC_PER_SEC; - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "+%" PRIu64 ".%09" PRIu64, delta_sec, delta_nsec); } else { - g_string_append(pretty->string, "+?.?????????"); + bt_common_g_string_append(pretty->string, "+?.?????????"); } } if (!print_names) { - g_string_append(pretty->string, ") "); + bt_common_g_string_append(pretty->string, ") "); } } *start_line = !print_names; @@ -316,16 +319,16 @@ int print_event_header(struct pretty_component *pretty, name = bt_trace_get_name(trace); if (name) { if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } if (print_names) { print_name_equal(pretty, "trace"); } - g_string_append(pretty->string, name); + bt_common_g_string_append(pretty->string, name); if (print_names) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } } } @@ -338,13 +341,13 @@ int print_event_header(struct pretty_component *pretty, const char *str; if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } if (print_names) { print_name_equal(pretty, "trace:hostname"); } str = bt_value_string_get(hostname_str); - g_string_append(pretty->string, str); + bt_common_g_string_append(pretty->string, str); dom_print = 1; } } @@ -357,15 +360,15 @@ int print_event_header(struct pretty_component *pretty, const char *str; if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } if (print_names) { print_name_equal(pretty, "trace:domain"); } else if (dom_print) { - g_string_append(pretty->string, ":"); + bt_common_g_string_append(pretty->string, ":"); } str = bt_value_string_get(domain_str); - g_string_append(pretty->string, str); + bt_common_g_string_append(pretty->string, str); dom_print = 1; } } @@ -378,15 +381,15 @@ int print_event_header(struct pretty_component *pretty, const char *str; if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } if (print_names) { print_name_equal(pretty, "trace:procname"); } else if (dom_print) { - g_string_append(pretty->string, ":"); + bt_common_g_string_append(pretty->string, ":"); } str = bt_value_string_get(procname_str); - g_string_append(pretty->string, str); + bt_common_g_string_append(pretty->string, str); dom_print = 1; } } @@ -399,15 +402,15 @@ int print_event_header(struct pretty_component *pretty, int64_t value; if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } if (print_names) { print_name_equal(pretty, "trace:vpid"); } else if (dom_print) { - g_string_append(pretty->string, ":"); + bt_common_g_string_append(pretty->string, ":"); } value = bt_value_integer_signed_get(vpid_value); - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "(%" PRId64 ")", value); dom_print = 1; } @@ -440,16 +443,16 @@ int print_event_header(struct pretty_component *pretty, BT_ASSERT(log_level_str); if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } if (print_names) { print_name_equal(pretty, "loglevel"); } else if (dom_print) { - g_string_append(pretty->string, ":"); + bt_common_g_string_append(pretty->string, ":"); } - g_string_append(pretty->string, log_level_str); - g_string_append_printf( + bt_common_g_string_append(pretty->string, log_level_str); + bt_common_g_string_append_printf( pretty->string, " (%d)", (int) log_level); dom_print = 1; } @@ -460,23 +463,23 @@ int print_event_header(struct pretty_component *pretty, uri_str = bt_event_class_get_emf_uri(event_class); if (uri_str) { if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } if (print_names) { print_name_equal(pretty, "model.emf.uri"); } else if (dom_print) { - g_string_append(pretty->string, ":"); + bt_common_g_string_append(pretty->string, ":"); } - g_string_append(pretty->string, uri_str); + bt_common_g_string_append(pretty->string, uri_str); dom_print = 1; } } if (dom_print && !print_names) { - g_string_append(pretty->string, " "); + bt_common_g_string_append(pretty->string, " "); } if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } pretty->start_line = true; if (print_names) { @@ -485,23 +488,25 @@ int print_event_header(struct pretty_component *pretty, ev_name = bt_event_class_get_name(event_class); if (pretty->use_colors) { if (ev_name) { - g_string_append(pretty->string, COLOR_EVENT_NAME); + bt_common_g_string_append(pretty->string, + COLOR_EVENT_NAME); } else { - g_string_append(pretty->string, COLOR_UNKNOWN); + bt_common_g_string_append(pretty->string, + COLOR_UNKNOWN); } } if (ev_name) { - g_string_append(pretty->string, ev_name); + bt_common_g_string_append(pretty->string, ev_name); } else { - g_string_append(pretty->string, ""); + bt_common_g_string_append(pretty->string, ""); } if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_RST); } if (!print_names) { - g_string_append(pretty->string, ": "); + bt_common_g_string_append(pretty->string, ": "); } else { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } end: @@ -533,7 +538,7 @@ int print_integer(struct pretty_component *pretty, } if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_NUMBER_VALUE); + bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE); rst_color = true; } @@ -544,10 +549,11 @@ int print_integer(struct pretty_component *pretty, int bitnr, len; len = bt_field_class_integer_get_field_value_range(int_fc); - g_string_append(pretty->string, "0b"); + bt_common_g_string_append(pretty->string, "0b"); _bt_safe_lshift(v.u, 64 - len); for (bitnr = 0; bitnr < len; bitnr++) { - g_string_append_printf(pretty->string, "%u", (v.u & (1ULL << 63)) ? 1 : 0); + bt_common_g_string_append_c(pretty->string, + (v.u & (1ULL << 63)) ? '1' : '0'); _bt_safe_lshift(v.u, 1); } break; @@ -570,15 +576,15 @@ int print_integer(struct pretty_component *pretty, } } - g_string_append_printf(pretty->string, "0%" PRIo64, v.u); + bt_common_g_string_append_printf(pretty->string, "0%" PRIo64, v.u); break; } case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL: if (ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) { - g_string_append_printf(pretty->string, "%" PRIu64, v.u); + bt_common_g_string_append_printf(pretty->string, "%" PRIu64, v.u); } else { - g_string_append_printf(pretty->string, "%" PRId64, v.s); + bt_common_g_string_append_printf(pretty->string, "%" PRId64, v.s); } break; case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL: @@ -593,7 +599,7 @@ int print_integer(struct pretty_component *pretty, v.u &= ((uint64_t) 1 << rounded_len) - 1; } - g_string_append_printf(pretty->string, "0x%" PRIX64, v.u); + bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64, v.u); break; } default: @@ -602,7 +608,7 @@ int print_integer(struct pretty_component *pretty, } end: if (rst_color) { - g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_RST); } return ret; } @@ -612,67 +618,67 @@ void print_escape_string(struct pretty_component *pretty, const char *str) { int i; - g_string_append_c(pretty->string, '"'); + bt_common_g_string_append_c(pretty->string, '"'); for (i = 0; i < strlen(str); i++) { /* Escape sequences not recognized by iscntrl(). */ switch (str[i]) { case '\\': - g_string_append(pretty->string, "\\\\"); + bt_common_g_string_append(pretty->string, "\\\\"); continue; case '\'': - g_string_append(pretty->string, "\\\'"); + bt_common_g_string_append(pretty->string, "\\\'"); continue; case '\"': - g_string_append(pretty->string, "\\\""); + bt_common_g_string_append(pretty->string, "\\\""); continue; case '\?': - g_string_append(pretty->string, "\\\?"); + bt_common_g_string_append(pretty->string, "\\\?"); continue; } /* Standard characters. */ if (!iscntrl(str[i])) { - g_string_append_c(pretty->string, str[i]); + bt_common_g_string_append_c(pretty->string, str[i]); continue; } switch (str[i]) { case '\0': - g_string_append(pretty->string, "\\0"); + bt_common_g_string_append(pretty->string, "\\0"); break; case '\a': - g_string_append(pretty->string, "\\a"); + bt_common_g_string_append(pretty->string, "\\a"); break; case '\b': - g_string_append(pretty->string, "\\b"); + bt_common_g_string_append(pretty->string, "\\b"); break; case '\e': - g_string_append(pretty->string, "\\e"); + bt_common_g_string_append(pretty->string, "\\e"); break; case '\f': - g_string_append(pretty->string, "\\f"); + bt_common_g_string_append(pretty->string, "\\f"); break; case '\n': - g_string_append(pretty->string, "\\n"); + bt_common_g_string_append(pretty->string, "\\n"); break; case '\r': - g_string_append(pretty->string, "\\r"); + bt_common_g_string_append(pretty->string, "\\r"); break; case '\t': - g_string_append(pretty->string, "\\t"); + bt_common_g_string_append(pretty->string, "\\t"); break; case '\v': - g_string_append(pretty->string, "\\v"); + bt_common_g_string_append(pretty->string, "\\v"); break; default: /* Unhandled control-sequence, print as hex. */ - g_string_append_printf(pretty->string, "\\x%02x", str[i]); + bt_common_g_string_append_printf(pretty->string, "\\x%02x", str[i]); break; } } - g_string_append_c(pretty->string, '"'); + bt_common_g_string_append_c(pretty->string, '"'); } static @@ -709,14 +715,14 @@ int print_enum(struct pretty_component *pretty, goto end; } - g_string_append(pretty->string, "( "); + bt_common_g_string_append(pretty->string, "( "); if (label_count == 0) { if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_UNKNOWN); + bt_common_g_string_append(pretty->string, COLOR_UNKNOWN); } - g_string_append(pretty->string, ""); + bt_common_g_string_append(pretty->string, ""); if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_RST); } goto skip_loop; } @@ -724,52 +730,32 @@ int print_enum(struct pretty_component *pretty, const char *mapping_name = label_array[i]; if (i != 0) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_ENUM_MAPPING_NAME); + bt_common_g_string_append(pretty->string, COLOR_ENUM_MAPPING_NAME); } print_escape_string(pretty, mapping_name); if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_RST); } } skip_loop: - g_string_append(pretty->string, " : container = "); + bt_common_g_string_append(pretty->string, " : container = "); ret = print_integer(pretty, field); if (ret != 0) { goto end; } - g_string_append(pretty->string, " )"); + bt_common_g_string_append(pretty->string, " )"); end: return ret; } -static -int filter_field_name(struct pretty_component *pretty, const char *field_name, - GQuark *filter_fields, int filter_array_len) -{ - int i; - GQuark field_quark = g_quark_try_string(field_name); - - if (!field_quark || pretty->options.verbose) { - return 1; - } - - for (i = 0; i < filter_array_len; i++) { - if (field_quark == filter_fields[i]) { - return 0; - } - } - return 1; -} - static int print_struct_field(struct pretty_component *pretty, const bt_field *_struct, const bt_field_class *struct_class, - uint64_t i, bool print_names, uint64_t *nr_printed_fields, - GQuark *filter_fields, int filter_array_len) + uint64_t i, bool print_names, uint64_t *nr_printed_fields) { int ret = 0; const char *field_name; @@ -786,21 +772,15 @@ int print_struct_field(struct pretty_component *pretty, struct_class, i); field_name = bt_field_class_structure_member_get_name(member); - if (filter_fields && !filter_field_name(pretty, field_name, - filter_fields, filter_array_len)) { - ret = 0; - goto end; - } - if (*nr_printed_fields > 0) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } else { - g_string_append(pretty->string, " "); + bt_common_g_string_append(pretty->string, " "); } if (print_names) { print_field_name_equal(pretty, field_name); } - ret = print_field(pretty, field, print_names, NULL, 0); + ret = print_field(pretty, field, print_names); *nr_printed_fields += 1; end: @@ -809,8 +789,7 @@ end: static int print_struct(struct pretty_component *pretty, - const bt_field *_struct, bool print_names, - GQuark *filter_fields, int filter_array_len) + const bt_field *_struct, bool print_names) { int ret = 0; const bt_field_class *struct_class = NULL; @@ -824,19 +803,18 @@ int print_struct(struct pretty_component *pretty, nr_fields = bt_field_class_structure_get_member_count(struct_class); - g_string_append(pretty->string, "{"); + bt_common_g_string_append(pretty->string, "{"); pretty->depth++; nr_printed_fields = 0; for (i = 0; i < nr_fields; i++) { ret = print_struct_field(pretty, _struct, struct_class, i, - print_names, &nr_printed_fields, filter_fields, - filter_array_len); + print_names, &nr_printed_fields); if (ret != 0) { goto end; } } pretty->depth--; - g_string_append(pretty->string, " }"); + bt_common_g_string_append(pretty->string, " }"); end: return ret; @@ -849,17 +827,17 @@ int print_array_field(struct pretty_component *pretty, const bt_field *field = NULL; if (i != 0) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } else { - g_string_append(pretty->string, " "); + bt_common_g_string_append(pretty->string, " "); } if (print_names) { - g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); + bt_common_g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); } field = bt_field_array_borrow_element_field_by_index_const(array, i); BT_ASSERT(field); - return print_field(pretty, field, print_names, NULL, 0); + return print_field(pretty, field, print_names); } static @@ -877,7 +855,7 @@ int print_array(struct pretty_component *pretty, goto end; } len = bt_field_array_get_length(array); - g_string_append(pretty->string, "["); + bt_common_g_string_append(pretty->string, "["); pretty->depth++; for (i = 0; i < len; i++) { ret = print_array_field(pretty, array, i, print_names); @@ -886,7 +864,7 @@ int print_array(struct pretty_component *pretty, } } pretty->depth--; - g_string_append(pretty->string, " ]"); + bt_common_g_string_append(pretty->string, " ]"); end: return ret; @@ -899,17 +877,17 @@ int print_sequence_field(struct pretty_component *pretty, const bt_field *field = NULL; if (i != 0) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } else { - g_string_append(pretty->string, " "); + bt_common_g_string_append(pretty->string, " "); } if (print_names) { - g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); + bt_common_g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); } field = bt_field_array_borrow_element_field_by_index_const(seq, i); BT_ASSERT(field); - return print_field(pretty, field, print_names, NULL, 0); + return print_field(pretty, field, print_names); } static @@ -921,7 +899,7 @@ int print_sequence(struct pretty_component *pretty, uint64_t i; len = bt_field_array_get_length(seq); - g_string_append(pretty->string, "["); + bt_common_g_string_append(pretty->string, "["); pretty->depth++; for (i = 0; i < len; i++) { @@ -931,7 +909,36 @@ int print_sequence(struct pretty_component *pretty, } } pretty->depth--; - g_string_append(pretty->string, " ]"); + bt_common_g_string_append(pretty->string, " ]"); + +end: + return ret; +} + +static +int print_option(struct pretty_component *pretty, + const bt_field *option, bool print_names) +{ + int ret = 0; + const bt_field *field = NULL; + + field = bt_field_option_borrow_field_const(option); + if (field) { + bt_common_g_string_append(pretty->string, "{ "); + pretty->depth++; + if (print_names) { + // TODO: find tag's name using field path + // print_field_name_equal(pretty, tag_choice); + } + ret = print_field(pretty, field, print_names); + if (ret != 0) { + goto end; + } + pretty->depth--; + bt_common_g_string_append(pretty->string, " }"); + } else { + bt_common_g_string_append(pretty->string, ""); + } end: return ret; @@ -946,18 +953,18 @@ int print_variant(struct pretty_component *pretty, field = bt_field_variant_borrow_selected_option_field_const(variant); BT_ASSERT(field); - g_string_append(pretty->string, "{ "); + bt_common_g_string_append(pretty->string, "{ "); pretty->depth++; if (print_names) { // TODO: find tag's name using field path // print_field_name_equal(pretty, tag_choice); } - ret = print_field(pretty, field, print_names, NULL, 0); + ret = print_field(pretty, field, print_names); if (ret != 0) { goto end; } pretty->depth--; - g_string_append(pretty->string, " }"); + bt_common_g_string_append(pretty->string, " }"); end: return ret; @@ -965,27 +972,67 @@ end: static int print_field(struct pretty_component *pretty, - const bt_field *field, bool print_names, - GQuark *filter_fields, int filter_array_len) + const bt_field *field, bool print_names) { bt_field_class_type class_id; class_id = bt_field_get_class_type(field); switch (class_id) { + case BT_FIELD_CLASS_TYPE_BOOL: + { + bt_bool v; + const char *text; + + v = bt_field_bool_get_value(field); + if (pretty->use_colors) { + bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE); + } + if (v) { + text = "true"; + } else { + text = "false"; + } + bt_common_g_string_append(pretty->string, text); + if (pretty->use_colors) { + bt_common_g_string_append(pretty->string, COLOR_RST); + } + return 0; + } + case BT_FIELD_CLASS_TYPE_BIT_ARRAY: + { + uint64_t v = bt_field_bit_array_get_value_as_integer(field); + + if (pretty->use_colors) { + bt_common_g_string_append(pretty->string, + COLOR_NUMBER_VALUE); + } + bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64, + v); + if (pretty->use_colors) { + bt_common_g_string_append(pretty->string, COLOR_RST); + } + return 0; + } case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: return print_integer(pretty, field); - case BT_FIELD_CLASS_TYPE_REAL: + case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: + case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: { double v; - v = bt_field_real_get_value(field); + if (class_id == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) { + v = (float) bt_field_real_single_precision_get_value(field); + } else { + v = bt_field_real_double_precision_get_value(field); + } + if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_NUMBER_VALUE); + bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE); } - g_string_append_printf(pretty->string, "%g", v); + bt_common_g_string_append_printf(pretty->string, "%g", v); if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_RST); } return 0; } @@ -1002,24 +1049,29 @@ int print_field(struct pretty_component *pretty, } if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_STRING_VALUE); + bt_common_g_string_append(pretty->string, COLOR_STRING_VALUE); } print_escape_string(pretty, str); if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, COLOR_RST); } return 0; } case BT_FIELD_CLASS_TYPE_STRUCTURE: - return print_struct(pretty, field, print_names, filter_fields, - filter_array_len); + return print_struct(pretty, field, print_names); + case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR: + return print_option(pretty, field, print_names); case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: - case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: - case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: return print_variant(pretty, field, print_names); case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: return print_array(pretty, field, print_names); - case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: return print_sequence(pretty, field, print_names); default: // TODO: log instead @@ -1045,16 +1097,14 @@ int print_stream_packet_context(struct pretty_component *pretty, goto end; } if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } pretty->start_line = false; if (pretty->options.print_scope_field_names) { print_name_equal(pretty, "stream.packet.context"); } ret = print_field(pretty, main_field, - pretty->options.print_context_field_names, - stream_packet_context_quarks, - STREAM_PACKET_CONTEXT_QUARKS_LEN); + pretty->options.print_context_field_names); end: return ret; @@ -1072,14 +1122,14 @@ int print_stream_event_context(struct pretty_component *pretty, goto end; } if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } pretty->start_line = false; if (pretty->options.print_scope_field_names) { print_name_equal(pretty, "stream.event.context"); } ret = print_field(pretty, main_field, - pretty->options.print_context_field_names, NULL, 0); + pretty->options.print_context_field_names); end: return ret; @@ -1097,14 +1147,14 @@ int print_event_context(struct pretty_component *pretty, goto end; } if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } pretty->start_line = false; if (pretty->options.print_scope_field_names) { print_name_equal(pretty, "event.context"); } ret = print_field(pretty, main_field, - pretty->options.print_context_field_names, NULL, 0); + pretty->options.print_context_field_names); end: return ret; @@ -1122,14 +1172,14 @@ int print_event_payload(struct pretty_component *pretty, goto end; } if (!pretty->start_line) { - g_string_append(pretty->string, ", "); + bt_common_g_string_append(pretty->string, ", "); } pretty->start_line = false; if (pretty->options.print_scope_field_names) { print_name_equal(pretty, "event.fields"); } ret = print_field(pretty, main_field, - pretty->options.print_payload_field_names, NULL, 0); + pretty->options.print_payload_field_names); end: return ret; @@ -1188,7 +1238,7 @@ int pretty_print_event(struct pretty_component *pretty, goto end; } - g_string_append_c(pretty->string, '\n'); + bt_common_g_string_append_c(pretty->string, '\n'); if (flush_buf(pretty->out, pretty)) { ret = -1; goto end; @@ -1249,7 +1299,7 @@ int print_discarded_elements_msg(struct pretty_component *pretty, init_msg = "Tracer discarded"; } - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "%s%sWARNING%s%s: %s ", bt_common_color_fg_yellow(), bt_common_color_bold(), @@ -1257,47 +1307,47 @@ int print_discarded_elements_msg(struct pretty_component *pretty, bt_common_color_fg_yellow(), init_msg); if (count == UINT64_C(-1)) { - g_string_append_printf(pretty->string, "%ss", elem_type); + bt_common_g_string_append_printf(pretty->string, "%ss", elem_type); } else { - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "%" PRIu64 " %s%s", count, elem_type, count == 1 ? "" : "s"); } - g_string_append_c(pretty->string, ' '); + bt_common_g_string_append_c(pretty->string, ' '); if (begin_clock_snapshot && end_clock_snapshot) { - g_string_append(pretty->string, "between ["); + bt_common_g_string_append(pretty->string, "between ["); print_timestamp_wall(pretty, begin_clock_snapshot, false); - g_string_append(pretty->string, "] and ["); + bt_common_g_string_append(pretty->string, "] and ["); print_timestamp_wall(pretty, end_clock_snapshot, false); - g_string_append(pretty->string, "]"); + bt_common_g_string_append(pretty->string, "]"); } else { - g_string_append(pretty->string, "(unknown time range)"); + bt_common_g_string_append(pretty->string, "(unknown time range)"); } - g_string_append_printf(pretty->string, " in trace \"%s\" ", trace_name); + bt_common_g_string_append_printf(pretty->string, " in trace \"%s\" ", trace_name); if (trace_uuid) { - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "(UUID: " BT_UUID_FMT ") ", BT_UUID_FMT_VALUES(trace_uuid)); } else { - g_string_append(pretty->string, "(no UUID) "); + bt_common_g_string_append(pretty->string, "(no UUID) "); } - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "within stream \"%s\" (stream class ID: %" PRIu64 ", ", stream_name, stream_class_id); if (stream_id >= 0) { - g_string_append_printf(pretty->string, + bt_common_g_string_append_printf(pretty->string, "stream ID: %" PRIu64, stream_id); } else { - g_string_append(pretty->string, "no stream ID"); + bt_common_g_string_append(pretty->string, "no stream ID"); } - g_string_append_printf(pretty->string, ").%s\n", + bt_common_g_string_append_printf(pretty->string, ").%s\n", bt_common_color_reset()); /*