13
0

few more read-test tweaks:

* add a file-limit option
* print max elapsed read time
This commit is contained in:
Robin Gareus 2015-01-20 18:29:35 +01:00
parent dfba00766c
commit 4b470902c2

View File

@ -1,4 +1,4 @@
/* gcc -o readtest readtest.cc `pkg-config --cflags --libs glib-2.0` */ /* gcc -o readtest readtest.c `pkg-config --cflags --libs glib-2.0` */
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
@ -23,21 +23,23 @@ read_one (int fd, ssize_t sz)
void void
usage () usage ()
{ {
fprintf (stderr, "readtest [ -b BLOCKSIZE ] [ -s ] [ -D ] filename-template\n"); fprintf (stderr, "readtest [ -b BLOCKSIZE ] [-l FILELIMIT] [ -D ] filename-template\n");
} }
int int
main (int argc, char* argv[]) main (int argc, char* argv[])
{ {
int* files; int* files;
char optstring[] = "b:D"; char optstring[] = "b:Dl:";
uint32_t block_size = 64 * 1024 * 4; uint32_t block_size = 64 * 1024 * 4;
int max_files = -1;
#ifdef __APPLE__ #ifdef __APPLE__
bool direct = false; bool direct = false;
#endif #endif
const struct option longopts[] = { const struct option longopts[] = {
{ "blocksize", 1, 0, 'b' }, { "blocksize", 1, 0, 'b' },
{ "direct", 0, 0, 'D' }, { "direct", 0, 0, 'D' },
{ "limit", 1, 0, 'l' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
@ -57,6 +59,9 @@ main (int argc, char* argv[])
case 'b': case 'b':
block_size = atoi (optarg); block_size = atoi (optarg);
break; break;
case 'l':
max_files = atoi (optarg);
break;
case 'D': case 'D':
#ifdef __APPLE__ #ifdef __APPLE__
direct = true; direct = true;
@ -85,6 +90,10 @@ main (int argc, char* argv[])
} }
++n; ++n;
if (max_files > 0 && n >= max_files) {
break;
}
} }
if (n == 0) { if (n == 0) {
@ -126,7 +135,7 @@ main (int argc, char* argv[])
data = (char*) malloc (sizeof (char) * block_size); data = (char*) malloc (sizeof (char) * block_size);
uint64_t _read = 0; uint64_t _read = 0;
double min_throughput = -1; double max_elapsed = 0;
double total_time = 0; double total_time = 0;
while (true) { while (true) {
@ -145,19 +154,21 @@ main (int argc, char* argv[])
gint64 elapsed = g_get_monotonic_time() - before; gint64 elapsed = g_get_monotonic_time() - before;
double bandwidth = ((nfiles * block_size)/1048576.0) / (elapsed/1000000.0); double bandwidth = ((nfiles * block_size)/1048576.0) / (elapsed/1000000.0);
printf ("BW @ %Lu %.3f seconds bandwidth %.4f MB/sec\n", _read, elapsed/1000000.0, bandwidth); printf ("BW @ %lu %.3f seconds bandwidth %.4f MB/sec\n", (long unsigned int)_read, elapsed/1000000.0, bandwidth);
total_time += elapsed; total_time += elapsed;
if (min_throughput > bandwidth || min_throughput < 0) {
min_throughput = bandwidth; if (elapsed > max_elapsed) {
max_elapsed = elapsed;
} }
} }
out: out:
if (min_throughput > 0 && total_time > 0) { if (max_elapsed > 0 && total_time > 0) {
double bandwidth = ((nfiles * _read)/1048576.0) / (total_time/1000000.0); double bandwidth = ((nfiles * _read)/1048576.0) / (total_time/1000000.0);
printf ("Min: %.4f MB/sec Avg: %.4f MB/sec\n", min_throughput, bandwidth); double min_throughput = ((nfiles * block_size)/1048576.0) / (max_elapsed/1000000.0);
printf ("Min: %.4f MB/sec Avg: %.4f MB/sec || Max: %.3f sec \n", min_throughput, bandwidth, max_elapsed/1000000.0);
} }
return 0; return 0;