Module: xenomai-forge
Branch: master
Commit: 4bcaa1e9655a0abf17dde7fe11b1d3b31349885c
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=4bcaa1e9655a0abf17dde7fe11b1d3b31349885c

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat May 12 13:37:27 2012 +0200

testsuite: add latency options and gnuplot script to generate histograms

---

 scripts/Makefile.am         |    3 +-
 scripts/Makefile.in         |    3 +-
 scripts/histo.gp            |   21 +++++++++++++++++
 testsuite/latency/latency.c |   51 +++++++++++++++++++++++++++++++++++++------
 4 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 98d1998..2e0c0dd 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -12,4 +12,5 @@ EXTRA_DIST = \
        prepare-patch.sh \
        wrap-link.sh \
        Kconfig.frag \
-       $(wildcard postinstall.sh)
+       $(wildcard postinstall.sh) \
+       histo.gp
diff --git a/scripts/Makefile.in b/scripts/Makefile.in
index 3bdd1fd..766aef7 100644
--- a/scripts/Makefile.in
+++ b/scripts/Makefile.in
@@ -245,7 +245,8 @@ EXTRA_DIST = \
        prepare-patch.sh \
        wrap-link.sh \
        Kconfig.frag \
-       $(wildcard postinstall.sh)
+       $(wildcard postinstall.sh) \
+       histo.gp
 
 all: all-am
 
diff --git a/scripts/histo.gp b/scripts/histo.gp
new file mode 100644
index 0000000..64a627a
--- /dev/null
+++ b/scripts/histo.gp
@@ -0,0 +1,21 @@
+#
+# Run this gnuplot script with the command line:
+#
+# gnuplot -e 
'input_file="/path/to/input";output_file="/path/to/output.png";graph_title="title
 text"' /path/to/histo.gp
+#
+# where the input file is generated using latency option "-g"
+#
+
+set terminal png size 1024,768
+set output output_file
+
+set title graph_title
+set xlabel "user-space latency in microseconds"
+set ylabel "occurences + 1 (log)"
+set logscale y
+set key off;
+
+set bar 1.000000
+set style fill  solid 1.00 border -1
+set style rectangle back fc lt -3 fillstyle  solid 1.00 border -1
+plot input_file w line
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index c12cb5f..4766488 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -56,13 +56,16 @@ int test_loops = 0;         /* outer loop count */
 
 /* Warmup time : in order to avoid spurious cache effects on low-end machines. 
*/
 #define WARMUP_TIME 1
-#define HISTOGRAM_CELLS 100
+#define HISTOGRAM_CELLS 300
 int histogram_size = HISTOGRAM_CELLS;
 long *histogram_avg = NULL, *histogram_max = NULL, *histogram_min = NULL;
 
+char *do_gnuplot = NULL;
 int do_histogram = 0, do_stats = 0, finished = 0;
 int bucketsize = 1000;         /* default = 1000ns, -B <size> to override */
 
+#define need_histo() (do_histogram || do_stats || do_gnuplot)
+
 static inline void add_histogram(long *histogram, long addval)
 {
        /* bucketsize steps */
@@ -145,12 +148,12 @@ void latency(void *cookie)
                                gmaxjitter = dt;
                        }
 
-                       if (!(finished || warmup) && (do_histogram || do_stats))
+                       if (!(finished || warmup) && need_histo())
                                add_histogram(histogram_avg, dt);
                }
 
                if (!warmup) {
-                       if (!finished && (do_histogram || do_stats)) {
+                       if (!finished && need_histo()) {
                                add_histogram(histogram_max, maxj);
                                add_histogram(histogram_min, minj);
                        }
@@ -204,8 +207,7 @@ void display(void *cookie)
                config.period = period_ns;
                config.priority = priority;
                config.warmup_loops = WARMUP_TIME;
-               config.histogram_size = (do_histogram
-                                        || do_stats) ? histogram_size : 0;
+               config.histogram_size = need_histo() ? histogram_size : 0;
                config.histogram_bucketsize = bucketsize;
                config.freeze_max = freeze_max;
 
@@ -327,6 +329,33 @@ double dump_histogram(long *histogram, char *kind)
        return avg;
 }
 
+void dump_histo_gnuplot(long *histogram)
+{
+       unsigned start, stop;
+       FILE *f;
+       int n;
+
+       f = fopen(do_gnuplot, "w");
+       if (!f)
+               return;
+
+       for (n = 0; n < histogram_size && histogram[n] == 0L; n++)
+               ;
+       start = n;
+
+       for (n = histogram_size - 1; n >= 0 && histogram[n] == 0L; n--)
+               ;
+       stop = n;
+
+       fprintf(f, "%g 1\n", start * bucketsize / 1000.0);
+       for (n = start; n <= stop; n++)
+               fprintf(f, "%g %ld\n",
+                       (n + 0.5) * bucketsize / 1000.0, histogram[n] + 1);
+       fprintf(f, "%g 1\n", (stop + 1) * bucketsize / 1000.0);
+
+       fclose(f);
+}
+
 void dump_stats(long *histogram, char *kind, double avg)
 {
        int n, total_hits = 0;
@@ -366,6 +395,9 @@ void dump_hist_stats(void)
        dump_stats(histogram_min, "min", minavg);
        dump_stats(histogram_avg, "avg", avgavg);
        dump_stats(histogram_max, "max", maxavg);
+
+       if (do_gnuplot)
+               dump_histo_gnuplot(histogram_avg);
 }
 
 void cleanup(void)
@@ -399,7 +431,7 @@ void cleanup(void)
        if (benchdev >= 0)
                rt_dev_close(benchdev);
 
-       if (do_histogram || do_stats)
+       if (need_histo())
                dump_hist_stats();
 
        time(&test_end);
@@ -460,8 +492,12 @@ int main(int argc, char *const *argv)
 
        copperplate_init(&argc, &argv);
 
-       while ((c = getopt(argc, argv, "hp:l:T:qH:B:sD:t:fc:P:b")) != EOF)
+       while ((c = getopt(argc, argv, "g:hp:l:T:qH:B:sD:t:fc:P:b")) != EOF)
                switch (c) {
+               case 'g':
+                       do_gnuplot = strdup(optarg);
+                       break;
+
                case 'h':
 
                        do_histogram = 1;
@@ -535,6 +571,7 @@ int main(int argc, char *const *argv)
                        fprintf(stderr,
 "usage: latency [options]\n"
 "  [-h]                         # print histograms of min, avg, max 
latencies\n"
+"  [-g <file>]                  # dump histogram to <file> in gnuplot format\n"
 "  [-s]                         # print statistics of min, avg, max 
latencies\n"
 "  [-H <histogram-size>]        # default = 200, increase if your last bucket 
is full\n"
 "  [-B <bucket-size>]           # default = 1000ns, decrease for more 
resolution\n"


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to