Spread test files for mixedbench across multiple subdirectories.
[bluesky.git] / microbench / mixedbench.c
index 1093a96..07584e1 100644 (file)
@@ -10,6 +10,7 @@
  *   Benchmark duration (seconds)
  *   Target operations per second (aggregate across all threads)
  *   Interval count (how many times to report results during the run)
+ *   Directory size (number of files per numbered subdirectory)
  */
 
 #include <errno.h>
@@ -25,7 +26,7 @@
 #include <unistd.h>
 #include <math.h>
 
-int opt_filesize, opt_filecount, opt_threads, opt_duration, opt_intervals;
+int opt_filesize, opt_filecount, opt_threads, opt_duration, opt_intervals, opt_dirsize;
 double opt_writeratio, opt_ops;
 
 struct thread_state {
@@ -89,8 +90,10 @@ void benchmark_op(struct thread_state *ts)
 
     start = now_hires();
 
-    char filename[64];
-    sprintf(filename, "t%d/%d", ts->thread_num, get_random(opt_filecount));
+    char filename[256];
+    int n = get_random(opt_filecount);
+    int n1 = n / opt_dirsize, n2 = n % opt_dirsize;
+    sprintf(filename, "t%d/%d/%d", ts->thread_num, n1, n2);
 
     double r = get_random(1000000) / 1e6;
 
@@ -210,7 +213,7 @@ void reset_stats(int print, double duration)
 
 int main(int argc, char *argv[])
 {
-    if (argc != 8) {
+    if (argc != 9) {
         fprintf(stderr, "Usage: TODO\n");
         return 1;
     }
@@ -222,6 +225,7 @@ int main(int argc, char *argv[])
     opt_duration = atoi(argv[5]);
     opt_ops = atof(argv[6]);
     opt_intervals = atoi(argv[7]);
+    opt_dirsize = atoi(argv[7]);
 
     srandom(time(NULL));