Skip to content

Commit f5c0cda

Browse files
author
Daniel Bristot de Oliveira
committed
rtla/timerlat: Use pretty formatting only on interactive tty
timerlat top does some background/font color formatting. While useful on terminal, it breaks the output on other formats. For example, when piping the output for pastebin tools, the format strings are printed as characters. For instance: [2;37;40m Timer Latency [0;0;0m 0 00:00:01 | IRQ Timer Latency (us) | Thread Timer Latency (us) [2;30;47mCPU COUNT | cur min avg max | cur min avg max[0;0;0m 0 #1013 | 1 0 1 54 | 5 2 4 57 1 #1013 | 3 0 1 10 | 6 2 4 15 To avoid this problem, do the formatting only if running on a tty, and in !quiet mode. Link: https://lkml.kernel.org/r/8288e1544ceab21557d5dda93a0f00339497c649.1713968967.git.bristot@kernel.org Cc: Jonathan Corbet <[email protected]> Cc: Juri Lelli <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]>
1 parent a40e5e4 commit f5c0cda

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct timerlat_top_params {
4444
int hk_cpus;
4545
int user_top;
4646
int user_workload;
47+
int pretty_output;
4748
cpu_set_t hk_cpu_set;
4849
struct sched_attr sched_param;
4950
struct trace_events *events;
@@ -179,19 +180,22 @@ timerlat_top_handler(struct trace_seq *s, struct tep_record *record,
179180
/*
180181
* timerlat_top_header - print the header of the tool output
181182
*/
182-
static void timerlat_top_header(struct osnoise_tool *top)
183+
static void timerlat_top_header(struct timerlat_top_params *params, struct osnoise_tool *top)
183184
{
184-
struct timerlat_top_params *params = top->params;
185185
struct trace_seq *s = top->trace.seq;
186186
char duration[26];
187187

188188
get_duration(top->start_time, duration, sizeof(duration));
189189

190-
trace_seq_printf(s, "\033[2;37;40m");
190+
if (params->pretty_output)
191+
trace_seq_printf(s, "\033[2;37;40m");
192+
191193
trace_seq_printf(s, " Timer Latency ");
192194
if (params->user_top)
193195
trace_seq_printf(s, " ");
194-
trace_seq_printf(s, "\033[0;0;0m");
196+
197+
if (params->pretty_output)
198+
trace_seq_printf(s, "\033[0;0;0m");
195199
trace_seq_printf(s, "\n");
196200

197201
trace_seq_printf(s, "%-6s | IRQ Timer Latency (%s) | Thread Timer Latency (%s)", duration,
@@ -204,11 +208,15 @@ static void timerlat_top_header(struct osnoise_tool *top)
204208
}
205209

206210
trace_seq_printf(s, "\n");
207-
trace_seq_printf(s, "\033[2;30;47m");
211+
if (params->pretty_output)
212+
trace_seq_printf(s, "\033[2;30;47m");
213+
208214
trace_seq_printf(s, "CPU COUNT | cur min avg max | cur min avg max");
209215
if (params->user_top)
210216
trace_seq_printf(s, " | cur min avg max");
211-
trace_seq_printf(s, "\033[0;0;0m");
217+
218+
if (params->pretty_output)
219+
trace_seq_printf(s, "\033[0;0;0m");
212220
trace_seq_printf(s, "\n");
213221
}
214222

@@ -305,7 +313,7 @@ timerlat_print_stats(struct timerlat_top_params *params, struct osnoise_tool *to
305313
if (!params->quiet)
306314
clear_terminal(trace->seq);
307315

308-
timerlat_top_header(top);
316+
timerlat_top_header(params, top);
309317

310318
for (i = 0; i < nr_cpus; i++) {
311319
if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus))
@@ -693,6 +701,9 @@ timerlat_top_apply_config(struct osnoise_tool *top, struct timerlat_top_params *
693701
}
694702
}
695703

704+
if (isatty(1) && !params->quiet)
705+
params->pretty_output = 1;
706+
696707
return 0;
697708

698709
out_err:

0 commit comments

Comments
 (0)