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

rtla/osnoise: Better report when histogram is empty

When osnoise hist does not observe any samples above the threshold,
no entries are recorded and the final report shows empty entries
for the usual statistics (count, min, max, avg):

[~]# osnoise hist -d 5s -T 500
# RTLA osnoise histogram
# Time unit is microseconds (us)
# Duration: 0 00:00:05
Index
over:
count:
min:
avg:
max:

That could lead users to confusing interpretations of the results.

A simple solution is to report 0 for count and the statistics, making it
clear that no noise (above the defined threshold) was observed:

[~]# osnoise hist -d 5s -T 500
# RTLA osnoise histogram
# Time unit is microseconds (us)
# Duration: 0 00:00:05
Index
over: 0
count: 0
min: 0
avg: 0
max: 0

Link: https://lkml.kernel.org/r/Zml6JmH5cbS7-HfZ@uudg.org

Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: John Kacur <jkacur@redhat.com>
Cc: Clark Williams <williams@redhat.com>
Reviewed-by: John Kacur <jkacur@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
587f05a8 59237b0c

+15
+15
tools/tracing/rtla/src/osnoise_hist.c
··· 374 374 { 375 375 struct osnoise_hist_data *data = tool->data; 376 376 struct trace_instance *trace = &tool->trace; 377 + int has_samples = 0; 377 378 int bucket, cpu; 378 379 int total; 379 380 ··· 403 402 continue; 404 403 } 405 404 405 + /* There are samples above the threshold */ 406 + has_samples = 1; 406 407 trace_seq_printf(trace->seq, "\n"); 407 408 trace_seq_do_printf(trace->seq); 408 409 trace_seq_reset(trace->seq); 410 + } 411 + 412 + /* 413 + * If no samples were recorded, skip calculations, print zeroed statistics 414 + * and return. 415 + */ 416 + if (!has_samples) { 417 + trace_seq_reset(trace->seq); 418 + trace_seq_printf(trace->seq, "over: 0\ncount: 0\nmin: 0\navg: 0\nmax: 0\n"); 419 + trace_seq_do_printf(trace->seq); 420 + trace_seq_reset(trace->seq); 421 + return; 409 422 } 410 423 411 424 if (!params->no_index)