9 static struct timeval tp1,tp2;
10 static size_t block_size = 64 * 1024;
11 static int show_latency;
12 static double min_latency, max_latency, total_time;
13 static unsigned num_blocks;
15 static void start_timer()
17 gettimeofday(&tp1,NULL);
20 static double end_timer()
22 gettimeofday(&tp2,NULL);
23 return((tp2.tv_sec - tp1.tv_sec) +
24 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
28 static void read_file(char *fname)
31 static double total, thisrun;
36 buf = malloc(block_size);
39 printf("Malloc of %d failed\n", block_size);
43 fd = open(fname, O_RDONLY);
51 last_time = end_timer();
54 while ((n = read(fd, buf, block_size)) > 0) {
58 double t = end_timer();
59 double latency = t - last_time;
60 if (latency > max_latency) {
61 max_latency = latency;
63 if (min_latency == 0 ||
64 latency < min_latency) {
65 min_latency = latency;
69 if (end_timer() >= 1.0) {
71 printf("%d MB %g MB/sec minlat=%.3f ms maxlat=%.3f ms\n",
73 (thisrun*1.0e-6)/end_timer(),
74 min_latency * 1000, max_latency * 1000);
76 printf("%d MB %g MB/sec\n",
78 (thisrun*1.0e-6)/end_timer());
84 min_latency = max_latency = 0;
93 static void usage(void)
96 "readfiles - reads from a list of files, showing read throughput\n" \
98 "Usage: readfiles [options] <files>\n" \
101 " -B size set the block size in bytes\n" \
102 " -L show latencies\n" \
106 int main(int argc, char *argv[])
113 while ((c = getopt(argc, argv, "B:hL")) != -1) {
116 block_size = strtol(optarg, NULL, 0);
139 for (i=0; i < argc; i++) {