diff mbox series

[1/2,v2] tools/tracing/rtla: osnoise_hist: use total duration for average calculation

Message ID 20230103103400.275566-2-br015@umbiko.net (mailing list archive)
State Handled Elsewhere
Headers show
Series rtla osnoise hist average calculation | expand

Commit Message

Andreas Ziegler Jan. 3, 2023, 10:33 a.m. UTC
Sampled durations must be weighted by observed quantity, to arrive at a correct
average duration value.

Perform calculation of total duration by summing (duration * count).

Fixes: 829a6c0b5698 ("rtla/osnoise: Add the hist mode")

Signed-off-by: Andreas Ziegler <br015@umbiko.net>
---
Changes v1 -> v2:
 - add 'Fixes' line (Daniel)

 tools/tracing/rtla/src/osnoise_hist.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Daniel Bristot de Oliveira Jan. 12, 2023, 2:32 p.m. UTC | #1
On 1/3/23 11:33, Andreas Ziegler wrote:
> Sampled durations must be weighted by observed quantity, to arrive at a correct
> average duration value.
> 
> Perform calculation of total duration by summing (duration * count).
> 
> Fixes: 829a6c0b5698 ("rtla/osnoise: Add the hist mode")
> Signed-off-by: Andreas Ziegler <br015@umbiko.net>

Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
-- Daniel

> ---
> Changes v1 -> v2:
>  - add 'Fixes' line (Daniel)
> 
>  tools/tracing/rtla/src/osnoise_hist.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
> index 5d7ea479ac89..fe34452fc4ec 100644
> --- a/tools/tracing/rtla/src/osnoise_hist.c
> +++ b/tools/tracing/rtla/src/osnoise_hist.c
> @@ -121,6 +121,7 @@ static void osnoise_hist_update_multiple(struct osnoise_tool *tool, int cpu,
>  {
>  	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 @@ static void osnoise_hist_update_multiple(struct osnoise_tool *tool, int cpu,
>  	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)
diff mbox series

Patch

diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index 5d7ea479ac89..fe34452fc4ec 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -121,6 +121,7 @@  static void osnoise_hist_update_multiple(struct osnoise_tool *tool, int cpu,
 {
 	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 @@  static void osnoise_hist_update_multiple(struct osnoise_tool *tool, int cpu,
 	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)