All of lore.kernel.org
 help / color / mirror / Atom feed
* rtla osnoise hist: average duration is always zero
@ 2022-12-24 12:39 Andreas Ziegler
  2022-12-24 21:17 ` Slade Watkins
  2022-12-28 15:25 ` Daniel Bristot de Oliveira
  0 siblings, 2 replies; 9+ messages in thread
From: Andreas Ziegler @ 2022-12-24 12:39 UTC (permalink / raw)
  To: Daniel Bristot de Oliveira, Steven Rostedt
  Cc: linux-trace-devel, linux-kernel

-- Observed in, but not limited to, Linux 6.1.1

Dear all,

rtla osnoise hist always outputs '0' as average duration value. Example:

# rtla osnoise hist -P F:1 -c 0-1 -r 900000 -d 1M -b 1 -E 5000 -T 1
# RTLA osnoise histogram
# Time unit is microseconds (us)
# Duration:   0 00:01:00
   ...
count:     5629      1364
min:          1         1
avg:          0         0
max:       2955        56

This is due to sum_sample in osnoise_hist_update_multiple() being 
calculated as the sum (duration), not as sum (duration * count).

Rounding, instead of truncating, of the average value would be cool.

The following patch would solve the issue described above:


Sampled duration must be weighted by observed quantity, to arrive at a
correct average duration value.

Fix calculation of total duration by summing (duration * count).
Introduce rounding for calculation of final value.

Signed-off-by: Andreas Ziegler <br015@umbiko.net>

--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -121,6 +121,7 @@
  {
  	struct osnoise_hist_params *params = tool->params;
  	struct osnoise_hist_data *data = tool->data;
+	unsigned long long total_duration;
  	int entries = data->entries;
  	int bucket;
  	int *hist;
@@ -131,10 +132,12 @@
  	if (data->bucket_size)
  		bucket = duration / data->bucket_size;

+	total_duration = duration * count;
+
  	hist = data->hist[cpu].samples;
  	data->hist[cpu].count += count;
  	update_min(&data->hist[cpu].min_sample, &duration);
-	update_sum(&data->hist[cpu].sum_sample, &duration);
+	update_sum(&data->hist[cpu].sum_sample, &total_duration);
  	update_max(&data->hist[cpu].max_sample, &duration);

  	if (bucket < entries)
@@ -333,7 +336,7 @@

  		if (data->hist[cpu].count)
  			trace_seq_printf(trace->seq, "%9llu ",
-					data->hist[cpu].sum_sample / data->hist[cpu].count);
+				(data->hist[cpu].sum_sample + data->hist[cpu].count / 2) / 
data->hist[cpu].count);
  		else
  			trace_seq_printf(trace->seq, "        - ");
  	}


Kind regards,
Andreas

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-01-12 14:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-24 12:39 rtla osnoise hist: average duration is always zero Andreas Ziegler
2022-12-24 21:17 ` Slade Watkins
2022-12-26 11:50   ` Andreas Ziegler
2022-12-28 15:25 ` Daniel Bristot de Oliveira
2023-01-03 10:33   ` [PATCH 0/2 v2] rtla osnoise hist average calculation Andreas Ziegler
2023-01-03 10:33   ` [PATCH 1/2 v2] tools/tracing/rtla: osnoise_hist: use total duration for " Andreas Ziegler
2023-01-12 14:32     ` Daniel Bristot de Oliveira
2023-01-03 10:34   ` [PATCH 2/2 v2] tools/tracing/rtla: osnoise_hist: display average with two-digit precision Andreas Ziegler
2023-01-12 14:33     ` Daniel Bristot de Oliveira

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.