sink.text.details: add `with-data` initialization parameter
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 20 Sep 2019 09:52:33 +0000 (05:52 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 25 Sep 2019 02:37:24 +0000 (22:37 -0400)
This patch makes a `sink.text.details` component handle a new
`with-data` initialization parameter. This new parameter controls
whether or not the component writes data lines, as opposed to metadata
lines: anything that's not metadata is considered data, except for
message iterator inactivity messages.

This can be useful to inspect the metadata blocks of the received
messages without having all the message lines.

The new `default-without-data-without-metadata.expect` expectation file
is empty because, without data and without metadata, there's effectively
nothing to write.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I844073b2080df373501a9216d8041f4d6b799c08
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2076
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/plugins/text/details/details.c
src/plugins/text/details/details.h
src/plugins/text/details/write.c
tests/data/plugins/sink.text.details/succeed/default-without-data-without-metadata.expect [new file with mode: 0644]
tests/data/plugins/sink.text.details/succeed/default-without-data.expect [new file with mode: 0644]
tests/plugins/sink.text.details/succeed/test_succeed

index 582230f0fb3dde3a4083880ed2c9952d70554747..9c45e39e4bacbaaf95ed0fc87b84ee3294b29267 100644 (file)
@@ -50,6 +50,9 @@ const char * const color_param_name = "color";
 static
 const char * const with_metadata_param_name = "with-metadata";
 
 static
 const char * const with_metadata_param_name = "with-metadata";
 
+static
+const char * const with_data_param_name = "with-data";
+
 static
 const char * const with_time_param_name = "with-time";
 
 static
 const char * const with_time_param_name = "with-time";
 
@@ -305,6 +308,13 @@ int configure_details_comp(struct details_comp *details_comp,
                goto error;
        }
 
                goto error;
        }
 
+       /* With data objects? */
+       ret = configure_bool_opt(details_comp, params, with_data_param_name,
+               true, &details_comp->cfg.with_data);
+       if (ret) {
+               goto error;
+       }
+
        /* Compact? */
        ret = configure_bool_opt(details_comp, params, compact_param_name,
                false, &details_comp->cfg.compact);
        /* Compact? */
        ret = configure_bool_opt(details_comp, params, compact_param_name,
                false, &details_comp->cfg.compact);
