added latency
authorAndrew Tridgell <tridge@samba.org>
Thu, 13 Dec 2007 10:01:35 +0000 (21:01 +1100)
committerAndrew Tridgell <tridge@samba.org>
Thu, 13 Dec 2007 10:01:35 +0000 (21:01 +1100)
readfiles.c

index 46025d7..0f0389f 100644 (file)
@@ -8,6 +8,9 @@
 
 static struct timeval tp1,tp2;
 static size_t block_size = 64 * 1024;
+static int show_latency;
+static double min_latency, max_latency, total_time;
+static unsigned num_blocks;
 
 static void start_timer()
 {
@@ -28,6 +31,7 @@ static void read_file(char *fname)
        static double total, thisrun;
        int n;
        char *buf;
+       double last_time;
 
        buf = malloc(block_size);
 
@@ -43,15 +47,41 @@ static void read_file(char *fname)
                return;
        }
 
+       if (show_latency) {
+               last_time = end_timer();
+       }
+
        while ((n = read(fd, buf, block_size)) > 0) {
                total += n;
                thisrun += n;
+               if (show_latency) {
+                       double t = end_timer();
+                       double latency = t - last_time;
+                       if (latency > max_latency) {
+                               max_latency = latency;
+                       }
+                       if (min_latency == 0 ||
+                           latency < min_latency) {
+                               min_latency = latency;
+                       }
+                       last_time = t;
+               }
                if (end_timer() >= 1.0) {
-                       printf("%d MB    %g MB/sec\n", 
-                              (int)(total/1.0e6),
-                              (thisrun*1.0e-6)/end_timer());
+                       if (show_latency) {
+                               printf("%d MB    %g MB/sec  minlat=%.3f ms  maxlat=%.3f ms\n", 
+                                      (int)(total/1.0e6),
+                                      (thisrun*1.0e-6)/end_timer(),
+                                      min_latency * 1000, max_latency * 1000);
+                       } else {
+                               printf("%d MB    %g MB/sec\n", 
+                                      (int)(total/1.0e6),
+                                      (thisrun*1.0e-6)/end_timer());
+                       }
+
                        start_timer();
+                       last_time = 0;
                        thisrun = 0;
+                       min_latency = max_latency = 0;
                }
        }
 
@@ -69,6 +99,7 @@ static void usage(void)
 "\n" \
 "Options:\n" \
 "    -B size        set the block size in bytes\n" \
+"    -L             show latencies\n" \
 "");
 }
 
@@ -79,11 +110,14 @@ int main(int argc, char *argv[])
        extern int optind;
        int c;
 
-       while ((c = getopt(argc, argv, "B:h")) != -1) {
+       while ((c = getopt(argc, argv, "B:hL")) != -1) {
                switch (c) {
                case 'B':
                        block_size = strtol(optarg, NULL, 0);
                        break;
+               case 'L':
+                       show_latency = 1;
+                       break;
                case 'h':
                default:
                        usage();