Allow interval at which benchmark results are printed to be controlled.
[bluesky.git] / microbench / mixedbench.c
index 81e63cf..1093a96 100644 (file)
@@ -9,6 +9,7 @@
  *   Threads
  *   Benchmark duration (seconds)
  *   Target operations per second (aggregate across all threads)
+ *   Interval count (how many times to report results during the run)
  */
 
 #include <errno.h>
@@ -24,7 +25,7 @@
 #include <unistd.h>
 #include <math.h>
 
-int opt_filesize, opt_filecount, opt_threads, opt_duration;
+int opt_filesize, opt_filecount, opt_threads, opt_duration, opt_intervals;
 double opt_writeratio, opt_ops;
 
 struct thread_state {
@@ -203,12 +204,13 @@ void reset_stats(int print, double duration)
                write_count / duration, write_time / write_count,
                stddev(write_time, write_time2, write_count));
         printf("\n");
+        fflush(stdout);
     }
 }
 
 int main(int argc, char *argv[])
 {
-    if (argc != 7) {
+    if (argc != 8) {
         fprintf(stderr, "Usage: TODO\n");
         return 1;
     }
@@ -219,6 +221,7 @@ int main(int argc, char *argv[])
     opt_threads = atoi(argv[4]);
     opt_duration = atoi(argv[5]);
     opt_ops = atof(argv[6]);
+    opt_intervals = atoi(argv[7]);
 
     srandom(time(NULL));
 
@@ -228,9 +231,9 @@ int main(int argc, char *argv[])
         launch_thread(i);
     }
 
-    for (int i = 0; i < 4; i++) {
-        sleep_micros(opt_duration * 1000000 / 4);
-        reset_stats(1, opt_duration / 4.0);
+    for (int i = 0; i < opt_intervals; i++) {
+        sleep_micros(opt_duration * 1000000 / opt_intervals);
+        reset_stats(1, (double)opt_duration / opt_intervals);
     }
 
     return 0;