index f3bd08283fd270fdc98ab045c7fd1b5059a5b903..dd52098c61beea8eef87e9d64f16a67b48ad2fab 100644 (file)
@@ -79,6 +79,9 @@ struct details_comp {
 
        /* Component's configuration */
        struct {
 
        /* Component's configuration */
        struct {
+               /* Write data objects */
+               bool with_data;
+
                /* Write metadata objects */
                bool with_meta;
 
                /* Write metadata objects */
                bool with_meta;
 
index aa45d3d08e746abbd8ba5d59225be8d11363246a..394c63fd491da3fb67ff2adf5ef492befad2ca50 100644 (file)
@@ -1596,7 +1596,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                 * rewrite `sc`.
                 */
                write_trace_class(ctx, tc);
                 * rewrite `sc`.
                 */
                write_trace_class(ctx, tc);
-               write_nl(ctx);
 
                /*
                 * Mark this trace class as written, as well as all
 
                /*
                 * Mark this trace class as written, as well as all
@@ -1648,7 +1647,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                 * classes, so we don't need to rewrite `ec`.
                 */
                write_stream_class(ctx, sc);
                 * classes, so we don't need to rewrite `ec`.
                 */
                write_stream_class(ctx, sc);
-               write_nl(ctx);
 
                /*
                 * Mark this stream class as written, as well as all its
 
                /*
                 * Mark this stream class as written, as well as all its
@@ -1681,7 +1679,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                }
 
                write_event_class(ctx, ec);
                }
 
                write_event_class(ctx, ec);
-               write_nl(ctx);
                details_did_write_meta_object(ctx, tc, ec);
                goto end;
        }
                details_did_write_meta_object(ctx, tc, ec);
                goto end;
        }
@@ -1982,6 +1979,18 @@ int write_event_message(struct details_write_ctx *ctx,
                goto end;
        }
 
                goto end;
        }
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
+       if (ctx->str->len > 0) {
+               /*
+                * Output buffer contains metadata: separate blocks with
+                * newline.
+                */
+               write_nl(ctx);
+       }
+
        /* Write time */
        if (bt_stream_class_borrow_default_clock_class_const(sc)) {
                write_time(ctx,
        /* Write time */
        if (bt_stream_class_borrow_default_clock_class_const(sc)) {
                write_time(ctx,
@@ -2038,7 +2047,6 @@ int write_event_message(struct details_write_ctx *ctx,
        decr_indent(ctx);
 
 end:
        decr_indent(ctx);
 
 end:
-
        return ret;
 }
 
        return ret;
 }
 
@@ -2219,6 +2227,18 @@ int write_stream_beginning_message(struct details_write_ctx *ctx,
                goto end;
        }
 
                goto end;
        }
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
+       if (ctx->str->len > 0) {
+               /*
+                * Output buffer contains metadata: separate blocks with
+                * newline.
+                */
+               write_nl(ctx);
+       }
+
        /* Write time */
        if (cc) {
                const bt_clock_snapshot *cs;
        /* Write time */
        if (cc) {
                const bt_clock_snapshot *cs;
@@ -2282,6 +2302,10 @@ int write_stream_end_message(struct details_write_ctx *ctx,
        const bt_clock_class *cc =
                bt_stream_class_borrow_default_clock_class_const(sc);
 
        const bt_clock_class *cc =
                bt_stream_class_borrow_default_clock_class_const(sc);
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (cc) {
                const bt_clock_snapshot *cs;
        /* Write time */
        if (cc) {
                const bt_clock_snapshot *cs;
@@ -2319,6 +2343,10 @@ int write_packet_beginning_message(struct details_write_ctx *ctx,
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
        const bt_field *field;
 
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
        const bt_field *field;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (bt_stream_class_packets_have_beginning_default_clock_snapshot(sc)) {
                write_time(ctx,
        /* Write time */
        if (bt_stream_class_packets_have_beginning_default_clock_snapshot(sc)) {
                write_time(ctx,
@@ -2396,6 +2424,7 @@ static
 int write_discarded_events_message(struct details_write_ctx *ctx,
                const bt_message *msg)
 {
 int write_discarded_events_message(struct details_write_ctx *ctx,
                const bt_message *msg)
 {
+       int ret = 0;
        const bt_stream *stream = bt_message_discarded_events_borrow_stream_const(
                msg);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
        const bt_stream *stream = bt_message_discarded_events_borrow_stream_const(
                msg);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
@@ -2403,6 +2432,10 @@ int write_discarded_events_message(struct details_write_ctx *ctx,
        const bt_clock_snapshot *end_cs = NULL;
        uint64_t count;
 
        const bt_clock_snapshot *end_cs = NULL;
        uint64_t count;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        if (bt_stream_class_discarded_events_have_default_clock_snapshots(sc)) {
                beginning_cs =
                        bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
        if (bt_stream_class_discarded_events_have_default_clock_snapshots(sc)) {
                beginning_cs =
                        bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
@@ -2417,14 +2450,18 @@ int write_discarded_events_message(struct details_write_ctx *ctx,
                count = UINT64_C(-1);
        }
 
                count = UINT64_C(-1);
        }
 
-       return write_discarded_items_message(ctx, "events", stream,
+       ret = write_discarded_items_message(ctx, "events", stream,
                beginning_cs, end_cs, count);
                beginning_cs, end_cs, count);
+
+end:
+       return ret;
 }
 
 static
 int write_discarded_packets_message(struct details_write_ctx *ctx,
                const bt_message *msg)
 {
 }
 
 static
 int write_discarded_packets_message(struct details_write_ctx *ctx,
                const bt_message *msg)
 {
+       int ret = 0;
        const bt_stream *stream = bt_message_discarded_packets_borrow_stream_const(
                msg);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
        const bt_stream *stream = bt_message_discarded_packets_borrow_stream_const(
                msg);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
@@ -2432,6 +2469,10 @@ int write_discarded_packets_message(struct details_write_ctx *ctx,
        const bt_clock_snapshot *end_cs = NULL;
        uint64_t count;
 
        const bt_clock_snapshot *end_cs = NULL;
        uint64_t count;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        if (bt_stream_class_discarded_packets_have_default_clock_snapshots(sc)) {
                beginning_cs =
                        bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
        if (bt_stream_class_discarded_packets_have_default_clock_snapshots(sc)) {
                beginning_cs =
                        bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
@@ -2446,8 +2487,11 @@ int write_discarded_packets_message(struct details_write_ctx *ctx,
                count = UINT64_C(-1);
        }
 
                count = UINT64_C(-1);
        }
 
-       return write_discarded_items_message(ctx, "packets", stream,
+       ret = write_discarded_items_message(ctx, "packets", stream,
                beginning_cs, end_cs, count);
                beginning_cs, end_cs, count);
+
+end:
+       return ret;
 }
 
 static
 }
 
 static
@@ -2460,6 +2504,10 @@ int write_packet_end_message(struct details_write_ctx *ctx,
        const bt_stream *stream = bt_packet_borrow_stream_const(packet);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
 
        const bt_stream *stream = bt_packet_borrow_stream_const(packet);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (bt_stream_class_packets_have_end_default_clock_snapshot(sc)) {
                write_time(ctx,
        /* Write time */
        if (bt_stream_class_packets_have_end_default_clock_snapshot(sc)) {
                write_time(ctx,
@@ -2528,10 +2576,6 @@ int details_write_message(struct details_comp *details_comp,
        /* Reset output buffer */
        g_string_assign(details_comp->str, "");
 
        /* Reset output buffer */
        g_string_assign(details_comp->str, "");
 
-       if (details_comp->printed_something && !details_comp->cfg.compact) {
-               write_nl(&ctx);
-       }
-
        switch (bt_message_get_type(msg)) {
        case BT_MESSAGE_TYPE_EVENT:
                ret = write_event_message(&ctx, msg);
        switch (bt_message_get_type(msg)) {
        case BT_MESSAGE_TYPE_EVENT:
                ret = write_event_message(&ctx, msg);
@@ -2561,5 +2605,17 @@ int details_write_message(struct details_comp *details_comp,
                abort();
        }
 
                abort();
        }
 
+       /*
+        * If this component printed at least one character so far, and
+        * we're not in compact mode, and there's something in the
+        * output buffer for this message, then prepend a newline to the
+        * output buffer to visually separate message blocks.
+        */
+       if (details_comp->printed_something && !details_comp->cfg.compact &&
+                       details_comp->str->len > 0) {
+               /* TODO: Optimize this */
+               g_string_prepend_c(details_comp->str, '\n');
+       }
+
        return ret;
 }
        return ret;
 }
diff --git a/tests/data/plugins/sink.text.details/succeed/default-without-data-without-metadata.expect b/tests/data/plugins/sink.text.details/succeed/default-without-data-without-metadata.expect
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/data/plugins/sink.text.details/succeed/default-without-data.expect b/tests/data/plugins/sink.text.details/succeed/default-without-data.expect
new file mode 100644 (file)
index 0000000..95efee2
--- /dev/null
@@ -0,0 +1,26 @@
+Trace class:
+  Stream class (ID 0):
+    Supports packets: Yes
+    Packets have beginning default clock snapshot: Yes
+    Packets have end default clock snapshot: Yes
+    Supports discarded events: Yes
+    Discarded events have default clock snapshots: Yes
+    Supports discarded packets: No
+    Default clock class:
+      Name: monotonic
+      Description: Monotonic Clock
+      Frequency (Hz): 1,000,000,000
+      Precision (cycles): 0
+      Offset (s): 1,351,530,929
+      Offset (cycles): 945,824,323
+      Origin is Unix epoch: Yes
+      UUID: c19b5ac9-b8e6-4f78-be95-a605d04e34c6
+    Packet context field class: Structure (1 member):
+      cpu_id: Unsigned integer (32-bit, Base 10)
+    Event common context field class: Structure (2 members):
+      vtid: Signed integer (32-bit, Base 10)
+      vpid: Signed integer (32-bit, Base 10)
+    Event class `heartbeat:msg` (ID 0):
+      Log level: Debug (line)
+      Payload field class: Structure (1 member):
+        msg: String
index ae4e77d480ccc151211f53cd72318fc8ce6891cb..85140a1d519ff59ac023c98a7306fef2a9f081fe 100755 (executable)
@@ -56,12 +56,14 @@ test_details_no_stream_name() {
                "${details_args[@]+${details_args[@]}}" -p with-stream-name=no
 }
 
                "${details_args[@]+${details_args[@]}}" -p with-stream-name=no
 }
 
-plan_tests 10
+plan_tests 12
 
 test_details_no_stream_name default wk-heartbeat-u
 test_details_no_stream_name default-compact wk-heartbeat-u -p compact=yes
 test_details_no_stream_name default-compact-without-metadata wk-heartbeat-u -p compact=yes,with-metadata=no
 test_details_no_stream_name default-compact-without-time wk-heartbeat-u -p compact=yes,with-time=no
 
 test_details_no_stream_name default wk-heartbeat-u
 test_details_no_stream_name default-compact wk-heartbeat-u -p compact=yes
 test_details_no_stream_name default-compact-without-metadata wk-heartbeat-u -p compact=yes,with-metadata=no
 test_details_no_stream_name default-compact-without-time wk-heartbeat-u -p compact=yes,with-time=no
+test_details_no_stream_name default-without-data wk-heartbeat-u -p with-data=no
+test_details_no_stream_name default-without-data-without-metadata wk-heartbeat-u -p with-data=no,with-metadata=no
 test_details_no_stream_name default-without-metadata wk-heartbeat-u -p with-metadata=no
 test_details_no_stream_name default-without-names wk-heartbeat-u -p with-stream-name=no,with-trace-name=no,with-stream-class-name=no
 test_details_no_stream_name default-without-time wk-heartbeat-u -p with-time=no
 test_details_no_stream_name default-without-metadata wk-heartbeat-u -p with-metadata=no
 test_details_no_stream_name default-without-names wk-heartbeat-u -p with-stream-name=no,with-trace-name=no,with-stream-class-name=no
 test_details_no_stream_name default-without-time wk-heartbeat-u -p with-time=no
This page took 0.031816 seconds and 4 git commands to generate.