+ unsigned long long total_bytes = 0;
+ struct statfs64 statbuf;
+
+ if (full) {
+ if (statfs64(testdir, &statbuf) == 0) {
+ if (strcmp(op, "write") == 0)
+ total_bytes = (unsigned long long)
+ (statbuf.f_bavail * statbuf.f_bsize);
+ else if (strcmp(op, "read") == 0)
+ total_bytes = (unsigned long long)
+ (statbuf.f_blocks * statbuf.f_bsize);
+ else {
+ fprintf(stderr, "\n%s: invalid operation: %s\n",
+ progname, op);
+ return -1;
+ }
+ } else {
+ fprintf(stderr, "\n%s: unable to stat %s: %s\n",
+ progname, testdir, strerror(errno));
+ return -errno;
+ }
+ } else {
+ total_bytes = num_dirs * files_in_dir * file_size;
+ }
+
+ return total_bytes;
+}
+
+/*
+ * show_rate: displays the current read/write file name and performance,
+ * along with an estimate of how long the whole read/write operation
+ * will continue.
+ */
+void show_rate(char *op, char *filename, const struct timeval *start_time,
+ const unsigned long long total_bytes,
+ const unsigned long long curr_bytes)
+{
+ static struct timeval last_time;
+ static unsigned long long last_bytes;
+ static char last_op;
+ struct timeval curr_time;
+ double curr_delta, overall_delta, curr_rate, overall_rate;
+ double total_time, remain_time;
+ int remain_hours, remain_minutes, remain_seconds;
+
+ if (last_time.tv_sec == 0)
+ last_time = *start_time;
+
+ if (last_op != op[0]) {
+ last_bytes = 0;
+ last_time = *start_time;
+ last_op = op[0];
+ }
+
+ gettimeofday(&curr_time, NULL);
+
+ curr_delta = (curr_time.tv_sec - last_time.tv_sec) +
+ (double)(curr_time.tv_usec - last_time.tv_usec) / 1000000;
+
+ overall_delta = (curr_time.tv_sec - start_time->tv_sec) +
+ (double)(curr_time.tv_usec - start_time->tv_usec) / 1000000;
+
+ curr_rate = (curr_bytes - last_bytes) / curr_delta;
+ overall_rate = curr_bytes / overall_delta;