]> rtime.felk.cvut.cz Git - can-benchmark.git/commitdiff
latester: Add percentiles to statistics
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 4 Feb 2014 17:32:56 +0000 (18:32 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 4 Feb 2014 17:32:56 +0000 (18:32 +0100)
latester/histogram.h
latester/latester.c

index 80d629e32d4a9518c90884d54bfabdde3847863a..b7c1cca7a3ed0f8abb6f7b989462693ab009b1d2 100644 (file)
@@ -52,5 +52,41 @@ void histogram_fprint(struct histogram *h, FILE *f)
 }
 
 
 }
 
 
+struct histogram_stats {
+       unsigned count;
+       unsigned long long sum;
+       unsigned avg;
+       unsigned percentile[100];
+};
+
+void histogram_stats(struct histogram *h, struct histogram_stats *s)
+{
+       unsigned long long sum;
+       unsigned i, j;
+
+       if (!s)
+               return;
+
+       memset(s, 0, sizeof(*s));
+
+       for (i = 0; i < h->allocated; i++) {
+               s->count += h->data[i];
+               s->sum += h->data[i] * i * h->resolution;
+       }
+       if (s->count == 0)
+               return;
+
+       s->avg = s->sum / s->count;
+
+       for (i = 0, j = 0, sum = 0; i < 100; i++) {
+               while (sum <= i * s->count / 100)
+                       sum += h->data[j++];
+
+               s->percentile[i] = (j-1) * h->resolution;
+       }
+       while (sum < i * s->count / 100)
+               sum += h->data[j++];
+       s->percentile[100] = (j-1) * h->resolution;
+}
 
 #endif
 
 #endif
index 8b1fb866c21fff7e0c0b1cbf10ba205dd99bd1fb..ff627dc18e461d3036273ac1b28779ed24155c5e 100644 (file)
@@ -865,6 +865,7 @@ int main(int argc, const char *argv[])
                fclose(opt.f_msgs);
 
        if (opt.f_stat) {
                fclose(opt.f_msgs);
 
        if (opt.f_stat) {
+               struct histogram_stats hs;
                fprintf(opt.f_stat, "cmdline='");
                for (i=0; i<argc; i++)
                        fprintf(opt.f_stat, "%s%s", argv[i], i < argc-1 ? " " : "");
                fprintf(opt.f_stat, "cmdline='");
                for (i=0; i<argc; i++)
                        fprintf(opt.f_stat, "%s%s", argv[i], i < argc-1 ? " " : "");
@@ -872,7 +873,7 @@ int main(int argc, const char *argv[])
 
                timespec_subtract(&diff, &stats.tac, &stats.tic);
                fprintf(opt.f_stat, "duration=%s # seconds\n", tstamp_str(NULL, &diff));
 
                timespec_subtract(&diff, &stats.tac, &stats.tic);
                fprintf(opt.f_stat, "duration=%s # seconds\n", tstamp_str(NULL, &diff));
-       
+
                fprintf(opt.f_stat, "sent=%d\n", count);
                fprintf(opt.f_stat, "overrun=%d\n", stats.overrun);
                if (stats.overrun && !opt.quiet)
                fprintf(opt.f_stat, "sent=%d\n", count);
                fprintf(opt.f_stat, "overrun=%d\n", stats.overrun);
                if (stats.overrun && !opt.quiet)
@@ -890,6 +891,12 @@ int main(int argc, const char *argv[])
                if (stats.timeouts && !opt.quiet)
                        printf("invalid_frame=%d\n", stats.timeouts);
 
                if (stats.timeouts && !opt.quiet)
                        printf("invalid_frame=%d\n", stats.timeouts);
 
+               histogram_stats(&histogram_gw, &hs);
+               double avg = hs.count ? (double)hs.sum/hs.count : 0;
+               fprintf(opt.f_stat, "avg=%g\n", avg);
+               for (i = 0; i <= 20; i++)
+                       fprintf(opt.f_stat, "percentile%d=%d\n", i*5, hs.percentile[i*5]);
+
                fclose(opt.f_stat);
        }
 
                fclose(opt.f_stat);
        }