summaryrefslogtreecommitdiffstats
path: root/seqreader.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2012-03-23 03:39:12 +0100
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2012-03-23 03:39:12 +0100
commit842350fe2160f48fc67ca1449a30eab79e3f8c41 (patch)
treeb85da20117025cb21c2380508033bd88bdc9aac2 /seqreader.c
parent118175a1f2988081241eddb3a49ef505abedf79d (diff)
downloadfwbench-842350fe2160f48fc67ca1449a30eab79e3f8c41.tar.gz
fwbench-842350fe2160f48fc67ca1449a30eab79e3f8c41.tar.bz2
fwbench-842350fe2160f48fc67ca1449a30eab79e3f8c41.tar.xz
fwbench-842350fe2160f48fc67ca1449a30eab79e3f8c41.zip
seqreader
Diffstat (limited to 'seqreader.c')
-rw-r--r--seqreader.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/seqreader.c b/seqreader.c
new file mode 100644
index 0000000..c589684
--- /dev/null
+++ b/seqreader.c
@@ -0,0 +1,79 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <dirent.h>
+
+#define BUFSIZE 65536
+
+int main(int argc, char *argv[]) {
+ int err;
+ size_t SKIP = 1;
+ DIR *dir;
+ struct dirent *ent;
+ struct timeval start, tv;
+ size_t us;
+ size_t files = 0;
+ size_t total_size = 0;
+ size_t skip;
+ size_t run;
+ char buffer[65536];
+
+ if (argc < 2) {
+ printf("Usage: %s <directory> [skip]\n", argv[0]);
+ exit(0);
+ }
+
+ chdir(argv[1]);
+
+ if (argc > 2) {
+ SKIP = atoi(argv[2]);
+
+ printf("Skip %i\n", SKIP);
+ }
+
+ gettimeofday(&start, NULL);
+ for (run = 0; run < SKIP; run++) {
+ skip = 0;
+ dir = opendir(".");
+ while (ent = readdir(dir)) {
+ struct stat st;
+
+ if (((skip++)%SKIP) != run) continue;
+
+ if (stat(ent->d_name, &st)) continue;
+ if (!S_ISREG(st.st_mode)) continue;
+
+ FILE *f = fopen(ent->d_name, "r");
+ if (!f) continue;
+
+ int size = st.st_blksize;
+
+ if (size > BUFSIZE) {
+ printf("Buffer too small\n");
+ exit(1);
+ }
+
+ while (!feof(f)) {
+ err = fread(buffer, 1, size, f);
+ if (err < 0) {
+ printf("Read failed\n");
+ exit(1);
+ }
+ }
+
+ fclose(f);
+
+ total_size += st.st_size;
+ files++;
+
+ gettimeofday(&tv, NULL);
+ us = (tv.tv_sec - start.tv_sec) * 1000000 + (tv.tv_usec - start.tv_usec);
+ printf("Reading: %s (%lu MB), Read: %lu files (%lu GB), Measured speed: %lu mB/s\n", ent->d_name, st.st_size/1024/1024, files, total_size / 1024 / 1024 / 1024, total_size / us);
+ }
+ closedir(dir);
+ }
+
+} \ No newline at end of file