sink.text.pretty: print discarded events and packets messages
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 4 Jul 2017 17:59:54 +0000 (13:59 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 6 Jul 2017 20:26:54 +0000 (16:26 -0400)
When getting a discarded events or discarded packets notification in
sink.text.pretty, print a warning on the standard error stream (to
remain compatible with Babeltrace 1 which does that) which looks like
this:

    WARNING: Tracer discarded 83565 events between [20:01:32.062781965]
    and [20:01:32.126649071] in trace "hostname/the-trace" (UUID:
    a560bbc4-7f93-b346-a980-3959745a0f5d) within stream
    "/home/user/my-traces/the-trace/stream-1048576_3_0"
    (stream class ID: 1, stream ID: 3).

The message also indicates when the trace has no UUID, or when the
stream has no (instance) ID. The stream class ID is always available.
When the trace's or stream's name is unavailable, `(unknown)` is
printed.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/text/pretty/pretty.c
plugins/text/pretty/pretty.h
plugins/text/pretty/print.c

index e8f89d3a38ee2d2901b3427a14507c1df197c776..f7a1b8bc08874e34a6d625532227e39302def6f6 100644 (file)
@@ -154,6 +154,10 @@ enum bt_component_status handle_notification(struct pretty_component *pretty,
        case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
        case BT_NOTIFICATION_TYPE_STREAM_END:
                break;
+       case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS:
+       case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS:
+               ret = pretty_print_discarded_elements(pretty, notification);
+               break;
        default:
                fprintf(stderr, "Unhandled notification type\n");
        }
@@ -172,6 +176,8 @@ void pretty_port_connected(
        struct pretty_component *pretty;
        static const enum bt_notification_type notif_types[] = {
                BT_NOTIFICATION_TYPE_EVENT,
+               BT_NOTIFICATION_TYPE_DISCARDED_PACKETS,
+               BT_NOTIFICATION_TYPE_DISCARDED_EVENTS,
                BT_NOTIFICATION_TYPE_SENTINEL,
        };
 
index f51ee6528206b06473a0eb47b59ec988e8b60539..272e06cff3a05f19784e5e1b81150cb5df2fb7b8 100644 (file)
@@ -128,4 +128,9 @@ BT_HIDDEN
 enum bt_component_status pretty_print_event(struct pretty_component *pretty,
                struct bt_notification *event_notif);
 
+BT_HIDDEN
+enum bt_component_status pretty_print_discarded_elements(
+               struct pretty_component *pretty,
+               struct bt_notification *notif);
+
 #endif /* BABELTRACE_PLUGIN_TEXT_PRETTY_PRETTY_H */
index 1161a3869d969ac707860d6e3ed9cb0343acff74..7271c3f9acd8726a8ad8fdc534371efbba9fcda3 100644 (file)
@@ -37,6 +37,8 @@
 #include <babeltrace/ctf-ir/fields.h>
 #include <babeltrace/ctf-ir/trace.h>
 #include <babeltrace/graph/notification-event.h>
+#include <babeltrace/graph/notification-discarded-events.h>
+#include <babeltrace/graph/notification-discarded-packets.h>
 #include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/bitfield-internal.h>
 #include <babeltrace/common-internal.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
@@ -131,24 +133,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_ctf_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);
        if (ret) {
                // TODO: log, this is unexpected
                g_string_append(pretty->string, "Error");
@@ -301,7 +299,11 @@ 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_ctf_clock_value *clock_value =
+                       bt_ctf_event_get_clock_value(event, clock_class);
+
+               print_timestamp_wall(pretty, clock_value);
+               bt_put(clock_value);
        }
        if (pretty->use_colors) {
                g_string_append(pretty->string, COLOR_RST);
@@ -1472,6 +1474,23 @@ 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:
+       return ret;
+}
+
 BT_HIDDEN
 enum bt_component_status pretty_print_event(struct pretty_component *pretty,
                struct bt_notification *event_notif)
@@ -1519,7 +1538,7 @@ 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;
        }
@@ -1529,3 +1548,122 @@ end:
        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_ctf_stream *stream = NULL;
+       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_ctf_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;
+
+       /* Stream name */
+       switch (bt_notification_get_type(notif)) {
+       case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS:
+               stream = bt_notification_discarded_events_get_stream(notif);
+               is_discarded_events = true;
+               break;
+       case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS:
+               stream = bt_notification_discarded_packets_get_stream(notif);
+               is_discarded_events = false;
+               break;
+       default:
+               abort();
+       }
+
+       assert(stream);
+       stream_name = bt_ctf_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 ID */
+       stream_id = bt_ctf_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);
+       if (!trace_name) {
+               trace_name = "(unknown)";
+       }
+
+       /* Trace UUID */
+       trace_uuid = bt_ctf_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 between [",
+               bt_common_color_fg_yellow(),
+               bt_common_color_bold(),
+               bt_common_color_reset(),
+               bt_common_color_fg_yellow(),
+               is_discarded_events ?
+                       bt_notification_discarded_events_get_count(notif) :
+                       bt_notification_discarded_packets_get_count(notif),
+               is_discarded_events ? "events" : "packets");
+       g_string_assign(pretty->string, "");
+       print_timestamp_wall(pretty,
+               is_discarded_events ?
+               bt_notification_discarded_events_get_begin_clock_value(notif) :
+               bt_notification_discarded_packets_get_begin_clock_value(notif));
+       fprintf(stderr, "%s] and [", pretty->string->str);
+       g_string_assign(pretty->string, "");
+       print_timestamp_wall(pretty,
+               is_discarded_events ?
+               bt_notification_discarded_events_get_end_clock_value(notif) :
+               bt_notification_discarded_packets_get_end_clock_value(notif));
+       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());
+       bt_put(stream);
+       bt_put(stream_class);
+       bt_put(trace);
+       return ret;
+}
This page took 0.029111 seconds and 4 git commands to generate.