]> rtime.felk.cvut.cz Git - can-benchmark.git/commitdiff
latester: Add statistics about data out of histogram range
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 17 Oct 2014 13:36:25 +0000 (15:36 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 17 Oct 2014 13:36:25 +0000 (15:36 +0200)
latester/histogram.h
latester/latester.c

index b4546e4a76ef72003105f050efc4d8f0dadd14dd..52dc66427c1b6fe1e52544e1476e79ad6c0f89af 100644 (file)
@@ -3,6 +3,7 @@
 
 struct histogram {
        unsigned *data;
 
 struct histogram {
        unsigned *data;
+       unsigned out_below, out_above;
        unsigned allocated;
        unsigned resolution;
 };
        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;
        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) {
        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)
 {
 
 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;
        unsigned index = value / h->resolution;
-       if (index >= h->allocated)
+       if (index >= h->allocated) {
+               h->out_above++;
                index = h->allocated - 1;
                index = h->allocated - 1;
+       }
        h->data[index]++;
 }
 
        h->data[index]++;
 }
 
@@ -56,6 +63,7 @@ struct histogram_stats {
        unsigned count;
        unsigned long long sum;
        unsigned avg;
        unsigned count;
        unsigned long long sum;
        unsigned avg;
+       unsigned below, above;  /* Count of data out of histogram range */
        unsigned percentile[101];
 };
 
        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;
        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
 }
 
 #endif
index ff627dc18e461d3036273ac1b28779ed24155c5e..72e123b25af1383fb112aeb88ca162c18c53bae5 100644 (file)
@@ -894,6 +894,8 @@ int main(int argc, const char *argv[])
                histogram_stats(&histogram_gw, &hs);
                double avg = hs.count ? (double)hs.sum/hs.count : 0;
                fprintf(opt.f_stat, "avg=%g\n", avg);
                histogram_stats(&histogram_gw, &hs);
                double avg = hs.count ? (double)hs.sum/hs.count : 0;
                fprintf(opt.f_stat, "avg=%g\n", avg);
+               fprintf(opt.f_stat, "out_of_range_below=%d\n", hs.below);
+               fprintf(opt.f_stat, "out_of_range_above=%d\n", hs.above);
                for (i = 0; i <= 20; i++)
                        fprintf(opt.f_stat, "percentile%d=%d\n", i*5, hs.percentile[i*5]);
 
                for (i = 0; i <= 20; i++)
                        fprintf(opt.f_stat, "percentile%d=%d\n", i*5, hs.percentile[i*5]);