diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2012-04-13 21:29:16 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2012-04-13 21:29:16 +0200 |
commit | fc7469226b63b92a6cd05ee83579186fb9cf8de5 (patch) | |
tree | e3e805730216b984236b2c2f4a79759e8c7123b1 | |
parent | 842350fe2160f48fc67ca1449a30eab79e3f8c41 (diff) | |
download | fwbench-fc7469226b63b92a6cd05ee83579186fb9cf8de5.tar.gz fwbench-fc7469226b63b92a6cd05ee83579186fb9cf8de5.tar.bz2 fwbench-fc7469226b63b92a6cd05ee83579186fb9cf8de5.tar.xz fwbench-fc7469226b63b92a6cd05ee83579186fb9cf8de5.zip |
Support RAW devices by seqreader
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rwxr-xr-x | fwbench.sh | 4 | ||||
-rw-r--r-- | seqreader.c | 49 |
3 files changed, 48 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a24d96..b1adb70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ include_directories( ) add_executable(fwbench fwbench.c) +add_executable(seqreader seqreader.c) if (USE_UFO_GENERATOR) target_link_libraries(fwbench m ufo fastwriter ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES}) @@ -3,8 +3,10 @@ function fwbench { if [ -f ../configure.sh -a -f fwbench ]; then ../configure.sh ./fwbench $* + elif [ -f fwbench ]; then + ./fwbench $* else - fwbench $* + `which fwbench` $* fi } diff --git a/seqreader.c b/seqreader.c index c589684..1a13cf9 100644 --- a/seqreader.c +++ b/seqreader.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE + #include <stdio.h> #include <stdlib.h> #include <sys/types.h> @@ -5,8 +7,14 @@ #include <sys/time.h> #include <unistd.h> #include <dirent.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +#define BUFSIZE 1048576//65536 +#define BLOCK_SIZE 16384//16384 +#define WRITE_INTERVAL 1 -#define BUFSIZE 65536 int main(int argc, char *argv[]) { int err; @@ -17,28 +25,59 @@ int main(int argc, char *argv[]) { size_t us; size_t files = 0; size_t total_size = 0; + size_t last_write = 0; size_t skip; size_t run; - char buffer[65536]; + char buffer[BUFSIZE]; if (argc < 2) { - printf("Usage: %s <directory> [skip]\n", argv[0]); + printf("Usage: %s <directory|device> [skip]\n", argv[0]); exit(0); } + if (!strstr(argv[0], "/dev/")) { + int fd = open(argv[1], O_RDONLY|O_NOATIME|O_LARGEFILE/*|O_DIRECT*/, 0); + if (fd < 0) { + printf("Unable to open device %s\n", argv[1]); + exit(1); + } + + int size = BLOCK_SIZE; + + gettimeofday(&start, NULL); + + err = read(fd, buffer, size); + while (err > 0) { + total_size += err; + + gettimeofday(&tv, NULL); + us = (tv.tv_sec - start.tv_sec) * 1000000 + (tv.tv_usec - start.tv_usec); + if ((us - last_write) > WRITE_INTERVAL * 1000000) { + last_write = us; + printf("Reading: %s (%lu GB), Measured speed: %lu mB/s\n", argv[0], total_size / 1024 / 1024 / 1024, total_size / us); + } + err = read(fd, buffer, size); + } + + close(fd); + + + return 0; + } + chdir(argv[1]); if (argc > 2) { SKIP = atoi(argv[2]); - printf("Skip %i\n", SKIP); + printf("Skip %zu\n", SKIP); } gettimeofday(&start, NULL); for (run = 0; run < SKIP; run++) { skip = 0; dir = opendir("."); - while (ent = readdir(dir)) { + while ((ent = readdir(dir))) { struct stat st; if (((skip++)%SKIP) != run) continue; |