rtla/osnoise: Use pretty formatting only on interactive tty
authorLuis Claudio R. Goncalves <lgoncalv@redhat.com>
Mon, 10 Jun 2024 13:25:28 +0000 (10:25 -0300)
committerDaniel Bristot de Oliveira <bristot@kernel.org>
Fri, 21 Jun 2024 08:17:51 +0000 (10:17 +0200)
osnoise top performs background/font color formatting that could make
the text output confusing if not on a terminal. Use the changes from
commit f5c0cdad6684a ("rtla/timerlat: Use pretty formatting only on
interactive tty") as an inspiration to fix this problem.

Apply the formatting only if running on a tty, and not in quiet mode.

Link: https://lkml.kernel.org/r/Zmb-yP_3EDHliI8Z@uudg.org
Suggested-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Reviewed-by: John Kacur <jkacur@redhat.com>
Reviewed-by: Clark Williams <williams@redhat.com>
Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
tools/tracing/rtla/src/osnoise_top.c

index 07ba55d4ec06f0d7c03bb6cda7b23e2fe9d8eb21..f594a44df840e41a3154bff1f67aa6a816e0d57a 100644 (file)
@@ -42,6 +42,7 @@ struct osnoise_top_params {
        int                     hk_cpus;
        int                     warmup;
        int                     buffer_size;
+       int                     pretty_output;
        cpu_set_t               hk_cpu_set;
        struct sched_attr       sched_param;
        struct trace_events     *events;
@@ -163,7 +164,9 @@ static void osnoise_top_header(struct osnoise_tool *top)
 
        get_duration(top->start_time, duration, sizeof(duration));
 
-       trace_seq_printf(s, "\033[2;37;40m");
+       if (params->pretty_output)
+               trace_seq_printf(s, "\033[2;37;40m");
+
        trace_seq_printf(s, "                                          ");
 
        if (params->mode == MODE_OSNOISE) {
@@ -174,12 +177,16 @@ static void osnoise_top_header(struct osnoise_tool *top)
        }
 
        trace_seq_printf(s, "                                   ");
-       trace_seq_printf(s, "\033[0;0;0m");
+
+       if (params->pretty_output)
+               trace_seq_printf(s, "\033[0;0;0m");
        trace_seq_printf(s, "\n");
 
        trace_seq_printf(s, "duration: %9s | time is in us\n", duration);
 
-       trace_seq_printf(s, "\033[2;30;47m");
+       if (params->pretty_output)
+               trace_seq_printf(s, "\033[2;30;47m");
+
        trace_seq_printf(s, "CPU Period       Runtime ");
        trace_seq_printf(s, "       Noise ");
        trace_seq_printf(s, " %% CPU Aval ");
@@ -192,7 +199,8 @@ static void osnoise_top_header(struct osnoise_tool *top)
        trace_seq_printf(s, "          IRQ      Softirq       Thread");
 
 eol:
-       trace_seq_printf(s, "\033[0;0;0m");
+       if (params->pretty_output)
+               trace_seq_printf(s, "\033[0;0;0m");
        trace_seq_printf(s, "\n");
 }
 
@@ -619,6 +627,9 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *p
                auto_house_keeping(&params->monitored_cpus);
        }
 
+       if (isatty(1) && !params->quiet)
+               params->pretty_output = 1;
+
        return 0;
 
 out_err: