X-Git-Url: http://rtime.felk.cvut.cz/gitweb/can-benchmark.git/blobdiff_plain/0050e301dae44fac57f8b30a22f07ec870618c2d..869acdaf3491ca1072f6284a260e6e648af2c271:/latester/histogram.h diff --git a/latester/histogram.h b/latester/histogram.h index b4546e4..52dc664 100644 --- a/latester/histogram.h +++ b/latester/histogram.h @@ -3,6 +3,7 @@ struct histogram { unsigned *data; + unsigned out_below, out_above; unsigned allocated; unsigned resolution; }; @@ -14,6 +15,7 @@ int histogram_init(struct histogram *h, size_t mem; h->allocated = max_value/resolution + 1; h->resolution = resolution; + h->out_below = h->out_above = 0; mem = h->allocated*sizeof(*h->data); h->data = malloc(mem); if (h->data) { @@ -25,10 +27,15 @@ int histogram_init(struct histogram *h, void histogram_add(struct histogram *h, int value) { - if (value < 0) value = 0; + if (value < 0) { + h->out_below++; + return; + } unsigned index = value / h->resolution; - if (index >= h->allocated) + if (index >= h->allocated) { + h->out_above++; index = h->allocated - 1; + } h->data[index]++; } @@ -56,6 +63,7 @@ struct histogram_stats { unsigned count; unsigned long long sum; unsigned avg; + unsigned below, above; /* Count of data out of histogram range */ unsigned percentile[101]; }; @@ -87,6 +95,9 @@ void histogram_stats(struct histogram *h, struct histogram_stats *s) while (sum < i * s->count / 100) sum += h->data[j++]; s->percentile[100] = (j-1) * h->resolution; + + s->below = h->out_below; + s->above = h->out_above; } #endif