X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Ftext%2Fpretty%2Fprint.c;h=a30f3a364da4640118080c00a30cbd951a87a88e;hb=3fadfbc0c91f82c46bd36e6e0657ea93570c9db1;hp=92de19095412075db2d1ea454bdf34ba59b668eb;hpb=0d72b8c329ad51d14ab4e83330b38c2c8da69dd4;p=babeltrace.git diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index 92de1909..a30f3a36 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -23,11 +23,11 @@ * SOFTWARE. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include "pretty.h" @@ -46,12 +46,12 @@ struct timestamp { int64_t real_timestamp; /* Relative to UNIX epoch. */ - uint64_t clock_value; /* In cycles. */ + uint64_t clock_snapshot; /* In cycles. */ }; static int print_field(struct pretty_component *pretty, - const struct bt_field *field, bool print_names, + const bt_field *field, bool print_names, GQuark *filters_fields, int filter_array_len); static @@ -78,30 +78,25 @@ void print_field_name_equal(struct pretty_component *pretty, const char *name) static void print_timestamp_cycles(struct pretty_component *pretty, - const struct bt_event *event) + const bt_clock_snapshot *clock_snapshot, bool update_last) { - const struct bt_clock_value *clock_value; uint64_t cycles; - enum bt_clock_value_status cv_status; - cv_status = bt_event_borrow_default_clock_value_const(event, &clock_value); - if (cv_status != BT_CLOCK_VALUE_STATUS_KNOWN || !clock_value) { - g_string_append(pretty->string, "????????????????????"); - return; - } - - cycles = bt_clock_value_get_value(clock_value); + cycles = bt_clock_snapshot_get_value(clock_snapshot); g_string_append_printf(pretty->string, "%020" PRIu64, cycles); - if (pretty->last_cycles_timestamp != -1ULL) { - pretty->delta_cycles = cycles - pretty->last_cycles_timestamp; + if (update_last) { + if (pretty->last_cycles_timestamp != -1ULL) { + pretty->delta_cycles = cycles - pretty->last_cycles_timestamp; + } + + pretty->last_cycles_timestamp = cycles; } - pretty->last_cycles_timestamp = cycles; } static void print_timestamp_wall(struct pretty_component *pretty, - const struct bt_clock_value *clock_value) + const bt_clock_snapshot *clock_snapshot, bool update_last) { int ret; int64_t ts_nsec = 0; /* add configurable offset */ @@ -109,23 +104,26 @@ void print_timestamp_wall(struct pretty_component *pretty, uint64_t ts_sec_abs, ts_nsec_abs; bool is_negative; - if (!clock_value) { + if (!clock_snapshot) { g_string_append(pretty->string, "??:??:??.?????????"); return; } - ret = bt_clock_value_get_ns_from_origin(clock_value, &ts_nsec); + 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"); return; } - if (pretty->last_real_timestamp != -1ULL) { - pretty->delta_real_timestamp = ts_nsec - pretty->last_real_timestamp; + if (update_last) { + if (pretty->last_real_timestamp != -1ULL) { + pretty->delta_real_timestamp = ts_nsec - pretty->last_real_timestamp; + } + + pretty->last_real_timestamp = ts_nsec; } - pretty->last_real_timestamp = ts_nsec; ts_sec += ts_nsec / NSEC_PER_SEC; ts_nsec = ts_nsec % NSEC_PER_SEC; @@ -216,39 +214,19 @@ end: static int print_event_timestamp(struct pretty_component *pretty, - const struct bt_event *event, bool *start_line) + const bt_message *event_msg, bool *start_line) { bool print_names = pretty->options.print_header_field_names; int ret = 0; - const struct bt_stream *stream = NULL; - const struct bt_stream_class *stream_class = NULL; - const struct bt_trace *trace = NULL; - const struct bt_clock_value *clock_value = NULL; - enum bt_clock_value_status cv_status; - - stream = bt_event_borrow_stream_const(event); - if (!stream) { - ret = -1; - goto end; - } + const bt_clock_snapshot *clock_snapshot = NULL; - stream_class = bt_stream_borrow_class_const(stream); - if (!stream_class) { - ret = -1; - goto end; - } - trace = bt_stream_class_borrow_trace_const(stream_class); - if (!trace) { - ret = -1; + if (!bt_message_event_borrow_stream_class_default_clock_class_const( + event_msg)) { + /* No default clock class: skip the timestamp without an error */ goto end; } - cv_status = bt_event_borrow_default_clock_value_const(event, - &clock_value); - if (cv_status != BT_CLOCK_VALUE_STATUS_KNOWN || !clock_value) { - /* No default clock value: skip the timestamp without an error */ - goto end; - } + clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(event_msg); if (print_names) { print_name_equal(pretty, "timestamp"); @@ -259,12 +237,9 @@ int print_event_timestamp(struct pretty_component *pretty, g_string_append(pretty->string, COLOR_TIMESTAMP); } if (pretty->options.print_timestamp_cycles) { - print_timestamp_cycles(pretty, event); + print_timestamp_cycles(pretty, clock_snapshot, true); } else { - clock_value = NULL; - cv_status = bt_event_borrow_default_clock_value_const(event, - &clock_value); - print_timestamp_wall(pretty, clock_value); + print_timestamp_wall(pretty, clock_snapshot, true); } if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); @@ -283,7 +258,7 @@ int print_event_timestamp(struct pretty_component *pretty, if (pretty->options.print_timestamp_cycles) { if (pretty->delta_cycles == -1ULL) { g_string_append(pretty->string, - "+??????????\?\?) "); /* Not a trigraph. */ + "+??????????\?\?"); /* Not a trigraph. */ } else { g_string_append_printf(pretty->string, "+%012" PRIu64, pretty->delta_cycles); @@ -314,39 +289,34 @@ end: static int print_event_header(struct pretty_component *pretty, - const struct bt_event *event) + const bt_message *event_msg) { bool print_names = pretty->options.print_header_field_names; int ret = 0; - const struct bt_event_class *event_class = NULL; - const struct bt_stream_class *stream_class = NULL; - const struct bt_trace *trace_class = NULL; + const bt_event_class *event_class = NULL; + const bt_stream_class *stream_class = NULL; + const bt_trace_class *trace_class = NULL; + const bt_packet *packet = NULL; + const bt_stream *stream = NULL; + const bt_trace *trace = NULL; + const bt_event *event = bt_message_event_borrow_event_const(event_msg); int dom_print = 0; - enum bt_property_availability prop_avail; + bt_property_availability prop_avail; event_class = bt_event_borrow_class_const(event); - if (!event_class) { - ret = -1; - goto end; - } stream_class = bt_event_class_borrow_stream_class_const(event_class); - if (!stream_class) { - ret = -1; - goto end; - } - trace_class = bt_stream_class_borrow_trace_const(stream_class); - if (!trace_class) { - ret = -1; - goto end; - } - ret = print_event_timestamp(pretty, event, &pretty->start_line); + trace_class = bt_stream_class_borrow_trace_class_const(stream_class); + packet = bt_event_borrow_packet_const(event); + stream = bt_packet_borrow_stream_const(packet); + trace = bt_stream_borrow_trace_const(stream); + ret = print_event_timestamp(pretty, event_msg, &pretty->start_line); if (ret) { goto end; } if (pretty->options.print_trace_field) { const char *name; - name = bt_trace_get_name(trace_class); + name = bt_trace_get_name(trace); if (name) { if (!pretty->start_line) { g_string_append(pretty->string, ", "); @@ -357,15 +327,15 @@ int print_event_header(struct pretty_component *pretty, g_string_append(pretty->string, name); - if (!print_names) { - g_string_append(pretty->string, " "); + if (print_names) { + g_string_append(pretty->string, ", "); } } } if (pretty->options.print_trace_hostname_field) { - const struct bt_value *hostname_str; + const bt_value *hostname_str; - hostname_str = bt_trace_borrow_environment_entry_value_by_name_const( + hostname_str = bt_trace_class_borrow_environment_entry_value_by_name_const( trace_class, "hostname"); if (hostname_str) { const char *str; @@ -382,9 +352,9 @@ int print_event_header(struct pretty_component *pretty, } } if (pretty->options.print_trace_domain_field) { - const struct bt_value *domain_str; + const bt_value *domain_str; - domain_str = bt_trace_borrow_environment_entry_value_by_name_const( + domain_str = bt_trace_class_borrow_environment_entry_value_by_name_const( trace_class, "domain"); if (domain_str) { const char *str; @@ -403,9 +373,9 @@ int print_event_header(struct pretty_component *pretty, } } if (pretty->options.print_trace_procname_field) { - const struct bt_value *procname_str; + const bt_value *procname_str; - procname_str = bt_trace_borrow_environment_entry_value_by_name_const( + procname_str = bt_trace_class_borrow_environment_entry_value_by_name_const( trace_class, "procname"); if (procname_str) { const char *str; @@ -424,9 +394,9 @@ int print_event_header(struct pretty_component *pretty, } } if (pretty->options.print_trace_vpid_field) { - const struct bt_value *vpid_value; + const bt_value *vpid_value; - vpid_value = bt_trace_borrow_environment_entry_value_by_name_const( + vpid_value = bt_trace_class_borrow_environment_entry_value_by_name_const( trace_class, "vpid"); if (vpid_value) { int64_t value; @@ -439,7 +409,7 @@ int print_event_header(struct pretty_component *pretty, } else if (dom_print) { g_string_append(pretty->string, ":"); } - value = bt_value_integer_get(vpid_value); + value = bt_value_signed_integer_get(vpid_value); g_string_append_printf(pretty->string, "(%" PRId64 ")", value); dom_print = 1; @@ -463,7 +433,7 @@ int print_event_header(struct pretty_component *pretty, [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE ] = "TRACE_DEBUG_LINE", [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG ] = "TRACE_DEBUG", }; - enum bt_event_class_log_level log_level; + bt_event_class_log_level log_level; const char *log_level_str = NULL; prop_avail = bt_event_class_get_log_level(event_class, @@ -534,17 +504,17 @@ end: static int print_integer(struct pretty_component *pretty, - const struct bt_field *field) + const bt_field *field) { int ret = 0; - enum bt_field_class_integer_preferred_display_base base; - const struct bt_field_class *int_fc; + bt_field_class_integer_preferred_display_base base; + const bt_field_class *int_fc; union { uint64_t u; int64_t s; } v; bool rst_color = false; - enum bt_field_class_type ft_type; + bt_field_class_type ft_type; int_fc = bt_field_borrow_class_const(field); BT_ASSERT(int_fc); @@ -569,10 +539,10 @@ int print_integer(struct pretty_component *pretty, len = bt_field_class_integer_get_field_value_range(int_fc); g_string_append(pretty->string, "0b"); - v.u = _bt_piecewise_lshift(v.u, 64 - len); + _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); - v.u = _bt_piecewise_lshift(v.u, 1); + _bt_safe_lshift(v.u, 1); } break; } @@ -701,10 +671,10 @@ void print_escape_string(struct pretty_component *pretty, const char *str) static int print_enum(struct pretty_component *pretty, - const struct bt_field *field) + const bt_field *field) { int ret = 0; - const struct bt_field_class *enumeration_field_class = NULL; + const bt_field_class *enumeration_field_class = NULL; bt_field_class_enumeration_mapping_label_array label_array; uint64_t label_count; uint64_t i; @@ -747,7 +717,7 @@ int print_enum(struct pretty_component *pretty, for (i = 0; i < label_count; i++) { const char *mapping_name = label_array[i]; - if (i == 0) { + if (i != 0) { g_string_append(pretty->string, ", "); } if (pretty->use_colors) { @@ -790,15 +760,15 @@ int filter_field_name(struct pretty_component *pretty, const char *field_name, static int print_struct_field(struct pretty_component *pretty, - const struct bt_field *_struct, - const struct bt_field_class *struct_class, + 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) { int ret = 0; const char *field_name; - const struct bt_field *field = NULL; - const struct bt_field_class *field_class = NULL;; + const bt_field *field = NULL; + const bt_field_class_structure_member *member; field = bt_field_structure_borrow_member_field_by_index_const(_struct, i); if (!field) { @@ -806,8 +776,9 @@ int print_struct_field(struct pretty_component *pretty, goto end; } - bt_field_class_structure_borrow_member_by_index_const(struct_class, i, - &field_name, &field_class); + member = bt_field_class_structure_borrow_member_by_index_const( + 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)) { @@ -832,11 +803,11 @@ end: static int print_struct(struct pretty_component *pretty, - const struct bt_field *_struct, bool print_names, + const bt_field *_struct, bool print_names, GQuark *filter_fields, int filter_array_len) { int ret = 0; - const struct bt_field_class *struct_class = NULL; + const bt_field_class *struct_class = NULL; uint64_t nr_fields, i, nr_printed_fields; struct_class = bt_field_borrow_class_const(_struct); @@ -844,11 +815,9 @@ int print_struct(struct pretty_component *pretty, ret = -1; goto end; } + nr_fields = bt_field_class_structure_get_member_count(struct_class); - if (nr_fields < 0) { - ret = -1; - goto end; - } + g_string_append(pretty->string, "{"); pretty->depth++; nr_printed_fields = 0; @@ -869,9 +838,9 @@ end: static int print_array_field(struct pretty_component *pretty, - const struct bt_field *array, uint64_t i, bool print_names) + const bt_field *array, uint64_t i, bool print_names) { - const struct bt_field *field = NULL; + const bt_field *field = NULL; if (i != 0) { g_string_append(pretty->string, ", "); @@ -889,10 +858,10 @@ int print_array_field(struct pretty_component *pretty, static int print_array(struct pretty_component *pretty, - const struct bt_field *array, bool print_names) + const bt_field *array, bool print_names) { int ret = 0; - const struct bt_field_class *array_class = NULL; + const bt_field_class *array_class = NULL; uint64_t len; uint64_t i; @@ -919,9 +888,9 @@ end: static int print_sequence_field(struct pretty_component *pretty, - const struct bt_field *seq, uint64_t i, bool print_names) + const bt_field *seq, uint64_t i, bool print_names) { - const struct bt_field *field = NULL; + const bt_field *field = NULL; if (i != 0) { g_string_append(pretty->string, ", "); @@ -939,18 +908,13 @@ int print_sequence_field(struct pretty_component *pretty, static int print_sequence(struct pretty_component *pretty, - const struct bt_field *seq, bool print_names) + const bt_field *seq, bool print_names) { int ret = 0; uint64_t len; uint64_t i; len = bt_field_array_get_length(seq); - if (len < 0) { - ret = -1; - goto end; - } - g_string_append(pretty->string, "["); pretty->depth++; @@ -969,10 +933,10 @@ end: static int print_variant(struct pretty_component *pretty, - const struct bt_field *variant, bool print_names) + const bt_field *variant, bool print_names) { int ret = 0; - const struct bt_field *field = NULL; + const bt_field *field = NULL; field = bt_field_variant_borrow_selected_option_field_const(variant); BT_ASSERT(field); @@ -995,10 +959,10 @@ end: static int print_field(struct pretty_component *pretty, - const struct bt_field *field, bool print_names, + const bt_field *field, bool print_names, GQuark *filter_fields, int filter_array_len) { - enum bt_field_class_type class_id; + bt_field_class_type class_id; class_id = bt_field_get_class_type(field); switch (class_id) { @@ -1058,11 +1022,11 @@ int print_field(struct pretty_component *pretty, static int print_stream_packet_context(struct pretty_component *pretty, - const struct bt_event *event) + const bt_event *event) { int ret = 0; - const struct bt_packet *packet = NULL; - const struct bt_field *main_field = NULL; + const bt_packet *packet = NULL; + const bt_field *main_field = NULL; packet = bt_event_borrow_packet_const(event); if (!packet) { @@ -1089,37 +1053,12 @@ end: return ret; } -static -int print_event_header_raw(struct pretty_component *pretty, - const struct bt_event *event) -{ - int ret = 0; - const struct bt_field *main_field = NULL; - - main_field = bt_event_borrow_header_field_const(event); - if (!main_field) { - goto end; - } - if (!pretty->start_line) { - g_string_append(pretty->string, ", "); - } - pretty->start_line = false; - if (pretty->options.print_scope_field_names) { - print_name_equal(pretty, "stream.event.header"); - } - ret = print_field(pretty, main_field, - pretty->options.print_header_field_names, NULL, 0); - -end: - return ret; -} - static int print_stream_event_context(struct pretty_component *pretty, - const struct bt_event *event) + const bt_event *event) { int ret = 0; - const struct bt_field *main_field = NULL; + const bt_field *main_field = NULL; main_field = bt_event_borrow_common_context_field_const(event); if (!main_field) { @@ -1141,10 +1080,10 @@ end: static int print_event_context(struct pretty_component *pretty, - const struct bt_event *event) + const bt_event *event) { int ret = 0; - const struct bt_field *main_field = NULL; + const bt_field *main_field = NULL; main_field = bt_event_borrow_specific_context_field_const(event); if (!main_field) { @@ -1166,10 +1105,10 @@ end: static int print_event_payload(struct pretty_component *pretty, - const struct bt_event *event) + const bt_event *event) { int ret = 0; - const struct bt_field *main_field = NULL; + const bt_field *main_field = NULL; main_field = bt_event_borrow_payload_field_const(event); if (!main_field) { @@ -1208,16 +1147,16 @@ end: BT_HIDDEN int pretty_print_event(struct pretty_component *pretty, - const struct bt_notification *event_notif) + const bt_message *event_msg) { int ret; - const struct bt_event *event = - bt_notification_event_borrow_event_const(event_notif); + const bt_event *event = + bt_message_event_borrow_event_const(event_msg); BT_ASSERT(event); pretty->start_line = true; g_string_assign(pretty->string, ""); - ret = print_event_header(pretty, event); + ret = print_event_header(pretty, event_msg); if (ret != 0) { goto end; } @@ -1227,13 +1166,6 @@ int pretty_print_event(struct pretty_component *pretty, goto end; } - if (pretty->options.verbose) { - ret = print_event_header_raw(pretty, event); - if (ret != 0) { - goto end; - } - } - ret = print_stream_event_context(pretty, event); if (ret != 0) { goto end; @@ -1260,28 +1192,27 @@ end: } static -int print_discarded_elements_msg( - struct pretty_component *pretty, const struct bt_packet *packet, +int print_discarded_elements_msg(struct pretty_component *pretty, + const bt_stream *stream, + const bt_clock_snapshot *begin_clock_snapshot, + const bt_clock_snapshot *end_clock_snapshot, uint64_t count, const char *elem_type) { -#if 0 int ret = 0; - const struct bt_stream *stream = NULL; - const struct bt_stream_class *stream_class = NULL; - const struct bt_trace *trace = NULL; + const bt_stream_class *stream_class = NULL; + const bt_trace *trace = NULL; const char *stream_name; const char *trace_name; - const unsigned char *trace_uuid; + bt_uuid trace_uuid; int64_t stream_class_id; int64_t stream_id; - struct bt_clock_value *begin_clock_value = NULL; - struct bt_clock_value *end_clock_value = NULL; + const char *init_msg; /* Stream name */ - BT_ASSERT(packet); - stream = bt_packet_borrow_stream_const(packet); - BT_ASSERT(stream); stream_name = bt_stream_get_name(stream); + if (!stream_name) { + stream_name = "(unknown)"; + } /* Stream class ID */ stream_class = bt_stream_borrow_class_const(stream); @@ -1292,7 +1223,7 @@ int print_discarded_elements_msg( stream_id = bt_stream_get_id(stream); /* Trace name */ - trace = bt_stream_class_borrow_trace_const(stream_class); + trace = bt_stream_borrow_trace_const(stream); BT_ASSERT(trace); trace_name = bt_trace_get_name(trace); if (!trace_name) { @@ -1300,29 +1231,40 @@ int print_discarded_elements_msg( } /* Trace UUID */ - trace_uuid = bt_trace_get_uuid(trace); - - /* Beginning and end times */ - (void) bt_packet_borrow_previous_packet_default_end_clock_value_const( - packet, &begin_clock_value); - (void) bt_packet_borrow_default_end_clock_value_const(packet, - &end_clock_value); + trace_uuid = bt_trace_class_get_uuid( + bt_trace_borrow_class_const(trace)); /* Format message */ g_string_assign(pretty->string, ""); + + if (count == UINT64_C(-1)) { + init_msg = "Tracer may have discarded"; + } else { + init_msg = "Tracer discarded"; + } + g_string_append_printf(pretty->string, - "%s%sWARNING%s%s: Tracer discarded %" PRId64 " %s%s ", + "%s%sWARNING%s%s: %s ", bt_common_color_fg_yellow(), bt_common_color_bold(), bt_common_color_reset(), - bt_common_color_fg_yellow(), - count, elem_type, count == 1 ? "" : "s"); + bt_common_color_fg_yellow(), init_msg); - if (begin_clock_value && end_clock_value) { + if (count == UINT64_C(-1)) { + g_string_append_printf(pretty->string, "%ss", elem_type); + } else { + g_string_append_printf(pretty->string, + "%" PRIu64 " %s%s", count, elem_type, + count == 1 ? "" : "s"); + } + + g_string_append_c(pretty->string, ' '); + + if (begin_clock_snapshot && end_clock_snapshot) { g_string_append(pretty->string, "between ["); - print_timestamp_wall(pretty, begin_clock_value); + print_timestamp_wall(pretty, begin_clock_snapshot, false); g_string_append(pretty->string, "] and ["); - print_timestamp_wall(pretty, end_clock_value); + print_timestamp_wall(pretty, end_clock_snapshot, false); g_string_append(pretty->string, "]"); } else { g_string_append(pretty->string, "(unknown time range)"); @@ -1354,12 +1296,12 @@ int print_discarded_elements_msg( } g_string_append_printf(pretty->string, - "within stream \"%s\" (stream class ID: %" PRId64 ", ", + "within stream \"%s\" (stream class ID: %" PRIu64 ", ", stream_name, stream_class_id); if (stream_id >= 0) { g_string_append_printf(pretty->string, - "stream ID: %" PRId64, stream_id); + "stream ID: %" PRIu64, stream_id); } else { g_string_append(pretty->string, "no stream ID"); } @@ -1376,42 +1318,73 @@ int print_discarded_elements_msg( } return ret; -#endif - return 0; } BT_HIDDEN -int pretty_print_packet(struct pretty_component *pretty, - const struct bt_notification *packet_beginning_notif) +int pretty_print_discarded_items(struct pretty_component *pretty, + const bt_message *msg) { -#if 0 - const struct bt_packet *packet = bt_notification_packet_begin_borrow_packet_const( - packet_beginning_notif); - uint64_t count; - int status = 0; - - if (bt_packet_get_discarded_event_count(packet, &count) == - BT_PACKET_PROPERTY_AVAILABILITY_AVAILABLE && - count > 0) { - status = print_discarded_elements_msg(pretty, packet, - count, "event"); - if (status != 0) { - goto end; + const bt_clock_snapshot *begin = NULL; + const bt_clock_snapshot *end = NULL; + const bt_stream *stream; + const bt_stream_class *stream_class; + uint64_t count = UINT64_C(-1); + const char *elem_type; + + switch (bt_message_get_type(msg)) { + case BT_MESSAGE_TYPE_DISCARDED_EVENTS: + stream = bt_message_discarded_events_borrow_stream_const(msg); + + if (bt_message_discarded_events_get_count(msg, &count) == + BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) { + count = UINT64_C(-1); + } + + elem_type = "event"; + break; + case BT_MESSAGE_TYPE_DISCARDED_PACKETS: + stream = bt_message_discarded_packets_borrow_stream_const(msg); + + if (bt_message_discarded_packets_get_count(msg, &count) == + BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) { + count = UINT64_C(-1); } + + elem_type = "packet"; + break; + default: + abort(); } - if (bt_packet_get_discarded_packet_count(packet, &count) == - BT_PACKET_PROPERTY_AVAILABILITY_AVAILABLE && - count > 0) { - status = print_discarded_elements_msg(pretty, packet, - count, "packet"); - if (status != 0) { - goto end; + BT_ASSERT(stream); + stream_class = bt_stream_borrow_class_const(stream); + + switch (bt_message_get_type(msg)) { + case BT_MESSAGE_TYPE_DISCARDED_EVENTS: + if (bt_stream_class_discarded_events_have_default_clock_snapshots( + stream_class)) { + begin = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const( + msg); + end = bt_message_discarded_events_borrow_end_default_clock_snapshot_const( + msg); + } + + break; + case BT_MESSAGE_TYPE_DISCARDED_PACKETS: + if (bt_stream_class_discarded_packets_have_default_clock_snapshots( + stream_class)) { + begin = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const( + msg); + end = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const( + msg); } + + break; + default: + abort(); } -end: - return status; -#endif + print_discarded_elements_msg(pretty, stream, begin, end, + count, elem_type); return 0; }