X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Ftext%2Fpretty%2Fprint.c;h=4dae18825cdb5d241c8b0c3380dc087edd684c32;hb=40f4ba76dd6f9508ca51b6220eaed57632281a07;hp=6972ed5d9b5c42fbce929cd3f0ccfb834ea79ca0;hpb=6acddae3723c0bf8ec27feb18ad2dde7aa073fd3;p=babeltrace.git diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index 6972ed5d..4dae1882 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -1,8 +1,4 @@ /* - * print.c - * - * Babeltrace CTF Text Output Plugin Event Printing - * * Copyright 2016 Jérémie Galarneau * Copyright 2016 Mathieu Desnoyers * @@ -31,6 +27,7 @@ #include #include #include +#include #include #include #include "pretty.h" @@ -53,8 +50,8 @@ struct timestamp { }; static -enum bt_component_status print_field(struct pretty_component *pretty, - struct bt_ctf_field *field, bool print_names, +int print_field(struct pretty_component *pretty, + const struct bt_field *field, bool print_names, GQuark *filters_fields, int filter_array_len); static @@ -81,27 +78,19 @@ void print_field_name_equal(struct pretty_component *pretty, const char *name) static void print_timestamp_cycles(struct pretty_component *pretty, - struct bt_ctf_clock_class *clock_class, - struct bt_ctf_event *event) + const struct bt_event *event) { - int ret; - struct bt_ctf_clock_value *clock_value; + const struct bt_clock_value *clock_value; uint64_t cycles; + enum bt_clock_value_status cv_status; - clock_value = bt_ctf_event_get_clock_value(event, clock_class); - if (!clock_value) { + 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; } - ret = bt_ctf_clock_value_get_value(clock_value, &cycles); - bt_put(clock_value); - if (ret) { - // TODO: log, this is unexpected - g_string_append(pretty->string, "Error"); - return; - } - + cycles = bt_clock_value_get_value(clock_value); g_string_append_printf(pretty->string, "%020" PRIu64, cycles); if (pretty->last_cycles_timestamp != -1ULL) { @@ -112,7 +101,7 @@ void print_timestamp_cycles(struct pretty_component *pretty, static void print_timestamp_wall(struct pretty_component *pretty, - struct bt_ctf_clock_value *clock_value) + const struct bt_clock_value *clock_value) { int ret; int64_t ts_nsec = 0; /* add configurable offset */ @@ -125,7 +114,7 @@ void print_timestamp_wall(struct pretty_component *pretty, return; } - ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, &ts_nsec); + ret = bt_clock_value_get_ns_from_origin(clock_value, &ts_nsec); if (ret) { // TODO: log, this is unexpected g_string_append(pretty->string, "Error"); @@ -226,45 +215,38 @@ end: } static -enum bt_component_status print_event_timestamp(struct pretty_component *pretty, - struct bt_ctf_event *event, - struct bt_clock_class_priority_map *cc_prio_map, - bool *start_line) +int print_event_timestamp(struct pretty_component *pretty, + const struct bt_event *event, bool *start_line) { bool print_names = pretty->options.print_header_field_names; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_stream *stream = NULL; - struct bt_ctf_stream_class *stream_class = NULL; - struct bt_ctf_trace *trace = NULL; - struct bt_ctf_clock_class *clock_class = NULL; + 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_ctf_event_get_stream(event); + stream = bt_event_borrow_stream_const(event); if (!stream) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } - stream_class = bt_ctf_stream_get_class(stream); + stream_class = bt_stream_borrow_class_const(stream); if (!stream_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } - trace = bt_ctf_stream_class_get_trace(stream_class); + trace = bt_stream_class_borrow_trace_const(stream_class); if (!trace) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - - if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) == 0) { - /* No clock class: skip the timestamp without an error */ + ret = -1; goto end; } - clock_class = - bt_clock_class_priority_map_get_highest_priority_clock_class( - cc_prio_map); - if (!clock_class) { - ret = BT_COMPONENT_STATUS_ERROR; + 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; } @@ -277,13 +259,12 @@ enum bt_component_status print_event_timestamp(struct pretty_component *pretty, g_string_append(pretty->string, COLOR_TIMESTAMP); } if (pretty->options.print_timestamp_cycles) { - print_timestamp_cycles(pretty, clock_class, event); + print_timestamp_cycles(pretty, event); } else { - struct bt_ctf_clock_value *clock_value = - bt_ctf_event_get_clock_value(event, clock_class); - + clock_value = NULL; + cv_status = bt_event_borrow_default_clock_value_const(event, + &clock_value); print_timestamp_wall(pretty, clock_value); - bt_put(clock_value); } if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); @@ -328,49 +309,44 @@ enum bt_component_status print_event_timestamp(struct pretty_component *pretty, *start_line = !print_names; end: - bt_put(stream); - bt_put(clock_class); - bt_put(stream_class); - bt_put(trace); return ret; } static -enum bt_component_status print_event_header(struct pretty_component *pretty, - struct bt_ctf_event *event, - struct bt_clock_class_priority_map *cc_prio_map) +int print_event_header(struct pretty_component *pretty, + const struct bt_event *event) { bool print_names = pretty->options.print_header_field_names; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_event_class *event_class = NULL; - struct bt_ctf_stream_class *stream_class = NULL; - struct bt_ctf_trace *trace_class = NULL; + 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; int dom_print = 0; + enum bt_property_availability prop_avail; - event_class = bt_ctf_event_get_class(event); + event_class = bt_event_borrow_class_const(event); if (!event_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } - stream_class = bt_ctf_event_class_get_stream_class(event_class); + stream_class = bt_event_class_borrow_stream_class_const(event_class); if (!stream_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } - trace_class = bt_ctf_stream_class_get_trace(stream_class); + trace_class = bt_stream_class_borrow_trace_const(stream_class); if (!trace_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } - ret = print_event_timestamp(pretty, event, cc_prio_map, - &pretty->start_line); - if (ret != BT_COMPONENT_STATUS_OK) { + ret = print_event_timestamp(pretty, event, &pretty->start_line); + if (ret) { goto end; } if (pretty->options.print_trace_field) { const char *name; - name = bt_ctf_trace_get_name(trace_class); + name = bt_trace_get_name(trace_class); if (name) { if (!pretty->start_line) { g_string_append(pretty->string, ", "); @@ -387,10 +363,10 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, } } if (pretty->options.print_trace_hostname_field) { - struct bt_value *hostname_str; + const struct bt_value *hostname_str; - hostname_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, - "hostname"); + hostname_str = bt_trace_borrow_environment_entry_value_by_name_const( + trace_class, "hostname"); if (hostname_str) { const char *str; @@ -400,19 +376,16 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, if (print_names) { print_name_equal(pretty, "trace:hostname"); } - if (bt_value_string_get(hostname_str, &str) - == BT_VALUE_STATUS_OK) { - g_string_append(pretty->string, str); - } - bt_put(hostname_str); + str = bt_value_string_get(hostname_str); + g_string_append(pretty->string, str); dom_print = 1; } } if (pretty->options.print_trace_domain_field) { - struct bt_value *domain_str; + const struct bt_value *domain_str; - domain_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, - "domain"); + domain_str = bt_trace_borrow_environment_entry_value_by_name_const( + trace_class, "domain"); if (domain_str) { const char *str; @@ -424,19 +397,16 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, } else if (dom_print) { g_string_append(pretty->string, ":"); } - if (bt_value_string_get(domain_str, &str) - == BT_VALUE_STATUS_OK) { - g_string_append(pretty->string, str); - } - bt_put(domain_str); + str = bt_value_string_get(domain_str); + g_string_append(pretty->string, str); dom_print = 1; } } if (pretty->options.print_trace_procname_field) { - struct bt_value *procname_str; + const struct bt_value *procname_str; - procname_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, - "procname"); + procname_str = bt_trace_borrow_environment_entry_value_by_name_const( + trace_class, "procname"); if (procname_str) { const char *str; @@ -448,19 +418,16 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, } else if (dom_print) { g_string_append(pretty->string, ":"); } - if (bt_value_string_get(procname_str, &str) - == BT_VALUE_STATUS_OK) { - g_string_append(pretty->string, str); - } - bt_put(procname_str); + str = bt_value_string_get(procname_str); + g_string_append(pretty->string, str); dom_print = 1; } } if (pretty->options.print_trace_vpid_field) { - struct bt_value *vpid_value; + const struct bt_value *vpid_value; - vpid_value = bt_ctf_trace_get_environment_field_value_by_name(trace_class, - "vpid"); + vpid_value = bt_trace_borrow_environment_entry_value_by_name_const( + trace_class, "vpid"); if (vpid_value) { int64_t value; @@ -472,42 +439,39 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, } else if (dom_print) { g_string_append(pretty->string, ":"); } - if (bt_value_integer_get(vpid_value, &value) - == BT_VALUE_STATUS_OK) { - g_string_append_printf(pretty->string, "(%" PRId64 ")", value); - } - bt_put(vpid_value); + value = bt_value_integer_get(vpid_value); + g_string_append_printf(pretty->string, + "(%" PRId64 ")", value); dom_print = 1; } } if (pretty->options.print_loglevel_field) { static const char *log_level_names[] = { - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY ] = "TRACE_EMERG", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT ] = "TRACE_ALERT", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL ] = "TRACE_CRIT", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR ] = "TRACE_ERR", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING ] = "TRACE_WARNING", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE ] = "TRACE_NOTICE", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO ] = "TRACE_INFO", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM ] = "TRACE_DEBUG_SYSTEM", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM ] = "TRACE_DEBUG_PROGRAM", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS ] = "TRACE_DEBUG_PROCESS", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE ] = "TRACE_DEBUG_MODULE", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT ] = "TRACE_DEBUG_UNIT", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION ] = "TRACE_DEBUG_FUNCTION", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE ] = "TRACE_DEBUG_LINE", - [ BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG ] = "TRACE_DEBUG", + [ BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY ] = "TRACE_EMERG", + [ BT_EVENT_CLASS_LOG_LEVEL_ALERT ] = "TRACE_ALERT", + [ BT_EVENT_CLASS_LOG_LEVEL_CRITICAL ] = "TRACE_CRIT", + [ BT_EVENT_CLASS_LOG_LEVEL_ERROR ] = "TRACE_ERR", + [ BT_EVENT_CLASS_LOG_LEVEL_WARNING ] = "TRACE_WARNING", + [ BT_EVENT_CLASS_LOG_LEVEL_NOTICE ] = "TRACE_NOTICE", + [ BT_EVENT_CLASS_LOG_LEVEL_INFO ] = "TRACE_INFO", + [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM ] = "TRACE_DEBUG_SYSTEM", + [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM ] = "TRACE_DEBUG_PROGRAM", + [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS ] = "TRACE_DEBUG_PROCESS", + [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE ] = "TRACE_DEBUG_MODULE", + [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT ] = "TRACE_DEBUG_UNIT", + [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION ] = "TRACE_DEBUG_FUNCTION", + [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE ] = "TRACE_DEBUG_LINE", + [ BT_EVENT_CLASS_LOG_LEVEL_DEBUG ] = "TRACE_DEBUG", }; - enum bt_ctf_event_class_log_level log_level; + enum bt_event_class_log_level log_level; const char *log_level_str = NULL; - log_level = bt_ctf_event_class_get_log_level(event_class); - assert(log_level != BT_CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN); - if (log_level != BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) { + prop_avail = bt_event_class_get_log_level(event_class, + &log_level); + if (prop_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) { log_level_str = log_level_names[log_level]; - } + BT_ASSERT(log_level_str); - if (log_level_str) { if (!pretty->start_line) { g_string_append(pretty->string, ", "); } @@ -526,7 +490,7 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, if (pretty->options.print_emf_field) { const char *uri_str; - uri_str = bt_ctf_event_class_get_emf_uri(event_class); + uri_str = bt_event_class_get_emf_uri(event_class); if (uri_str) { if (!pretty->start_line) { g_string_append(pretty->string, ", "); @@ -554,7 +518,7 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, if (pretty->use_colors) { g_string_append(pretty->string, COLOR_EVENT_NAME); } - g_string_append(pretty->string, bt_ctf_event_class_get_name(event_class)); + g_string_append(pretty->string, bt_event_class_get_name(event_class)); if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); } @@ -563,62 +527,33 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, } else { g_string_append(pretty->string, ", "); } + end: - bt_put(trace_class); - bt_put(stream_class); - bt_put(event_class); return ret; } static -enum bt_component_status print_integer(struct pretty_component *pretty, - struct bt_ctf_field *field) +int print_integer(struct pretty_component *pretty, + const struct bt_field *field) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field_type *field_type = NULL; - enum bt_ctf_integer_base base; - enum bt_ctf_string_encoding encoding; - int signedness; + int ret = 0; + enum bt_field_class_integer_preferred_display_base base; + const struct bt_field_class *int_fc; union { uint64_t u; int64_t s; } v; bool rst_color = false; - - field_type = bt_ctf_field_get_type(field); - if (!field_type) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - signedness = bt_ctf_field_type_integer_get_signed(field_type); - if (signedness < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - if (!signedness) { - if (bt_ctf_field_unsigned_integer_get_value(field, &v.u) < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } + enum bt_field_class_type ft_type; + + int_fc = bt_field_borrow_class_const(field); + BT_ASSERT(int_fc); + ft_type = bt_field_get_class_type(field); + if (ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || + ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) { + v.u = bt_field_unsigned_integer_get_value(field); } else { - if (bt_ctf_field_signed_integer_get_value(field, &v.s) < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - } - - encoding = bt_ctf_field_type_integer_get_encoding(field_type); - switch (encoding) { - case BT_CTF_STRING_ENCODING_UTF8: - case BT_CTF_STRING_ENCODING_ASCII: - g_string_append_c(pretty->tmp_string, (int) v.u); - goto end; - case BT_CTF_STRING_ENCODING_NONE: - case BT_CTF_STRING_ENCODING_UNKNOWN: - break; - default: - ret = BT_COMPONENT_STATUS_ERROR; - goto end; + v.s = bt_field_signed_integer_get_value(field); } if (pretty->use_colors) { @@ -626,17 +561,13 @@ enum bt_component_status print_integer(struct pretty_component *pretty, rst_color = true; } - base = bt_ctf_field_type_integer_get_base(field_type); + base = bt_field_class_integer_get_preferred_display_base(int_fc); switch (base) { - case BT_CTF_INTEGER_BASE_BINARY: + case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY: { int bitnr, len; - len = bt_ctf_field_type_integer_get_size(field_type); - if (len < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } + 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); for (bitnr = 0; bitnr < len; bitnr++) { @@ -645,20 +576,18 @@ enum bt_component_status print_integer(struct pretty_component *pretty, } break; } - case BT_CTF_INTEGER_BASE_OCTAL: + case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL: { - if (signedness) { + if (ft_type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || + ft_type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) { int len; - len = bt_ctf_field_type_integer_get_size(field_type); - if (len < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } + len = bt_field_class_integer_get_field_value_range( + int_fc); if (len < 64) { size_t rounded_len; - assert(len != 0); + BT_ASSERT(len != 0); /* Round length to the nearest 3-bit */ rounded_len = (((len - 1) / 3) + 1) * 3; v.u &= ((uint64_t) 1 << rounded_len) - 1; @@ -668,23 +597,19 @@ enum bt_component_status print_integer(struct pretty_component *pretty, g_string_append_printf(pretty->string, "0%" PRIo64, v.u); break; } - case BT_CTF_INTEGER_BASE_DECIMAL: - case BT_CTF_INTEGER_BASE_UNSPECIFIED: - if (!signedness) { + 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); } else { g_string_append_printf(pretty->string, "%" PRId64, v.s); } break; - case BT_CTF_INTEGER_BASE_HEXADECIMAL: + case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL: { int len; - len = bt_ctf_field_type_integer_get_size(field_type); - if (len < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } + len = bt_field_class_integer_get_field_value_range(int_fc); if (len < 64) { /* Round length to the nearest nibble */ uint8_t rounded_len = ((len + 3) & ~0x3); @@ -696,14 +621,13 @@ enum bt_component_status print_integer(struct pretty_component *pretty, break; } default: - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } end: if (rst_color) { g_string_append(pretty->string, COLOR_RST); } - bt_put(field_type); return ret; } @@ -776,61 +700,41 @@ void print_escape_string(struct pretty_component *pretty, const char *str) } static -enum bt_component_status print_enum(struct pretty_component *pretty, - struct bt_ctf_field *field) +int print_enum(struct pretty_component *pretty, + const struct bt_field *field) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field *container_field = NULL; - struct bt_ctf_field_type *enumeration_field_type = NULL; - struct bt_ctf_field_type *container_field_type = NULL; - struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL; - int nr_mappings = 0; - int is_signed; - - enumeration_field_type = bt_ctf_field_get_type(field); - if (!enumeration_field_type) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - container_field = bt_ctf_field_enumeration_get_container(field); - if (!container_field) { - ret = BT_COMPONENT_STATUS_ERROR; + int ret = 0; + const struct bt_field_class *enumeration_field_class = NULL; + bt_field_class_enumeration_mapping_label_array label_array; + uint64_t label_count; + uint64_t i; + + enumeration_field_class = bt_field_borrow_class_const(field); + if (!enumeration_field_class) { + ret = -1; goto end; } - container_field_type = bt_ctf_field_get_type(container_field); - if (!container_field_type) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; + + switch (bt_field_get_class_type(field)) { + case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: + ret = bt_field_unsigned_enumeration_get_mapping_labels(field, + &label_array, &label_count); + break; + case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: + ret = bt_field_signed_enumeration_get_mapping_labels(field, + &label_array, &label_count); + break; + default: + abort(); } - is_signed = bt_ctf_field_type_integer_get_signed(container_field_type); - if (is_signed < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + + if (ret) { + ret = -1; goto end; } - if (is_signed) { - int64_t value; - - if (bt_ctf_field_signed_integer_get_value(container_field, - &value)) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - iter = bt_ctf_field_type_enumeration_find_mappings_by_signed_value( - enumeration_field_type, value); - } else { - uint64_t value; - if (bt_ctf_field_unsigned_integer_get_value(container_field, - &value)) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value( - enumeration_field_type, value); - } g_string_append(pretty->string, "( "); - ret = bt_ctf_field_type_enumeration_mapping_iterator_next(iter); - if (ret) { + if (label_count == 0) { if (pretty->use_colors) { g_string_append(pretty->string, COLOR_UNKNOWN); } @@ -840,16 +744,12 @@ enum bt_component_status print_enum(struct pretty_component *pretty, } goto skip_loop; } - for (;;) { - const char *mapping_name; + for (i = 0; i < label_count; i++) { + const char *mapping_name = label_array[i]; - if (bt_ctf_field_type_enumeration_mapping_iterator_get_signed( - iter, &mapping_name, NULL, NULL) < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - if (nr_mappings++) + if (i == 0) { g_string_append(pretty->string, ", "); + } if (pretty->use_colors) { g_string_append(pretty->string, COLOR_ENUM_MAPPING_NAME); } @@ -857,22 +757,15 @@ enum bt_component_status print_enum(struct pretty_component *pretty, if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); } - if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter) < 0) { - break; - } } skip_loop: g_string_append(pretty->string, " : container = "); - ret = print_integer(pretty, container_field); - if (ret != BT_COMPONENT_STATUS_OK) { + ret = print_integer(pretty, field); + if (ret != 0) { goto end; } g_string_append(pretty->string, " )"); end: - bt_put(iter); - bt_put(container_field_type); - bt_put(container_field); - bt_put(enumeration_field_type); return ret; } @@ -896,31 +789,29 @@ int filter_field_name(struct pretty_component *pretty, const char *field_name, } static -enum bt_component_status print_struct_field(struct pretty_component *pretty, - struct bt_ctf_field *_struct, - struct bt_ctf_field_type *struct_type, - int i, bool print_names, int *nr_printed_fields, +int print_struct_field(struct pretty_component *pretty, + const struct bt_field *_struct, + const struct bt_field_class *struct_class, + uint64_t i, bool print_names, uint64_t *nr_printed_fields, GQuark *filter_fields, int filter_array_len) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; const char *field_name; - struct bt_ctf_field *field = NULL; - struct bt_ctf_field_type *field_type = NULL;; + const struct bt_field *field = NULL; + const struct bt_field_class *field_class = NULL;; - field = bt_ctf_field_structure_get_field_by_index(_struct, i); + field = bt_field_structure_borrow_member_field_by_index_const(_struct, i); if (!field) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - if (bt_ctf_field_type_structure_get_field(struct_type, - &field_name, &field_type, i) < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } + bt_field_class_structure_borrow_member_by_index_const(struct_class, i, + &field_name, &field_class); + if (filter_fields && !filter_field_name(pretty, field_name, filter_fields, filter_array_len)) { - ret = BT_COMPONENT_STATUS_OK; + ret = 0; goto end; } @@ -934,357 +825,191 @@ enum bt_component_status print_struct_field(struct pretty_component *pretty, } ret = print_field(pretty, field, print_names, NULL, 0); *nr_printed_fields += 1; + end: - bt_put(field_type); - bt_put(field); return ret; } static -enum bt_component_status print_struct(struct pretty_component *pretty, - struct bt_ctf_field *_struct, bool print_names, +int print_struct(struct pretty_component *pretty, + const struct bt_field *_struct, bool print_names, GQuark *filter_fields, int filter_array_len) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field_type *struct_type = NULL; - int nr_fields, i, nr_printed_fields; + int ret = 0; + const struct bt_field_class *struct_class = NULL; + uint64_t nr_fields, i, nr_printed_fields; - struct_type = bt_ctf_field_get_type(_struct); - if (!struct_type) { - ret = BT_COMPONENT_STATUS_ERROR; + struct_class = bt_field_borrow_class_const(_struct); + if (!struct_class) { + ret = -1; goto end; } - nr_fields = bt_ctf_field_type_structure_get_field_count(struct_type); + nr_fields = bt_field_class_structure_get_member_count(struct_class); if (nr_fields < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } 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_type, i, + ret = print_struct_field(pretty, _struct, struct_class, i, print_names, &nr_printed_fields, filter_fields, filter_array_len); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } } pretty->depth--; g_string_append(pretty->string, " }"); + end: - bt_put(struct_type); return ret; } static -enum bt_component_status print_array_field(struct pretty_component *pretty, - struct bt_ctf_field *array, uint64_t i, - bool is_string, bool print_names) +int print_array_field(struct pretty_component *pretty, + const struct bt_field *array, uint64_t i, bool print_names) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field *field = NULL; + const struct bt_field *field = NULL; - if (!is_string) { - if (i != 0) { - g_string_append(pretty->string, ", "); - } else { - g_string_append(pretty->string, " "); - } - if (print_names) { - g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); - } + if (i != 0) { + g_string_append(pretty->string, ", "); + } else { + g_string_append(pretty->string, " "); } - field = bt_ctf_field_array_get_field(array, i); - if (!field) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; + if (print_names) { + g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); } - ret = print_field(pretty, field, print_names, NULL, 0); -end: - bt_put(field); - return ret; + + field = bt_field_array_borrow_element_field_by_index_const(array, i); + BT_ASSERT(field); + return print_field(pretty, field, print_names, NULL, 0); } static -enum bt_component_status print_array(struct pretty_component *pretty, - struct bt_ctf_field *array, bool print_names) +int print_array(struct pretty_component *pretty, + const struct bt_field *array, bool print_names) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field_type *array_type = NULL, *field_type = NULL; - enum bt_ctf_field_type_id type_id; - int64_t len; + int ret = 0; + const struct bt_field_class *array_class = NULL; + uint64_t len; uint64_t i; - bool is_string = false; - array_type = bt_ctf_field_get_type(array); - if (!array_type) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - field_type = bt_ctf_field_type_array_get_element_type(array_type); - if (!field_type) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - len = bt_ctf_field_type_array_get_length(array_type); - if (len < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + array_class = bt_field_borrow_class_const(array); + if (!array_class) { + ret = -1; goto end; } - type_id = bt_ctf_field_type_get_type_id(field_type); - if (type_id == BT_CTF_FIELD_TYPE_ID_INTEGER) { - enum bt_ctf_string_encoding encoding; - - encoding = bt_ctf_field_type_integer_get_encoding(field_type); - if (encoding == BT_CTF_STRING_ENCODING_UTF8 - || encoding == BT_CTF_STRING_ENCODING_ASCII) { - int integer_len, integer_alignment; - - integer_len = bt_ctf_field_type_integer_get_size(field_type); - if (integer_len < 0) { - return BT_COMPONENT_STATUS_ERROR; - } - integer_alignment = bt_ctf_field_type_get_alignment(field_type); - if (integer_alignment < 0) { - return BT_COMPONENT_STATUS_ERROR; - } - if (integer_len == CHAR_BIT - && integer_alignment == CHAR_BIT) { - is_string = true; - } - } - } - - if (is_string) { - g_string_assign(pretty->tmp_string, ""); - } else { - g_string_append(pretty->string, "["); - } - + len = bt_field_array_get_length(array); + g_string_append(pretty->string, "["); pretty->depth++; for (i = 0; i < len; i++) { - ret = print_array_field(pretty, array, i, is_string, print_names); - if (ret != BT_COMPONENT_STATUS_OK) { + ret = print_array_field(pretty, array, i, print_names); + if (ret != 0) { goto end; } } pretty->depth--; + g_string_append(pretty->string, " ]"); - if (is_string) { - if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_STRING_VALUE); - } - print_escape_string(pretty, pretty->tmp_string->str); - if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); - } - } else { - g_string_append(pretty->string, " ]"); - } end: - bt_put(field_type); - bt_put(array_type); return ret; } static -enum bt_component_status print_sequence_field(struct pretty_component *pretty, - struct bt_ctf_field *seq, uint64_t i, - bool is_string, bool print_names) +int print_sequence_field(struct pretty_component *pretty, + const struct bt_field *seq, uint64_t i, bool print_names) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field *field = NULL; + const struct bt_field *field = NULL; - if (!is_string) { - if (i != 0) { - g_string_append(pretty->string, ", "); - } else { - g_string_append(pretty->string, " "); - } - if (print_names) { - g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); - } + if (i != 0) { + g_string_append(pretty->string, ", "); + } else { + g_string_append(pretty->string, " "); } - field = bt_ctf_field_sequence_get_field(seq, i); - if (!field) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; + if (print_names) { + g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i); } - ret = print_field(pretty, field, print_names, NULL, 0); -end: - bt_put(field); - return ret; + + field = bt_field_array_borrow_element_field_by_index_const(seq, i); + BT_ASSERT(field); + return print_field(pretty, field, print_names, NULL, 0); } static -enum bt_component_status print_sequence(struct pretty_component *pretty, - struct bt_ctf_field *seq, bool print_names) +int print_sequence(struct pretty_component *pretty, + const struct bt_field *seq, bool print_names) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field_type *seq_type = NULL, *field_type = NULL; - struct bt_ctf_field *length_field = NULL; - enum bt_ctf_field_type_id type_id; + int ret = 0; uint64_t len; uint64_t i; - bool is_string = false; - seq_type = bt_ctf_field_get_type(seq); - if (!seq_type) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - length_field = bt_ctf_field_sequence_get_length(seq); - if (!length_field) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - if (bt_ctf_field_unsigned_integer_get_value(length_field, &len) < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - field_type = bt_ctf_field_type_sequence_get_element_type(seq_type); - if (!field_type) { - ret = BT_COMPONENT_STATUS_ERROR; + len = bt_field_array_get_length(seq); + if (len < 0) { + ret = -1; goto end; } - type_id = bt_ctf_field_type_get_type_id(field_type); - if (type_id == BT_CTF_FIELD_TYPE_ID_INTEGER) { - enum bt_ctf_string_encoding encoding; - encoding = bt_ctf_field_type_integer_get_encoding(field_type); - if (encoding == BT_CTF_STRING_ENCODING_UTF8 - || encoding == BT_CTF_STRING_ENCODING_ASCII) { - int integer_len, integer_alignment; - - integer_len = bt_ctf_field_type_integer_get_size(field_type); - if (integer_len < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - integer_alignment = bt_ctf_field_type_get_alignment(field_type); - if (integer_alignment < 0) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - if (integer_len == CHAR_BIT - && integer_alignment == CHAR_BIT) { - is_string = true; - } - } - } - - if (is_string) { - g_string_assign(pretty->tmp_string, ""); - } else { - g_string_append(pretty->string, "["); - } + g_string_append(pretty->string, "["); pretty->depth++; for (i = 0; i < len; i++) { - ret = print_sequence_field(pretty, seq, i, - is_string, print_names); - if (ret != BT_COMPONENT_STATUS_OK) { + ret = print_sequence_field(pretty, seq, i, print_names); + if (ret != 0) { goto end; } } pretty->depth--; + g_string_append(pretty->string, " ]"); - if (is_string) { - if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_STRING_VALUE); - } - print_escape_string(pretty, pretty->tmp_string->str); - if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); - } - } else { - g_string_append(pretty->string, " ]"); - } end: - bt_put(length_field); - bt_put(field_type); - bt_put(seq_type); return ret; } static -enum bt_component_status print_variant(struct pretty_component *pretty, - struct bt_ctf_field *variant, bool print_names) +int print_variant(struct pretty_component *pretty, + const struct bt_field *variant, bool print_names) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field *field = NULL; + int ret = 0; + const struct bt_field *field = NULL; - field = bt_ctf_field_variant_get_current_field(variant); - if (!field) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } + field = bt_field_variant_borrow_selected_option_field_const(variant); + BT_ASSERT(field); g_string_append(pretty->string, "{ "); pretty->depth++; if (print_names) { - int iter_ret; - struct bt_ctf_field *tag_field = NULL; - const char *tag_choice; - struct bt_ctf_field_type_enumeration_mapping_iterator *iter; - - tag_field = bt_ctf_field_variant_get_tag(variant); - if (!tag_field) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - - iter = bt_ctf_field_enumeration_get_mappings(tag_field); - iter_ret = bt_ctf_field_type_enumeration_mapping_iterator_next( - iter); - if (!iter || ret) { - bt_put(tag_field); - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - - iter_ret = - bt_ctf_field_type_enumeration_mapping_iterator_get_signed( - iter, &tag_choice, NULL, NULL); - if (iter_ret) { - bt_put(iter); - bt_put(tag_field); - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - print_field_name_equal(pretty, tag_choice); - bt_put(tag_field); - bt_put(iter); + // TODO: find tag's name using field path + // print_field_name_equal(pretty, tag_choice); } ret = print_field(pretty, field, print_names, NULL, 0); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } pretty->depth--; g_string_append(pretty->string, " }"); + end: - bt_put(field); return ret; } static -enum bt_component_status print_field(struct pretty_component *pretty, - struct bt_ctf_field *field, bool print_names, +int print_field(struct pretty_component *pretty, + const struct bt_field *field, bool print_names, GQuark *filter_fields, int filter_array_len) { - enum bt_ctf_field_type_id type_id; + enum bt_field_class_type class_id; - type_id = bt_ctf_field_get_type_id(field); - switch (type_id) { - case CTF_TYPE_INTEGER: + class_id = bt_field_get_class_type(field); + switch (class_id) { + case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: + case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: return print_integer(pretty, field); - case CTF_TYPE_FLOAT: + case BT_FIELD_CLASS_TYPE_REAL: { double v; - if (bt_ctf_field_floating_point_get_value(field, &v)) { - return BT_COMPONENT_STATUS_ERROR; - } + v = bt_field_real_get_value(field); if (pretty->use_colors) { g_string_append(pretty->string, COLOR_NUMBER_VALUE); } @@ -1292,17 +1017,18 @@ enum bt_component_status print_field(struct pretty_component *pretty, if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); } - return BT_COMPONENT_STATUS_OK; + return 0; } - case CTF_TYPE_ENUM: + case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: + case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: return print_enum(pretty, field); - case CTF_TYPE_STRING: + case BT_FIELD_CLASS_TYPE_STRING: { const char *str; - str = bt_ctf_field_string_get_value(field); + str = bt_field_string_get_value(field); if (!str) { - return BT_COMPONENT_STATUS_ERROR; + return -1; } if (pretty->use_colors) { @@ -1312,38 +1038,38 @@ enum bt_component_status print_field(struct pretty_component *pretty, if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); } - return BT_COMPONENT_STATUS_OK; + return 0; } - case CTF_TYPE_STRUCT: + case BT_FIELD_CLASS_TYPE_STRUCTURE: return print_struct(pretty, field, print_names, filter_fields, filter_array_len); - case CTF_TYPE_VARIANT: + case BT_FIELD_CLASS_TYPE_VARIANT: return print_variant(pretty, field, print_names); - case CTF_TYPE_ARRAY: + case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: return print_array(pretty, field, print_names); - case CTF_TYPE_SEQUENCE: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: return print_sequence(pretty, field, print_names); default: // TODO: log instead - fprintf(pretty->err, "[error] Unknown type id: %d\n", (int) type_id); - return BT_COMPONENT_STATUS_ERROR; + fprintf(pretty->err, "[error] Unknown type id: %d\n", (int) class_id); + return -1; } } static -enum bt_component_status print_stream_packet_context(struct pretty_component *pretty, - struct bt_ctf_event *event) +int print_stream_packet_context(struct pretty_component *pretty, + const struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_packet *packet = NULL; - struct bt_ctf_field *main_field = NULL; + int ret = 0; + const struct bt_packet *packet = NULL; + const struct bt_field *main_field = NULL; - packet = bt_ctf_event_get_packet(event); + packet = bt_event_borrow_packet_const(event); if (!packet) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } - main_field = bt_ctf_packet_get_context(packet); + main_field = bt_packet_borrow_context_field_const(packet); if (!main_field) { goto end; } @@ -1358,20 +1084,19 @@ enum bt_component_status print_stream_packet_context(struct pretty_component *pr pretty->options.print_context_field_names, stream_packet_context_quarks, STREAM_PACKET_CONTEXT_QUARKS_LEN); + end: - bt_put(main_field); - bt_put(packet); return ret; } static -enum bt_component_status print_event_header_raw(struct pretty_component *pretty, - struct bt_ctf_event *event) +int print_event_header_raw(struct pretty_component *pretty, + const struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field *main_field = NULL; + int ret = 0; + const struct bt_field *main_field = NULL; - main_field = bt_ctf_event_get_header(event); + main_field = bt_event_borrow_header_field_const(event); if (!main_field) { goto end; } @@ -1384,19 +1109,19 @@ enum bt_component_status print_event_header_raw(struct pretty_component *pretty, } ret = print_field(pretty, main_field, pretty->options.print_header_field_names, NULL, 0); + end: - bt_put(main_field); return ret; } static -enum bt_component_status print_stream_event_context(struct pretty_component *pretty, - struct bt_ctf_event *event) +int print_stream_event_context(struct pretty_component *pretty, + const struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field *main_field = NULL; + int ret = 0; + const struct bt_field *main_field = NULL; - main_field = bt_ctf_event_get_stream_event_context(event); + main_field = bt_event_borrow_common_context_field_const(event); if (!main_field) { goto end; } @@ -1409,19 +1134,19 @@ enum bt_component_status print_stream_event_context(struct pretty_component *pre } ret = print_field(pretty, main_field, pretty->options.print_context_field_names, NULL, 0); + end: - bt_put(main_field); return ret; } static -enum bt_component_status print_event_context(struct pretty_component *pretty, - struct bt_ctf_event *event) +int print_event_context(struct pretty_component *pretty, + const struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field *main_field = NULL; + int ret = 0; + const struct bt_field *main_field = NULL; - main_field = bt_ctf_event_get_event_context(event); + main_field = bt_event_borrow_specific_context_field_const(event); if (!main_field) { goto end; } @@ -1434,19 +1159,19 @@ enum bt_component_status print_event_context(struct pretty_component *pretty, } ret = print_field(pretty, main_field, pretty->options.print_context_field_names, NULL, 0); + end: - bt_put(main_field); return ret; } static -enum bt_component_status print_event_payload(struct pretty_component *pretty, - struct bt_ctf_event *event) +int print_event_payload(struct pretty_component *pretty, + const struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_field *main_field = NULL; + int ret = 0; + const struct bt_field *main_field = NULL; - main_field = bt_ctf_event_get_event_payload(event); + main_field = bt_event_borrow_payload_field_const(event); if (!main_field) { goto end; } @@ -1459,13 +1184,13 @@ enum bt_component_status print_event_payload(struct pretty_component *pretty, } ret = print_field(pretty, main_field, pretty->options.print_payload_field_names, NULL, 0); + end: - bt_put(main_field); return ret; } static -int flush_buf(struct pretty_component *pretty) +int flush_buf(FILE *stream, struct pretty_component *pretty) { int ret = 0; @@ -1473,7 +1198,7 @@ int flush_buf(struct pretty_component *pretty) goto end; } - if (fwrite(pretty->string->str, pretty->string->len, 1, pretty->out) != 1) { + if (fwrite(pretty->string->str, pretty->string->len, 1, stream) != 1) { ret = -1; } @@ -1482,149 +1207,131 @@ end: } BT_HIDDEN -enum bt_component_status pretty_print_event(struct pretty_component *pretty, +int pretty_print_event(struct pretty_component *pretty, struct bt_notification *event_notif) { - enum bt_component_status ret; - struct bt_ctf_event *event = - bt_notification_event_get_event(event_notif); - struct bt_clock_class_priority_map *cc_prio_map = - bt_notification_event_get_clock_class_priority_map(event_notif); - - assert(event); - assert(cc_prio_map); + int ret; + const struct bt_event *event = + bt_notification_event_borrow_event(event_notif); + + BT_ASSERT(event); pretty->start_line = true; g_string_assign(pretty->string, ""); - ret = print_event_header(pretty, event, cc_prio_map); - if (ret != BT_COMPONENT_STATUS_OK) { + ret = print_event_header(pretty, event); + if (ret != 0) { goto end; } ret = print_stream_packet_context(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } if (pretty->options.verbose) { ret = print_event_header_raw(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } } ret = print_stream_event_context(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } ret = print_event_context(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } ret = print_event_payload(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } g_string_append_c(pretty->string, '\n'); - if (flush_buf(pretty)) { - ret = BT_COMPONENT_STATUS_ERROR; + if (flush_buf(pretty->out, pretty)) { + ret = -1; goto end; } end: - bt_put(event); - bt_put(cc_prio_map); return ret; } -BT_HIDDEN -enum bt_component_status pretty_print_discarded_elements( - struct pretty_component *pretty, - struct bt_notification *notif) +static +int print_discarded_elements_msg( + struct pretty_component *pretty, const struct bt_packet *packet, + uint64_t count, const char *elem_type) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_ctf_stream *stream = NULL; - struct bt_ctf_stream_class *stream_class = NULL; - struct bt_ctf_trace *trace = NULL; +#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 char *stream_name; const char *trace_name; const unsigned char *trace_uuid; int64_t stream_class_id; int64_t stream_id; - bool is_discarded_events; - int64_t count; - struct bt_ctf_clock_value *clock_value = NULL; + struct bt_clock_value *begin_clock_value = NULL; + struct bt_clock_value *end_clock_value = NULL; /* Stream name */ - switch (bt_notification_get_type(notif)) { - case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS: - stream = bt_notification_discarded_events_get_stream(notif); - count = bt_notification_discarded_events_get_count(notif); - is_discarded_events = true; - break; - case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS: - stream = bt_notification_discarded_packets_get_stream(notif); - count = bt_notification_discarded_packets_get_count(notif); - is_discarded_events = false; - break; - default: - abort(); - } - - assert(stream); - stream_name = bt_ctf_stream_get_name(stream); + BT_ASSERT(packet); + stream = bt_packet_borrow_stream_const(packet); + BT_ASSERT(stream); + stream_name = bt_stream_get_name(stream); /* Stream class ID */ - stream_class = bt_ctf_stream_get_class(stream); - assert(stream_class); - stream_class_id = bt_ctf_stream_class_get_id(stream_class); + stream_class = bt_stream_borrow_class_const(stream); + BT_ASSERT(stream_class); + stream_class_id = bt_stream_class_get_id(stream_class); /* Stream ID */ - stream_id = bt_ctf_stream_get_id(stream); + stream_id = bt_stream_get_id(stream); - /* Trace path */ - trace = bt_ctf_stream_class_get_trace(stream_class); - assert(trace); - trace_name = bt_ctf_trace_get_name(trace); + /* Trace name */ + trace = bt_stream_class_borrow_trace_const(stream_class); + BT_ASSERT(trace); + trace_name = bt_trace_get_name(trace); if (!trace_name) { trace_name = "(unknown)"; } /* Trace UUID */ - trace_uuid = bt_ctf_trace_get_uuid(trace); + trace_uuid = bt_trace_get_uuid(trace); - /* - * Print to standard error stream to remain backward compatible - * with Babeltrace 1. - */ - fprintf(stderr, - "%s%sWARNING%s%s: Tracer discarded %" PRId64 " %s%s between [", + /* 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); + + /* Format message */ + g_string_assign(pretty->string, ""); + g_string_append_printf(pretty->string, + "%s%sWARNING%s%s: Tracer discarded %" PRId64 " %s%s ", bt_common_color_fg_yellow(), bt_common_color_bold(), bt_common_color_reset(), bt_common_color_fg_yellow(), - count, is_discarded_events ? "event" : "packet", - count == 1 ? "" : "s"); - g_string_assign(pretty->string, ""); - clock_value = is_discarded_events ? - bt_notification_discarded_events_get_begin_clock_value(notif) : - bt_notification_discarded_packets_get_begin_clock_value(notif); - print_timestamp_wall(pretty, clock_value); - BT_PUT(clock_value); - fprintf(stderr, "%s] and [", pretty->string->str); - g_string_assign(pretty->string, ""); - clock_value = is_discarded_events ? - bt_notification_discarded_events_get_end_clock_value(notif) : - bt_notification_discarded_packets_get_end_clock_value(notif); - print_timestamp_wall(pretty, clock_value); - BT_PUT(clock_value); - fprintf(stderr, "%s] in trace \"%s\" ", - pretty->string->str, trace_name); + count, elem_type, count == 1 ? "" : "s"); + + if (begin_clock_value && end_clock_value) { + g_string_append(pretty->string, "between ["); + print_timestamp_wall(pretty, begin_clock_value); + g_string_append(pretty->string, "] and ["); + print_timestamp_wall(pretty, end_clock_value); + g_string_append(pretty->string, "]"); + } else { + g_string_append(pretty->string, "(unknown time range)"); + } + + g_string_append_printf(pretty->string, " in trace \"%s\" ", trace_name); if (trace_uuid) { - fprintf(stderr, + g_string_append_printf(pretty->string, "(UUID: %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x) ", trace_uuid[0], trace_uuid[1], @@ -1643,22 +1350,68 @@ enum bt_component_status pretty_print_discarded_elements( trace_uuid[14], trace_uuid[15]); } else { - fprintf(stderr, "(no UUID) "); + g_string_append(pretty->string, "(no UUID) "); } - fprintf(stderr, "within stream \"%s\" (stream class ID: %" PRId64 ", ", + g_string_append_printf(pretty->string, + "within stream \"%s\" (stream class ID: %" PRId64 ", ", stream_name, stream_class_id); if (stream_id >= 0) { - fprintf(stderr, "stream ID: %" PRId64, stream_id); + g_string_append_printf(pretty->string, + "stream ID: %" PRId64, stream_id); } else { - fprintf(stderr, "no stream ID"); + g_string_append(pretty->string, "no stream ID"); + } + + g_string_append_printf(pretty->string, ").%s\n", + bt_common_color_reset()); + + /* + * Print to standard error stream to remain backward compatible + * with Babeltrace 1. + */ + if (flush_buf(stderr, pretty)) { + ret = -1; } - fprintf(stderr, ").%s\n", bt_common_color_reset()); - bt_put(stream); - bt_put(stream_class); - bt_put(trace); - bt_put(clock_value); return ret; +#endif + return 0; +} + +BT_HIDDEN +int pretty_print_packet(struct pretty_component *pretty, + struct bt_notification *packet_beginning_notif) +{ +#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; + } + } + + 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; + } + } + +end: + return status; +#endif + return 0; }