Whamcloud - gitweb
Add a statmany.c file to complement createmany.c
authorpschwan <pschwan>
Tue, 24 Dec 2002 23:15:49 +0000 (23:15 +0000)
committerpschwan <pschwan>
Tue, 24 Dec 2002 23:15:49 +0000 (23:15 +0000)
Some day I'll clean up this directory, I swear it.

lustre/tests/statmany.c [new file with mode: 0644]

diff --git a/lustre/tests/statmany.c b/lustre/tests/statmany.c
new file mode 100644 (file)
index 0000000..a291ebf
--- /dev/null
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <time.h>
+
+int main(int argc, char ** argv)
+{
+        int i, count, iter;
+        long int start, last, rc = 0;
+
+        if (argc != 4) {
+                printf("Usage %s filenamebase file_count iterations\n",
+                       argv[0]);
+                exit(1);
+        }
+
+        if (strlen(argv[1]) > 4080) {
+                printf("name too long\n");
+                exit(1);
+        }
+
+        count = strtoul(argv[2], NULL, 0);
+        iter = strtoul(argv[3], NULL, 0);
+
+        start = last = time(0);
+
+        for (i = 0; i < iter; i++) {
+                struct stat buf;
+                char filename[4096];
+                int tmp;
+
+                tmp = random() % count;
+                sprintf(filename, "%s-%d", argv[1], tmp);
+
+                rc = stat(filename, &buf);
+                if (rc) {
+                        printf("stat(%s) error: %s\n", filename,
+                               strerror(errno));
+                        break;
+                }
+
+               if ((i % 10000) == 0) {
+                        printf(" - stat %d (time %ld ; total %ld ; last %ld)\n",
+                               i, time(0), time(0) - start, time(0) - last);
+                        last = time(0);
+                }
+        }
+
+        printf("total: %d stats in %ld seconds: %f stats/second\n", i,
+               time(0) - start, ((float)i / (time(0) - start)));
+
+        exit(rc);
+}