From cc413248eefb5938459338ea1c543d0e03a339fc Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 20 Sep 2019 05:52:33 -0400 Subject: [PATCH] sink.text.details: add `with-data` initialization parameter 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 Change-Id: I844073b2080df373501a9216d8041f4d6b799c08 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2076 Reviewed-by: Simon Marchi Reviewed-by: Francis Deslauriers --- src/plugins/text/details/details.c | 10 +++ src/plugins/text/details/details.h | 3 + src/plugins/text/details/write.c | 76 ++++++++++++++++--- ...fault-without-data-without-metadata.expect | 0 .../succeed/default-without-data.expect | 26 +++++++ .../sink.text.details/succeed/test_succeed | 4 +- 6 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 tests/data/plugins/sink.text.details/succeed/default-without-data-without-metadata.expect create mode 100644 tests/data/plugins/sink.text.details/succeed/default-without-data.expect diff --git a/src/plugins/text/details/details.c b/src/plugins/text/details/details.c index 582230f0..9c45e39e 100644 --- a/src/plugins/text/details/details.c +++ b/src/plugins/text/details/details.c @@ -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_data_param_name = "with-data"; + 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; } + /* 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); diff --git a/src/plugins/text/details/details.h b/src/plugins/text/details/details.h index f3bd0828..dd52098c 100644 --- a/src/plugins/text/details/details.h +++ b/src/plugins/text/details/details.h @@ -79,6 +79,9 @@ struct details_comp { /* Component's configuration */ struct { + /* Write data objects */ + bool with_data; + /* Write metadata objects */ bool with_meta; diff --git a/src/plugins/text/details/write.c b/src/plugins/text/details/write.c index aa45d3d0..394c63fd 100644 --- a/src/plugins/text/details/write.c +++ b/src/plugins/text/details/write.c @@ -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); - write_nl(ctx); /* * 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); - write_nl(ctx); /* * 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_nl(ctx); 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; } + 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, @@ -2038,7 +2047,6 @@ int write_event_message(struct details_write_ctx *ctx, decr_indent(ctx); end: - return ret; } @@ -2219,6 +2227,18 @@ int write_stream_beginning_message(struct details_write_ctx *ctx, 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; @@ -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); + if (!ctx->details_comp->cfg.with_data) { + goto end; + } + /* 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; + 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, @@ -2396,6 +2424,7 @@ static 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); @@ -2403,6 +2432,10 @@ int write_discarded_events_message(struct details_write_ctx *ctx, 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( @@ -2417,14 +2450,18 @@ int write_discarded_events_message(struct details_write_ctx *ctx, 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); + +end: + return ret; } 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); @@ -2432,6 +2469,10 @@ int write_discarded_packets_message(struct details_write_ctx *ctx, 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( @@ -2446,8 +2487,11 @@ int write_discarded_packets_message(struct details_write_ctx *ctx, 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); + +end: + return ret; } 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); + 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, @@ -2528,10 +2576,6 @@ int details_write_message(struct details_comp *details_comp, /* 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); @@ -2561,5 +2605,17 @@ int details_write_message(struct details_comp *details_comp, 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; } 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 index 00000000..e69de29b 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 index 00000000..95efee2b --- /dev/null +++ b/tests/data/plugins/sink.text.details/succeed/default-without-data.expect @@ -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 diff --git a/tests/plugins/sink.text.details/succeed/test_succeed b/tests/plugins/sink.text.details/succeed/test_succeed index ae4e77d4..85140a1d 100755 --- a/tests/plugins/sink.text.details/succeed/test_succeed +++ b/tests/plugins/sink.text.details/succeed/test_succeed @@ -56,12 +56,14 @@ test_details_no_stream_name() { "${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-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 -- 2.34.1