sink.text.details: don't write empty strings
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 18 Mar 2024 17:59:52 +0000 (13:59 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
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 <eeppeliteloop@gmail.com>
Change-Id: I6be83e2721bc6ce98e1459a7df42e32ccf6b661d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12249
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/text/details/write.c
tests/data/plugins/src.ctf.lttng-live/cli-multi-domains.expect

index 1962f5dfe3506a775c754370e2a7b1cfd96c9326..5c9f9e75591a6039a8ccd438ecf674aea8806004 100644 (file)
@@ -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();
                        }
index 9c7db7cf55128335e99d264e4bf8d0736006c07c..5c534621a86ab058263a00a0136911b5cf59db2f 100644 (file)
@@ -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
This page took 0.044926 seconds and 4 git commands to generate.