Skip to content

Commit 59237b0

Browse files
lclaudioDaniel Bristot de Oliveira
authored andcommitted
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 f5c0cda ("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/[email protected] Suggested-by: Daniel Bristot de Oliveira <[email protected]> Reviewed-by: John Kacur <[email protected]> Reviewed-by: Clark Williams <[email protected]> Signed-off-by: Luis Claudio R. Goncalves <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]>
1 parent 6ba59ff commit 59237b0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct osnoise_top_params {
4242
int hk_cpus;
4343
int warmup;
4444
int buffer_size;
45+
int pretty_output;
4546
cpu_set_t hk_cpu_set;
4647
struct sched_attr sched_param;
4748
struct trace_events *events;
@@ -163,7 +164,9 @@ static void osnoise_top_header(struct osnoise_tool *top)
163164

164165
get_duration(top->start_time, duration, sizeof(duration));
165166

166-
trace_seq_printf(s, "\033[2;37;40m");
167+
if (params->pretty_output)
168+
trace_seq_printf(s, "\033[2;37;40m");
169+
167170
trace_seq_printf(s, " ");
168171

169172
if (params->mode == MODE_OSNOISE) {
@@ -174,12 +177,16 @@ static void osnoise_top_header(struct osnoise_tool *top)
174177
}
175178

176179
trace_seq_printf(s, " ");
177-
trace_seq_printf(s, "\033[0;0;0m");
180+
181+
if (params->pretty_output)
182+
trace_seq_printf(s, "\033[0;0;0m");
178183
trace_seq_printf(s, "\n");
179184

180185
trace_seq_printf(s, "duration: %9s | time is in us\n", duration);
181186

182-
trace_seq_printf(s, "\033[2;30;47m");
187+
if (params->pretty_output)
188+
trace_seq_printf(s, "\033[2;30;47m");
189+
183190
trace_seq_printf(s, "CPU Period Runtime ");
184191
trace_seq_printf(s, " Noise ");
185192
trace_seq_printf(s, " %% CPU Aval ");
@@ -192,7 +199,8 @@ static void osnoise_top_header(struct osnoise_tool *top)
192199
trace_seq_printf(s, " IRQ Softirq Thread");
193200

194201
eol:
195-
trace_seq_printf(s, "\033[0;0;0m");
202+
if (params->pretty_output)
203+
trace_seq_printf(s, "\033[0;0;0m");
196204
trace_seq_printf(s, "\n");
197205
}
198206

@@ -619,6 +627,9 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *p
619627
auto_house_keeping(&params->monitored_cpus);
620628
}
621629

630+
if (isatty(1) && !params->quiet)
631+
params->pretty_output = 1;
632+
622633
return 0;
623634

624635
out_err:

0 commit comments

Comments
 (0)