lib: add internal object pool API and use it; adapt plugins/tests
[babeltrace.git] / plugins / text / pretty / print.c
index 1161a3869d969ac707860d6e3ed9cb0343acff74..a9e6104d667ff84437fafbab9ec310da1a7b6d97 100644 (file)
  * SOFTWARE.
  */
 
-#include <babeltrace/ctf-ir/event.h>
-#include <babeltrace/ctf-ir/event-class.h>
-#include <babeltrace/ctf-ir/packet.h>
-#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/clock-class.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/graph/notification-event.h>
-#include <babeltrace/graph/clock-class-priority-map.h>
+#include <babeltrace/babeltrace.h>
 #include <babeltrace/bitfield-internal.h>
 #include <babeltrace/common-internal.h>
 #include <babeltrace/compat/time-internal.h>
+#include <babeltrace/assert-internal.h>
 #include <inttypes.h>
 #include <ctype.h>
 #include "pretty.h"
 #define NSEC_PER_SEC 1000000000LL
 
 #define COLOR_NAME             BT_COMMON_COLOR_BOLD
-#define COLOR_FIELD_NAME               BT_COMMON_COLOR_FG_CYAN
+#define COLOR_FIELD_NAME       BT_COMMON_COLOR_FG_CYAN
 #define COLOR_RST              BT_COMMON_COLOR_RESET
 #define COLOR_STRING_VALUE     BT_COMMON_COLOR_BOLD
 #define COLOR_NUMBER_VALUE     BT_COMMON_COLOR_BOLD
 #define COLOR_ENUM_MAPPING_NAME        BT_COMMON_COLOR_BOLD
 #define COLOR_UNKNOWN          BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_RED
-#define COLOR_EVENT_NAME               BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_MAGENTA
+#define COLOR_EVENT_NAME       BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_MAGENTA
 #define COLOR_TIMESTAMP                BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_YELLOW
 
