summaryrefslogtreecommitdiffstats
path: root/seqreader.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2012-04-15 16:32:49 +0200
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2012-04-15 16:32:49 +0200
commit28673c9220debee363a21cc7ecbcb87e2eaa49da (patch)
treed7222715e37d0696ec62e7aac40c3cc1c40df7f3 /seqreader.c
parent133aa259230f293e59b8b013f9fd2ac8b1c03b05 (diff)
downloadfwbench-28673c9220debee363a21cc7ecbcb87e2eaa49da.tar.gz
fwbench-28673c9220debee363a21cc7ecbcb87e2eaa49da.tar.bz2
fwbench-28673c9220debee363a21cc7ecbcb87e2eaa49da.tar.xz
fwbench-28673c9220debee363a21cc7ecbcb87e2eaa49da.zip
fsbench
Diffstat (limited to 'seqreader.c')
-rw-r--r--seqreader.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/seqreader.c b/seqreader.c
index f2128e2..359f38e 100644
--- a/seqreader.c
+++ b/seqreader.c
@@ -13,8 +13,13 @@
#define FASTWRITER_SYNCIO_ALIGN 512
+#define SYNC_MODE
#define BUFSIZE 2097152
-#define BLOCK_SIZE 2097152
+#ifdef SYNC_MODE
+# define BLOCK_SIZE 2097152
+#else /* SYNC_MODE */
+# define BLOCK_SIZE 16384
+#endif /* SYNC_MODE */
#define WRITE_INTERVAL 1
@@ -31,18 +36,29 @@ int main(int argc, char *argv[]) {
size_t skip;
size_t run;
ssize_t res;
+ size_t max_size = (size_t)-1;
char *buffer;//[BUFSIZE];
long double mcoef = 1000000. / (1024 * 1024);
+ int flags = O_RDONLY|O_NOATIME|O_LARGEFILE;
+
+#ifdef SYNC_MODE
+ flags |= O_DIRECT;
+#endif
posix_memalign((void**)&buffer, FASTWRITER_SYNCIO_ALIGN, BUFSIZE);
if (argc < 2) {
- printf("Usage: %s <directory|device> [skip]\n", argv[0]);
+ printf("Usage: %s <directory|device> [skip|size]\n", argv[0]);
exit(0);
}
if (strstr(argv[1], "/dev/")) {
- int fd = open(argv[1], O_RDONLY|O_NOATIME|O_LARGEFILE|O_DIRECT, 0);
+ if (argc > 2) {
+ max_size = atol(argv[2]);
+ max_size *= 1024 * 1024 * 1024;
+ }
+
+ int fd = open(argv[1], flags, 0);
if (fd < 0) {
printf("Unable to open device %s\n", argv[1]);
exit(1);
@@ -66,6 +82,12 @@ int main(int argc, char *argv[]) {
last_write = us;
printf("Reading: %s (%lu GB), Measured speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us));
}
+
+ if (total_size > max_size) {
+ printf("Reading: %s (%lu GB), Measured speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us));
+ break;
+ }
+
res = read(fd, buffer, size);
}
@@ -100,9 +122,14 @@ int main(int argc, char *argv[]) {
if (stat(ent->d_name, &st)) continue;
if (!S_ISREG(st.st_mode)) continue;
-
+
+#ifdef F_MODE
FILE *f = fopen(ent->d_name, "r");
if (!f) continue;
+#else
+ int fd = open(ent->d_name, flags, 0);
+ if (fd < 0) continue;
+#endif
int size = st.st_blksize;
@@ -110,16 +137,33 @@ int main(int argc, char *argv[]) {
printf("Buffer too small\n");
exit(1);
}
-
+
+
+#ifdef F_MODE
while (!feof(f)) {
err = fread(buffer, 1, size, f);
- if (err < 0) {
- printf("Read failed\n");
- exit(1);
- }
+ if (err < 0) break;
}
-
+#else
+# ifdef SYNC_MODE
+ if (size < BLOCK_SIZE) size = BLOCK_SIZE;
+# endif
+ err = read(fd, buffer, size);
+ while (err > 0) {
+ err = read(fd, buffer, size);
+ }
+#endif
+
+ if (err < 0) {
+ printf("Read failed\n");
+ exit(1);
+ }
+
+#ifdef F_MODE
fclose(f);
+#else
+ close(fd);
+#endif
total_size += st.st_size;
files++;