Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtla/osnoise: Use pretty formatting only on interactive tty

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>

authored by

Luis Claudio R. Goncalves and committed by
Daniel Bristot de Oliveira
59237b0c 6ba59ff4

+15 -4
+15 -4
tools/tracing/rtla/src/osnoise_top.c
··· 42 42 int hk_cpus; 43 43 int warmup; 44 44 int buffer_size; 45 + int pretty_output; 45 46 cpu_set_t hk_cpu_set; 46 47 struct sched_attr sched_param; 47 48 struct trace_events *events; ··· 164 163 165 164 get_duration(top->start_time, duration, sizeof(duration)); 166 165 167 - trace_seq_printf(s, "\033[2;37;40m"); 166 + if (params->pretty_output) 167 + trace_seq_printf(s, "\033[2;37;40m"); 168 + 168 169 trace_seq_printf(s, " "); 169 170 170 171 if (params->mode == MODE_OSNOISE) { ··· 177 174 } 178 175 179 176 trace_seq_printf(s, " "); 180 - trace_seq_printf(s, "\033[0;0;0m"); 177 + 178 + if (params->pretty_output) 179 + trace_seq_printf(s, "\033[0;0;0m"); 181 180 trace_seq_printf(s, "\n"); 182 181 183 182 trace_seq_printf(s, "duration: %9s | time is in us\n", duration); 184 183 185 - trace_seq_printf(s, "\033[2;30;47m"); 184 + if (params->pretty_output) 185 + trace_seq_printf(s, "\033[2;30;47m"); 186 + 186 187 trace_seq_printf(s, "CPU Period Runtime "); 187 188 trace_seq_printf(s, " Noise "); 188 189 trace_seq_printf(s, " %% CPU Aval "); ··· 199 192 trace_seq_printf(s, " IRQ Softirq Thread"); 200 193 201 194 eol: 202 - trace_seq_printf(s, "\033[0;0;0m"); 195 + if (params->pretty_output) 196 + trace_seq_printf(s, "\033[0;0;0m"); 203 197 trace_seq_printf(s, "\n"); 204 198 } 205 199 ··· 626 618 */ 627 619 auto_house_keeping(&params->monitored_cpus); 628 620 } 621 + 622 + if (isatty(1) && !params->quiet) 623 + params->pretty_output = 1; 629 624 630 625 return 0; 631 626