-static inline
-const char *rem_(const char *str)
-{
-       if (str[0] == '_')
-               return &str[1];
-       else
-               return str;
-}
-
 struct timestamp {
        int64_t real_timestamp; /* Relative to UNIX epoch. */
        uint64_t clock_value;   /* In cycles. */
@@ -73,7 +55,7 @@ struct timestamp {
 
 static
 enum bt_component_status print_field(struct pretty_component *pretty,
-               struct bt_ctf_field *field, bool print_names,
+               struct bt_field *field, bool print_names,
                GQuark *filters_fields, int filter_array_len);
 
 static
@@ -100,21 +82,20 @@ 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)
+               struct bt_clock_class *clock_class,
+               struct bt_event *event)
 {
        int ret;
-       struct bt_ctf_clock_value *clock_value;
+       struct bt_clock_value *clock_value;
        uint64_t cycles;
 
-       clock_value = bt_ctf_event_get_clock_value(event, clock_class);
+       clock_value = bt_event_borrow_clock_value(event, clock_class);
        if (!clock_value) {
                g_string_append(pretty->string, "????????????????????");
                return;
        }
 
-       ret = bt_ctf_clock_value_get_value(clock_value, &cycles);
-       bt_put(clock_value);
+       ret = bt_clock_value_get_value(clock_value, &cycles);
        if (ret) {
                // TODO: log, this is unexpected
                g_string_append(pretty->string, "Error");
@@ -131,24 +112,20 @@ void print_timestamp_cycles(struct pretty_component *pretty,
 
 static
 void print_timestamp_wall(struct pretty_component *pretty,
-               struct bt_ctf_clock_class *clock_class,
-               struct bt_ctf_event *event)
+               struct bt_clock_value *clock_value)
 {
        int ret;
-       struct bt_ctf_clock_value *clock_value;
        int64_t ts_nsec = 0;    /* add configurable offset */
        int64_t ts_sec = 0;     /* add configurable offset */
        uint64_t ts_sec_abs, ts_nsec_abs;
        bool is_negative;
 
-       clock_value = bt_ctf_event_get_clock_value(event, clock_class);
        if (!clock_value) {
                g_string_append(pretty->string, "??:??:??.?????????");
                return;
        }
 
-       ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, &ts_nsec);
-       bt_put(clock_value);
+       ret = bt_clock_value_get_value_ns_from_epoch(clock_value, &ts_nsec);
        if (ret) {
                // TODO: log, this is unexpected
                g_string_append(pretty->string, "Error");
@@ -193,9 +170,10 @@ void print_timestamp_wall(struct pretty_component *pretty,
                struct tm tm;
                time_t time_s = (time_t) ts_sec_abs;
 
-               if (is_negative) {
+               if (is_negative && !pretty->negative_timestamp_warning_done) {
                        // TODO: log instead
                        fprintf(stderr, "[warning] Fallback to [sec.ns] to print negative time value. Use --clock-seconds.\n");
+                       pretty->negative_timestamp_warning_done = true;
                        goto seconds;
                }
 
@@ -249,29 +227,29 @@ end:
 
 static
 enum bt_component_status print_event_timestamp(struct pretty_component *pretty,
-               struct bt_ctf_event *event,
+               struct bt_event *event,
                struct bt_clock_class_priority_map *cc_prio_map,
                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;
+       struct bt_stream *stream = NULL;
+       struct bt_stream_class *stream_class = NULL;
+       struct bt_trace *trace = NULL;
+       struct bt_clock_class *clock_class = NULL;
 
-       stream = bt_ctf_event_get_stream(event);
+       stream = bt_event_borrow_stream(event);
        if (!stream) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
 
-       stream_class = bt_ctf_stream_get_class(stream);
+       stream_class = bt_stream_borrow_class(stream);
        if (!stream_class) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       trace = bt_ctf_stream_class_get_trace(stream_class);
+       trace = bt_stream_class_borrow_trace(stream_class);
        if (!trace) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
@@ -283,7 +261,7 @@ enum bt_component_status print_event_timestamp(struct pretty_component *pretty,
        }
 
        clock_class =
-               bt_clock_class_priority_map_get_highest_priority_clock_class(
+               bt_clock_class_priority_map_borrow_highest_priority_clock_class(
                        cc_prio_map);
        if (!clock_class) {
                ret = BT_COMPONENT_STATUS_ERROR;
@@ -301,7 +279,10 @@ enum bt_component_status print_event_timestamp(struct pretty_component *pretty,
        if (pretty->options.print_timestamp_cycles) {
                print_timestamp_cycles(pretty, clock_class, event);
        } else {
-               print_timestamp_wall(pretty, clock_class, event);
+               struct bt_clock_value *clock_value =
+                       bt_event_borrow_clock_value(event, clock_class);
+
+               print_timestamp_wall(pretty, clock_value);
        }
        if (pretty->use_colors) {
                g_string_append(pretty->string, COLOR_RST);
@@ -346,36 +327,32 @@ 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_event *event,
                struct bt_clock_class_priority_map *cc_prio_map)
 {
        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;
+       struct bt_event_class *event_class = NULL;
+       struct bt_stream_class *stream_class = NULL;
+       struct bt_trace *trace_class = NULL;
        int dom_print = 0;
 
-       event_class = bt_ctf_event_get_class(event);
+       event_class = bt_event_borrow_class(event);
        if (!event_class) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       stream_class = bt_ctf_event_class_get_stream_class(event_class);
+       stream_class = bt_event_class_borrow_stream_class(event_class);
        if (!stream_class) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       trace_class = bt_ctf_stream_class_get_trace(stream_class);
+       trace_class = bt_stream_class_borrow_trace(stream_class);
        if (!trace_class) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
@@ -388,7 +365,7 @@ enum bt_component_status print_event_header(struct pretty_component *pretty,
        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, ", ");
@@ -407,8 +384,8 @@ enum bt_component_status print_event_header(struct pretty_component *pretty,
        if (pretty->options.print_trace_hostname_field) {
                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_field_value_by_name(
+                       trace_class, "hostname");
                if (hostname_str) {
                        const char *str;
 
@@ -422,15 +399,14 @@ enum bt_component_status print_event_header(struct pretty_component *pretty,
                                        == BT_VALUE_STATUS_OK) {
                                g_string_append(pretty->string, str);
                        }
-                       bt_put(hostname_str);
                        dom_print = 1;
                }
        }
        if (pretty->options.print_trace_domain_field) {
                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_field_value_by_name(
+                       trace_class, "domain");
                if (domain_str) {
                        const char *str;
 
@@ -446,15 +422,14 @@ enum bt_component_status print_event_header(struct pretty_component *pretty,
                                        == BT_VALUE_STATUS_OK) {
                                g_string_append(pretty->string, str);
                        }
-                       bt_put(domain_str);
                        dom_print = 1;
                }
        }
        if (pretty->options.print_trace_procname_field) {
                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_field_value_by_name(
+                       trace_class, "procname");
                if (procname_str) {
                        const char *str;
 
@@ -470,15 +445,15 @@ enum bt_component_status print_event_header(struct pretty_component *pretty,
                                        == BT_VALUE_STATUS_OK) {
                                g_string_append(pretty->string, str);
                        }
-                       bt_put(procname_str);
+
                        dom_print = 1;
                }
        }
        if (pretty->options.print_trace_vpid_field) {
                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_field_value_by_name(
+                       trace_class, "vpid");
                if (vpid_value) {
                        int64_t value;
 
@@ -494,34 +469,34 @@ enum bt_component_status print_event_header(struct pretty_component *pretty,
                                        == BT_VALUE_STATUS_OK) {
                                g_string_append_printf(pretty->string, "(%" PRId64 ")", value);
                        }
-                       bt_put(vpid_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) {
+               log_level = bt_event_class_get_log_level(event_class);
+               BT_ASSERT(log_level != BT_EVENT_CLASS_LOG_LEVEL_UNKNOWN);
+               if (log_level != BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) {
                        log_level_str = log_level_names[log_level];
                }
 
@@ -544,7 +519,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, ", ");
@@ -572,7 +547,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);
        }
@@ -581,58 +556,72 @@ 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)
+               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;
+       struct bt_field_type *field_type = NULL;
+       enum bt_integer_base base;
+       enum bt_string_encoding encoding;
        int signedness;
+       struct bt_field_type *int_ft;
        union {
                uint64_t u;
                int64_t s;
        } v;
        bool rst_color = false;
+       enum bt_field_type_id ft_id;
 
-       field_type = bt_ctf_field_get_type(field);
+       field_type = bt_field_borrow_type(field);
        if (!field_type) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       signedness = bt_ctf_field_type_integer_get_signed(field_type);
+
+       ft_id = bt_field_get_type_id(field);
+
+       switch (ft_id) {
+       case BT_FIELD_TYPE_ID_INTEGER:
+               int_ft = field_type;
+               break;
+       case BT_FIELD_TYPE_ID_ENUM:
+               int_ft = bt_field_type_enumeration_borrow_container_field_type(
+                       field_type);
+               break;
+       default:
+               abort();
+       }
+
+       signedness = bt_field_type_integer_is_signed(int_ft);
        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;
-               }
+               ret = bt_field_integer_unsigned_get_value(field, &v.u);
        } else {
-               if (bt_ctf_field_signed_integer_get_value(field, &v.s) < 0) {
-                       ret = BT_COMPONENT_STATUS_ERROR;
-                       goto end;
-               }
+               ret = bt_field_integer_signed_get_value(field, &v.s);
+       }
+
+       if (ret < 0) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
        }
 
-       encoding = bt_ctf_field_type_integer_get_encoding(field_type);
+       encoding = bt_field_type_integer_get_encoding(int_ft);
        switch (encoding) {
-       case BT_CTF_STRING_ENCODING_UTF8:
-       case BT_CTF_STRING_ENCODING_ASCII:
+       case BT_STRING_ENCODING_UTF8:
+       case BT_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:
+       case BT_STRING_ENCODING_NONE:
+       case BT_STRING_ENCODING_UNKNOWN:
                break;
        default:
                ret = BT_COMPONENT_STATUS_ERROR;
@@ -644,13 +633,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_type_integer_get_base(int_ft);
        switch (base) {
-       case BT_CTF_INTEGER_BASE_BINARY:
+       case BT_INTEGER_BASE_BINARY:
        {
                int bitnr, len;
 
-               len = bt_ctf_field_type_integer_get_size(field_type);
+               len = bt_field_type_integer_get_size(int_ft);
                if (len < 0) {
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
@@ -663,12 +652,12 @@ enum bt_component_status print_integer(struct pretty_component *pretty,
                }
                break;
        }
-       case BT_CTF_INTEGER_BASE_OCTAL:
+       case BT_INTEGER_BASE_OCTAL:
        {
                if (signedness) {
                        int len;
 
-                       len = bt_ctf_field_type_integer_get_size(field_type);
+                       len = bt_field_type_integer_get_size(int_ft);
                        if (len < 0) {
                                ret = BT_COMPONENT_STATUS_ERROR;
                                goto end;
@@ -676,7 +665,7 @@ enum bt_component_status print_integer(struct pretty_component *pretty,
                        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;
@@ -686,19 +675,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:
+       case BT_INTEGER_BASE_DECIMAL:
+       case BT_INTEGER_BASE_UNSPECIFIED:
                if (!signedness) {
                        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_INTEGER_BASE_HEXADECIMAL:
        {
                int len;
 
-               len = bt_ctf_field_type_integer_get_size(field_type);
+               len = bt_field_type_integer_get_size(int_ft);
                if (len < 0) {
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
@@ -721,7 +710,6 @@ end:
        if (rst_color) {
                g_string_append(pretty->string, COLOR_RST);
        }
-       bt_put(field_type);
        return ret;
 }
 
@@ -795,66 +783,47 @@ 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)
+               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;
+       struct bt_field_type *enumeration_field_type = NULL;
+       struct bt_field_type *container_field_type = NULL;
+       struct bt_field_type_enumeration_mapping_iterator *iter = NULL;
        int nr_mappings = 0;
-       int is_signed;
 
-       enumeration_field_type = bt_ctf_field_get_type(field);
+       enumeration_field_type = bt_field_borrow_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;
-               goto end;
-       }
-       container_field_type = bt_ctf_field_get_type(container_field);
+       container_field_type =
+               bt_field_type_enumeration_borrow_container_field_type(
+                       enumeration_field_type);
        if (!container_field_type) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       is_signed = bt_ctf_field_type_integer_get_signed(container_field_type);
-       if (is_signed < 0) {
+       iter = bt_field_enumeration_get_mappings(field);
+       if (!iter) {
                ret = BT_COMPONENT_STATUS_ERROR;
                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;
+       g_string_append(pretty->string, "( ");
+       ret = bt_field_type_enumeration_mapping_iterator_next(iter);
+       if (ret) {
+               if (pretty->use_colors) {
+                       g_string_append(pretty->string, COLOR_UNKNOWN);
                }
-               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;
+               g_string_append(pretty->string, "<unknown>");
+               if (pretty->use_colors) {
+                       g_string_append(pretty->string, COLOR_RST);
                }
-               iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
-                               enumeration_field_type, value);
-       }
-       if (!iter) {
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
+               goto skip_loop;
        }
-       g_string_append(pretty->string, "( ");
        for (;;) {
                const char *mapping_name;
 
-               if (bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
+               if (bt_field_type_enumeration_mapping_iterator_signed_get(
                                iter, &mapping_name, NULL, NULL) < 0) {
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
@@ -868,30 +837,19 @@ 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) {
+               if (bt_field_type_enumeration_mapping_iterator_next(iter) < 0) {
                        break;
                }
        }
-       if (!nr_mappings) {
-               if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_UNKNOWN);
-               }
-               g_string_append(pretty->string, "<unknown>");
-               if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_RST);
-               }
-       }
+skip_loop:
        g_string_append(pretty->string, " : container = ");
-       ret = print_integer(pretty, container_field);
+       ret = print_integer(pretty, field);
        if (ret != BT_COMPONENT_STATUS_OK) {
                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;
 }
 
@@ -916,22 +874,22 @@ 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,
+               struct bt_field *_struct,
+               struct bt_field_type *struct_type,
                int i, bool print_names, int *nr_printed_fields,
                GQuark *filter_fields, int filter_array_len)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
        const char *field_name;
-       struct bt_ctf_field *field = NULL;
-       struct bt_ctf_field_type *field_type = NULL;;
+       struct bt_field *field = NULL;
+       struct bt_field_type *field_type = NULL;;
 
-       field = bt_ctf_field_structure_get_field_by_index(_struct, i);
+       field = bt_field_structure_borrow_field_by_index(_struct, i);
        if (!field) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       if (bt_ctf_field_type_structure_get_field(struct_type,
+       if (bt_field_type_structure_borrow_field_by_index(struct_type,
                        &field_name, &field_type, i) < 0) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
@@ -949,31 +907,30 @@ enum bt_component_status print_struct_field(struct pretty_component *pretty,
                g_string_append(pretty->string, " ");
        }
        if (print_names) {
-               print_field_name_equal(pretty, rem_(field_name));
+               print_field_name_equal(pretty, field_name);
        }
        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,
+               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;
+       struct bt_field_type *struct_type = NULL;
        int nr_fields, i, nr_printed_fields;
 
-       struct_type = bt_ctf_field_get_type(_struct);
+       struct_type = bt_field_borrow_type(_struct);
        if (!struct_type) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       nr_fields = bt_ctf_field_type_structure_get_field_count(struct_type);
+       nr_fields = bt_field_type_structure_get_field_count(struct_type);
        if (nr_fields < 0) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
@@ -991,18 +948,18 @@ enum bt_component_status print_struct(struct pretty_component *pretty,
        }
        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,
+               struct bt_field *array, uint64_t i,
                bool is_string, bool print_names)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_ctf_field *field = NULL;
+       struct bt_field *field = NULL;
 
        if (!is_string) {
                if (i != 0) {
@@ -1014,57 +971,57 @@ enum bt_component_status print_array_field(struct pretty_component *pretty,
                        g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
                }
        }
-       field = bt_ctf_field_array_get_field(array, i);
+       field = bt_field_array_borrow_field(array, i);
        if (!field) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
        ret = print_field(pretty, field, print_names, NULL, 0);
+
 end:
-       bt_put(field);
        return ret;
 }
 
 static
 enum bt_component_status print_array(struct pretty_component *pretty,
-               struct bt_ctf_field *array, bool print_names)
+               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;
+       struct bt_field_type *array_type = NULL, *field_type = NULL;
+       enum bt_field_type_id type_id;
        int64_t len;
        uint64_t i;
        bool is_string = false;
 
-       array_type = bt_ctf_field_get_type(array);
+       array_type = bt_field_borrow_type(array);
        if (!array_type) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       field_type = bt_ctf_field_type_array_get_element_type(array_type);
+       field_type = bt_field_type_array_borrow_element_field_type(array_type);
        if (!field_type) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       len = bt_ctf_field_type_array_get_length(array_type);
+       len = bt_field_type_array_get_length(array_type);
        if (len < 0) {
                ret = BT_COMPONENT_STATUS_ERROR;
                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;
+       type_id = bt_field_type_get_type_id(field_type);
+       if (type_id == BT_FIELD_TYPE_ID_INTEGER) {
+               enum bt_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) {
+               encoding = bt_field_type_integer_get_encoding(field_type);
+               if (encoding == BT_STRING_ENCODING_UTF8
+                               || encoding == BT_STRING_ENCODING_ASCII) {
                        int integer_len, integer_alignment;
 
-                       integer_len = bt_ctf_field_type_integer_get_size(field_type);
+                       integer_len = bt_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);
+                       integer_alignment = bt_field_type_get_alignment(field_type);
                        if (integer_alignment < 0) {
                                return BT_COMPONENT_STATUS_ERROR;
                        }
@@ -1101,19 +1058,18 @@ enum bt_component_status print_array(struct pretty_component *pretty,
        } 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,
+               struct bt_field *seq, uint64_t i,
                bool is_string, bool print_names)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_ctf_field *field = NULL;
+       struct bt_field *field = NULL;
 
        if (!is_string) {
                if (i != 0) {
@@ -1125,63 +1081,58 @@ enum bt_component_status print_sequence_field(struct pretty_component *pretty,
                        g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
                }
        }
-       field = bt_ctf_field_sequence_get_field(seq, i);
+       field = bt_field_sequence_borrow_field(seq, i);
        if (!field) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
        ret = print_field(pretty, field, print_names, NULL, 0);
+
 end:
-       bt_put(field);
        return ret;
 }
 
 static
 enum bt_component_status print_sequence(struct pretty_component *pretty,
-               struct bt_ctf_field *seq, bool print_names)
+               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;
-       uint64_t len;
+       struct bt_field_type *seq_type = NULL, *field_type = NULL;
+       enum bt_field_type_id type_id;
+       int64_t len;
        uint64_t i;
        bool is_string = false;
 
-       seq_type = bt_ctf_field_get_type(seq);
+       seq_type = bt_field_borrow_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) {
+       len = bt_field_sequence_get_length(seq);
+       if (len < 0) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       field_type = bt_ctf_field_type_sequence_get_element_type(seq_type);
+       field_type = bt_field_type_sequence_borrow_element_field_type(seq_type);
        if (!field_type) {
                ret = BT_COMPONENT_STATUS_ERROR;
                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;
+       type_id = bt_field_type_get_type_id(field_type);
+       if (type_id == BT_FIELD_TYPE_ID_INTEGER) {
+               enum bt_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) {
+               encoding = bt_field_type_integer_get_encoding(field_type);
+               if (encoding == BT_STRING_ENCODING_UTF8
+                               || encoding == BT_STRING_ENCODING_ASCII) {
                        int integer_len, integer_alignment;
 
-                       integer_len = bt_ctf_field_type_integer_get_size(field_type);
+                       integer_len = bt_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);
+                       integer_alignment = bt_field_type_get_alignment(field_type);
                        if (integer_alignment < 0) {
                                ret = BT_COMPONENT_STATUS_ERROR;
                                goto end;
@@ -1220,21 +1171,19 @@ enum bt_component_status print_sequence(struct pretty_component *pretty,
        } 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)
+               struct bt_field *variant, bool print_names)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_ctf_field *field = NULL;
+       struct bt_field *field = NULL;
 
-       field = bt_ctf_field_variant_get_current_field(variant);
+       field = bt_field_variant_borrow_current_field(variant);
        if (!field) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
@@ -1242,35 +1191,67 @@ enum bt_component_status print_variant(struct pretty_component *pretty,
        g_string_append(pretty->string, "{ ");
        pretty->depth++;
        if (print_names) {
-               int iter_ret;
-               struct bt_ctf_field *tag_field = NULL;
+               int iret;
+               struct bt_field_type *var_ft;
+               struct bt_field_type *tag_ft;
+               struct bt_field_type *container_ft;
                const char *tag_choice;
-               struct bt_ctf_field_type_enumeration_mapping_iterator *iter;
+               bt_bool is_signed;
+               struct bt_field_type_enumeration_mapping_iterator *iter;
+
+               var_ft = bt_field_borrow_type(variant);
+               tag_ft = bt_field_type_variant_borrow_tag_field_type(
+                       var_ft);
+               container_ft =
+                       bt_field_type_enumeration_borrow_container_field_type(
+                               tag_ft);
+               is_signed = bt_field_type_integer_is_signed(container_ft);
+
+               if (is_signed) {
+                       int64_t tag;
+
+                       iret = bt_field_variant_get_tag_signed(variant, &tag);
+                       if (iret) {
+                               ret = BT_COMPONENT_STATUS_ERROR;
+                               goto end;
+                       }
+
+                       iter = bt_field_type_enumeration_signed_find_mappings_by_value(
+                               tag_ft, tag);
+               } else {
+                       uint64_t tag;
+
+                       iret = bt_field_variant_get_tag_unsigned(variant, &tag);
+                       if (iret) {
+                               ret = BT_COMPONENT_STATUS_ERROR;
+                               goto end;
+                       }
+
+                       iter = bt_field_type_enumeration_unsigned_find_mappings_by_value(
+                               tag_ft, tag);
+               }
 
-               tag_field = bt_ctf_field_variant_get_tag(variant);
-               if (!tag_field) {
+               if (!iter) {
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
                }
 
-               iter = bt_ctf_field_enumeration_get_mappings(tag_field);
-               if (!iter) {
-                       bt_put(tag_field);
+               iret = bt_field_type_enumeration_mapping_iterator_next(
+                       iter);
+               if (!iter || ret) {
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
                }
 
-               iter_ret =
-                       bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
+               iret =
+                       bt_field_type_enumeration_mapping_iterator_signed_get(
                                iter, &tag_choice, NULL, NULL);
-               if (iter_ret) {
+               if (iret) {
                        bt_put(iter);
-                       bt_put(tag_field);
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
                }
-               print_field_name_equal(pretty, rem_(tag_choice));
-               bt_put(tag_field);
+               print_field_name_equal(pretty, tag_choice);
                bt_put(iter);
        }
        ret = print_field(pretty, field, print_names, NULL, 0);
@@ -1279,27 +1260,27 @@ enum bt_component_status print_variant(struct pretty_component *pretty,
        }
        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,
+               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_type_id type_id;
 
-       type_id = bt_ctf_field_get_type_id(field);
+       type_id = bt_field_get_type_id(field);
        switch (type_id) {
-       case CTF_TYPE_INTEGER:
+       case BT_CTF_FIELD_TYPE_ID_INTEGER:
                return print_integer(pretty, field);
-       case CTF_TYPE_FLOAT:
+       case BT_CTF_FIELD_TYPE_ID_FLOAT:
        {
                double v;
 
-               if (bt_ctf_field_floating_point_get_value(field, &v)) {
+               if (bt_field_floating_point_get_value(field, &v)) {
                        return BT_COMPONENT_STATUS_ERROR;
                }
                if (pretty->use_colors) {
@@ -1311,25 +1292,34 @@ enum bt_component_status print_field(struct pretty_component *pretty,
                }
                return BT_COMPONENT_STATUS_OK;
        }
-       case CTF_TYPE_ENUM:
+       case BT_CTF_FIELD_TYPE_ID_ENUM:
                return print_enum(pretty, field);
-       case CTF_TYPE_STRING:
+       case BT_CTF_FIELD_TYPE_ID_STRING:
+       {
+               const char *str;
+
+               str = bt_field_string_get_value(field);
+               if (!str) {
+                       return BT_COMPONENT_STATUS_ERROR;
+               }
+
                if (pretty->use_colors) {
                        g_string_append(pretty->string, COLOR_STRING_VALUE);
                }
-               print_escape_string(pretty, bt_ctf_field_string_get_value(field));
+               print_escape_string(pretty, str);
                if (pretty->use_colors) {
                        g_string_append(pretty->string, COLOR_RST);
                }
                return BT_COMPONENT_STATUS_OK;
-       case CTF_TYPE_STRUCT:
+       }
+       case BT_CTF_FIELD_TYPE_ID_STRUCT:
                return print_struct(pretty, field, print_names, filter_fields,
                                filter_array_len);
-       case CTF_TYPE_VARIANT:
+       case BT_CTF_FIELD_TYPE_ID_VARIANT:
                return print_variant(pretty, field, print_names);
-       case CTF_TYPE_ARRAY:
+       case BT_CTF_FIELD_TYPE_ID_ARRAY:
                return print_array(pretty, field, print_names);
-       case CTF_TYPE_SEQUENCE:
+       case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
                return print_sequence(pretty, field, print_names);
        default:
                // TODO: log instead
@@ -1340,18 +1330,18 @@ enum bt_component_status print_field(struct pretty_component *pretty,
 
 static
 enum bt_component_status print_stream_packet_context(struct pretty_component *pretty,
-               struct bt_ctf_event *event)
+               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;
+       struct bt_packet *packet = NULL;
+       struct bt_field *main_field = NULL;
 
-       packet = bt_ctf_event_get_packet(event);
+       packet = bt_event_borrow_packet(event);
        if (!packet) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       main_field = bt_ctf_packet_get_context(packet);
+       main_field = bt_packet_borrow_context(packet);
        if (!main_field) {
                goto end;
        }
@@ -1366,20 +1356,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)
+               struct bt_event *event)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_ctf_field *main_field = NULL;
+       struct bt_field *main_field = NULL;
 
-       main_field = bt_ctf_event_get_header(event);
+       main_field = bt_event_borrow_header(event);
        if (!main_field) {
                goto end;
        }
@@ -1392,19 +1381,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)
+               struct bt_event *event)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_ctf_field *main_field = NULL;
+       struct bt_field *main_field = NULL;
 
-       main_field = bt_ctf_event_get_stream_event_context(event);
+       main_field = bt_event_borrow_stream_event_context(event);
        if (!main_field) {
                goto end;
        }
@@ -1417,19 +1406,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)
+               struct bt_event *event)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_ctf_field *main_field = NULL;
+       struct bt_field *main_field = NULL;
 
-       main_field = bt_ctf_event_get_event_context(event);
+       main_field = bt_event_borrow_context(event);
        if (!main_field) {
                goto end;
        }
@@ -1442,19 +1431,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)
+               struct bt_event *event)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_ctf_field *main_field = NULL;
+       struct bt_field *main_field = NULL;
 
-       main_field = bt_ctf_event_get_event_payload(event);
+       main_field = bt_event_borrow_payload(event);
        if (!main_field) {
                goto end;
        }
@@ -1467,8 +1456,25 @@ 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:
+       return ret;
+}
+
+static
+int flush_buf(struct pretty_component *pretty)
+{
+       int ret = 0;
+
+       if (pretty->string->len == 0) {
+               goto end;
+       }
+
+       if (fwrite(pretty->string->str, pretty->string->len, 1, pretty->out) != 1) {
+               ret = -1;
+       }
+
 end:
-       bt_put(main_field);
        return ret;
 }
 
@@ -1477,13 +1483,14 @@ enum bt_component_status 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_event *event =
+               bt_notification_event_borrow_event(event_notif);
        struct bt_clock_class_priority_map *cc_prio_map =
-               bt_notification_event_get_clock_class_priority_map(event_notif);
+               bt_notification_event_borrow_clock_class_priority_map(
+                       event_notif);
 
-       assert(event);
-       assert(cc_prio_map);
+       BT_ASSERT(event);
+       BT_ASSERT(cc_prio_map);
        pretty->start_line = true;
        g_string_assign(pretty->string, "");
        ret = print_event_header(pretty, event, cc_prio_map);
@@ -1519,13 +1526,129 @@ enum bt_component_status pretty_print_event(struct pretty_component *pretty,
        }
 
        g_string_append_c(pretty->string, '\n');
-       if (fwrite(pretty->string->str, pretty->string->len, 1, pretty->out) != 1) {
+       if (flush_buf(pretty)) {
                ret = BT_COMPONENT_STATUS_ERROR;
                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)
+{
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_stream *stream = NULL;
+       struct bt_stream_class *stream_class = NULL;
+       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_clock_value *clock_value = NULL;
+
+       /* Stream name */
+       switch (bt_notification_get_type(notif)) {
+       case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS:
+               stream = bt_notification_discarded_events_borrow_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_borrow_stream(notif);
+               count = bt_notification_discarded_packets_get_count(notif);
+               is_discarded_events = false;
+               break;
+       default:
+               abort();
+       }
+
+       BT_ASSERT(stream);
+       stream_name = bt_stream_get_name(stream);
+
+       /* Stream class ID */
+       stream_class = bt_stream_borrow_class(stream);
+       BT_ASSERT(stream_class);
+       stream_class_id = bt_stream_class_get_id(stream_class);
+
+       /* Stream ID */
+       stream_id = bt_stream_get_id(stream);
+
+       /* Trace path */
+       trace = bt_stream_class_borrow_trace(stream_class);
+       BT_ASSERT(trace);
+       trace_name = bt_trace_get_name(trace);
+       if (!trace_name) {
+               trace_name = "(unknown)";
+       }
+
+       /* Trace UUID */
+       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 [",
+               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_borrow_begin_clock_value(notif) :
+               bt_notification_discarded_packets_borrow_begin_clock_value(notif);
+       print_timestamp_wall(pretty, clock_value);
+       fprintf(stderr, "%s] and [", pretty->string->str);
+       g_string_assign(pretty->string, "");
+       clock_value = is_discarded_events ?
+               bt_notification_discarded_events_borrow_end_clock_value(notif) :
+               bt_notification_discarded_packets_borrow_end_clock_value(notif);
+       print_timestamp_wall(pretty, clock_value);
+       fprintf(stderr, "%s] in trace \"%s\" ",
+               pretty->string->str, trace_name);
+
+       if (trace_uuid) {
+               fprintf(stderr,
+                       "(UUID: %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x) ",
+                       trace_uuid[0],
+                       trace_uuid[1],
+                       trace_uuid[2],
+                       trace_uuid[3],
+                       trace_uuid[4],
+                       trace_uuid[5],
+                       trace_uuid[6],
+                       trace_uuid[7],
+                       trace_uuid[8],
+                       trace_uuid[9],
+                       trace_uuid[10],
+                       trace_uuid[11],
+                       trace_uuid[12],
+                       trace_uuid[13],
+                       trace_uuid[14],
+                       trace_uuid[15]);
+       } else {
+               fprintf(stderr, "(no UUID) ");
+       }
+
+       fprintf(stderr, "within stream \"%s\" (stream class ID: %" PRId64 ", ",
+               stream_name, stream_class_id);
+
+       if (stream_id >= 0) {
+               fprintf(stderr, "stream ID: %" PRId64, stream_id);
+       } else {
+               fprintf(stderr, "no stream ID");
+       }
+
+       fprintf(stderr, ").%s\n", bt_common_color_reset());
        return ret;
 }
This page took 0.044665 seconds and 4 git commands to generate.