1. Change output to provide a single line pct done + avg/min/max.
2. Add "-l" flag to support previous style.
3. Add "-x n" flag to specify max loop iterations.
In a nutshell, output looks like this:
$ debug/test/bench -x 8192
done avg min max
17% 942 653 18997
-cl
--
Index: bench.c
===================================================================
--- bench.c (revision 433)
+++ bench.c (working copy)
@@ -55,7 +55,8 @@
static int count, writes, fired;
static int *pipes;
-static int num_pipes, num_active, num_writes;
+static int per_line;
+static int num_pipes, num_active, num_writes, num_iter;
static struct event *events;
@@ -106,7 +107,7 @@
} while (count != fired);
gettimeofday(&te, NULL);
- if (xcount != count) fprintf(stderr, "Xcount: %d, Rcount: %d\n",
xcount, count);
+ if (xcount != count && per_line) fprintf(stderr, "Xcount: %d, Rcount:
%d\n", xcount, count);
}
timersub(&te, &ts, &te);
@@ -122,11 +123,14 @@
struct timeval *tv;
int *cp;
extern char *optarg;
+ unsigned long t, min = 0x1 << 31, max = 0, avg = 0;
num_pipes = 100;
num_active = 1;
num_writes = num_pipes;
- while ((c = getopt(argc, argv, "n:a:w:")) != -1) {
+ num_iter = 25;
+
+ while ((c = getopt(argc, argv, "n:a:w:x:l")) != -1) {
switch (c) {
case 'n':
num_pipes = atoi(optarg);
@@ -137,6 +141,12 @@
case 'w':
num_writes = atoi(optarg);
break;
+ case 'x':
+ num_iter = atoi(optarg);
+ break;
+ case 'l':
+ per_line++;
+ break;
default:
fprintf(stderr, "Illegal argument \"%c\"\n", c);
exit(1);
@@ -169,13 +179,23 @@
}
}
- for (i = 0; i < 25; i++) {
+ fprintf(stdout, "%5s %12s %12s %12s\n", "done", "avg", "min", "max");
+ for (i = 1; i <= num_iter; i++) {
tv = run_once();
+ t = tv->tv_sec * 1000000L + tv->tv_usec;
if (tv == NULL)
exit(1);
- fprintf(stdout, "%ld\n",
- tv->tv_sec * 1000000L + tv->tv_usec);
+ if (per_line) {
+ fprintf(stdout, "%ld\n", t);
+ } else {
+ avg += t;
+ if (t < min) min = t;
+ else if (t > max) max = t;
+ fprintf(stdout, "\r%4d%% %12ld %12ld %12ld",
+ (100 * i) / num_iter, avg / i, min, max);
+ }
}
+ fprintf(stdout, "\n");
exit(0);
}
_______________________________________________
Libevent-users mailing list
[email protected]
http://monkey.org/mailman/listinfo/libevent-users