From 35fbda93735515c5f07909a96f2d96f6ebaefabb Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 18 Mar 2024 13:59:52 -0400 Subject: [PATCH] sink.text.details: don't write empty strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch makes a `sink.text.details` not write the value of a trace environment entry or of a value object when it's an empty string. This is mostly because I don't like to keep plain text files with significant trailing whitespaces in this repository, and `data/plugins/src.ctf.lttng-live/cli-multi-domains.expect` had some, for example: trace_creation_datetime:️▒ trace_name:▒ where `▒` is a space. Of course we'll have the same issue if a user string contains only whitespaces instead of being empty, but since it's unlikely that we'll do this in our own tests, this patch is good enough for me. Signed-off-by: Philippe Proulx Change-Id: I6be83e2721bc6ce98e1459a7df42e32ccf6b661d Reviewed-on: https://review.lttng.org/c/babeltrace/+/12249 CI-Build: Simon Marchi Tested-by: jenkins --- src/plugins/text/details/write.c | 16 +++++++++++----- .../src.ctf.lttng-live/cli-multi-domains.expect | 16 ++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/plugins/text/details/write.c b/src/plugins/text/details/write.c index 1962f5df..5c9f9e75 100644 --- a/src/plugins/text/details/write.c +++ b/src/plugins/text/details/write.c @@ -413,8 +413,11 @@ void write_value(struct details_write_ctx *ctx, const bt_value *value, write_float_prop_value(ctx, bt_value_real_get(value)); break; case BT_VALUE_TYPE_STRING: - write_sp(ctx); - write_str_prop_value(ctx, bt_value_string_get(value)); + if (strlen(bt_value_string_get(value)) > 0) { + write_sp(ctx); + write_str_prop_value(ctx, bt_value_string_get(value)); + } + break; case BT_VALUE_TYPE_ARRAY: { @@ -2122,16 +2125,19 @@ void write_trace(struct details_write_ctx *ctx, const bt_trace *trace) BT_ASSERT_DBG(value); write_compound_member_name(ctx, name); - write_sp(ctx); if (bt_value_get_type(value) == BT_VALUE_TYPE_SIGNED_INTEGER) { + write_sp(ctx); write_int_prop_value(ctx, bt_value_integer_signed_get(value)); } else if (bt_value_get_type(value) == BT_VALUE_TYPE_STRING) { - write_str_prop_value(ctx, - bt_value_string_get(value)); + if (strlen(bt_value_string_get(value)) > 0) { + write_sp(ctx); + write_str_prop_value(ctx, + bt_value_string_get(value)); + } } else { bt_common_abort(); } diff --git a/tests/data/plugins/src.ctf.lttng-live/cli-multi-domains.expect b/tests/data/plugins/src.ctf.lttng-live/cli-multi-domains.expect index 9c7db7cf..5c534621 100644 --- a/tests/data/plugins/src.ctf.lttng-live/cli-multi-domains.expect +++ b/tests/data/plugins/src.ctf.lttng-live/cli-multi-domains.expect @@ -237,8 +237,8 @@ Stream beginning: kernel_version: #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 sysname: Linux trace_buffering_scheme: global - trace_creation_datetime: - trace_name: + trace_creation_datetime: + trace_name: tracer_major: 2 tracer_minor: 11 tracer_name: lttng-modules @@ -261,8 +261,8 @@ Stream beginning: kernel_version: #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 sysname: Linux trace_buffering_scheme: global - trace_creation_datetime: - trace_name: + trace_creation_datetime: + trace_name: tracer_major: 2 tracer_minor: 11 tracer_name: lttng-modules @@ -285,8 +285,8 @@ Stream beginning: kernel_version: #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 sysname: Linux trace_buffering_scheme: global - trace_creation_datetime: - trace_name: + trace_creation_datetime: + trace_name: tracer_major: 2 tracer_minor: 11 tracer_name: lttng-modules @@ -309,8 +309,8 @@ Stream beginning: kernel_version: #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 sysname: Linux trace_buffering_scheme: global - trace_creation_datetime: - trace_name: + trace_creation_datetime: + trace_name: tracer_major: 2 tracer_minor: 11 tracer_name: lttng-modules -- 2.34.1