Update synthetic RPC client to record timing.
[bluesky.git] / microbench / readbench.c
index 88eb888..043a2cf 100644 (file)
@@ -1,11 +1,13 @@
+#include <errno.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <time.h>
-#include <pthread.h>
+#include <unistd.h>
 
 struct thread_state {
     pthread_t thread;
@@ -55,12 +57,17 @@ void *benchmark_thread(void *arg)
     struct thread_state *ts = (struct thread_state *)arg;
 
     char namebuf[64];
-    sprintf(namebuf, "file-%d", ts->thread_num);
+    sprintf(namebuf, "file-%d", ts->thread_num + 1);
     printf("Opening %s\n", namebuf);
 
     int64_t start, end;
 
     start = now_hires();
+
+    struct stat stat_buf;
+    stat(namebuf, &stat_buf);
+
+#if 0
     FILE *f = fopen(namebuf, "rb");
     if (f == NULL) {
         perror("fopen");
@@ -69,11 +76,12 @@ void *benchmark_thread(void *arg)
 
     char buf[4096];
     fread(buf, 1, sizeof(buf), f);
+#endif
 
     end = now_hires();
     printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start);
 
-    fclose(f);
+    // fclose(f);
 
     return NULL;
 }
@@ -96,11 +104,20 @@ void wait_thread(int n)
 
 int main(int argc, char *argv[])
 {
-    for (int i = 0; i < 8; i++) {
+    int threads = 8;
+
+    if (argc > 1)
+        threads = atoi(argv[1]);
+    if (threads > MAX_THREADS)
+        threads = MAX_THREADS;
+
+    printf("Testing with %d threads\n", threads);
+
+    for (int i = 0; i < threads; i++) {
         launch_thread(i);
     }
 
-    for (int i = 0; i < 8; i++) {
+    for (int i = 0; i < threads; i++) {
         wait_thread(i);
     }