]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxcmd: provide a common function to report command runtimes
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 28 Oct 2015 04:48:22 +0000 (15:48 +1100)
committerDave Chinner <david@fromorbit.com>
Wed, 28 Oct 2015 04:48:22 +0000 (15:48 +1100)
Refactor the open-coded runtime stats reporting into a library
command, then update xfs_io commands to use it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
include/command.h
io/pread.c
io/pwrite.c
io/sendfile.c
libxcmd/command.c

index 4869edf64d068abf1ba68f9deda752822d4f22bc..7b9fc284116c67895a4d0e24daf505bb4800600d 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef __COMMAND_H__
 #define __COMMAND_H__
 
+#include <sys/time.h>
+
 #define CMD_FLAG_GLOBAL        ((int)0x80000000)       /* don't iterate "args" */
 
 typedef int (*cfunc_t)(int argc, char **argv);
@@ -56,4 +58,8 @@ extern void           command_loop(void);
 extern int             command_usage(const cmdinfo_t *ci);
 extern int             command(const cmdinfo_t *ci, int argc, char **argv);
 
+extern void            report_io_times(const char *verb, struct timeval *t2,
+                                       long long offset, long long count,
+                                       long long total, int ops, int compact);
+
 #endif /* __COMMAND_H__ */
index 1c77c41349b0928069d537f59f68c4a19aa5c39c..f16c86c1a76dcd4dd4d35dc1f536d98381ac3f35 100644 (file)
@@ -379,7 +379,6 @@ pread_f(
        long long       count, total, tmp;
        size_t          fsblocksize, fssectsize;
        struct timeval  t1, t2;
-       char            s1[64], s2[64], ts[64];
        char            *sp;
        int             Cflag, qflag, uflag, vflag;
        int             eof = 0, direction = IO_FORWARD;
@@ -488,20 +487,7 @@ pread_f(
        gettimeofday(&t2, NULL);
        t2 = tsub(t2, t1);
 
-       /* Finally, report back -- -C gives a parsable format */
-       timestr(&t2, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0);
-       if (!Cflag) {
-               cvtstr((double)total, s1, sizeof(s1));
-               cvtstr(tdiv((double)total, t2), s2, sizeof(s2));
-               printf(_("read %lld/%lld bytes at offset %lld\n"),
-                       total, count, (long long)offset);
-               printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"),
-                       s1, c, ts, s2, tdiv((double)c, t2));
-       } else {/* bytes,ops,time,bytes/sec,ops/sec */
-               printf("%lld,%d,%s,%.3f,%.3f\n",
-                       total, c, ts,
-                       tdiv((double)total, t2), tdiv((double)c, t2));
-       }
+       report_io_times("read", &t2, (long long)offset, count, total, c, Cflag);
        return 0;
 }
 
index 10f78e42aeb14e475482d1230f56fcaec6bc673f..fd9114d1eb6bdf2ae3db1591aea2c0aebbc1223c 100644 (file)
@@ -250,7 +250,6 @@ pwrite_f(
        unsigned int    zeed = 0, seed = 0xcdcdcdcd;
        size_t          fsblocksize, fssectsize;
        struct timeval  t1, t2;
-       char            s1[64], s2[64], ts[64];
        char            *sp, *infile = NULL;
        int             Cflag, qflag, uflag, dflag, wflag, Wflag;
        int             direction = IO_FORWARD;
@@ -385,20 +384,8 @@ pwrite_f(
        gettimeofday(&t2, NULL);
        t2 = tsub(t2, t1);
 
-       /* Finally, report back -- -C gives a parsable format */
-       timestr(&t2, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0);
-       if (!Cflag) {
-               cvtstr((double)total, s1, sizeof(s1));
-               cvtstr(tdiv((double)total, t2), s2, sizeof(s2));
-               printf(_("wrote %lld/%lld bytes at offset %lld\n"),
-                       total, count, (long long)offset);
-               printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"),
-                       s1, c, ts, s2, tdiv((double)c, t2));
-       } else {/* bytes,ops,time,bytes/sec,ops/sec */
-               printf("%lld,%d,%s,%.3f,%.3f\n",
-                       total, c, ts,
-                       tdiv((double)total, t2), tdiv((double)c, t2));
-       }
+       report_io_times("wrote", &t2, (long long)offset, count, total, c,
+                       Cflag);
 done:
        if (infile)
                close(fd);
index 5c1638ff8e403bb49d160ab373ee58e6613e810d..21ab444a45c1e84c57961cf632fd7a190a021bb5 100644 (file)
@@ -81,7 +81,6 @@ sendfile_f(
        long long       count, total;
        size_t          blocksize, sectsize;
        struct timeval  t1, t2;
-       char            s1[64], s2[64], ts[64];
        char            *infile = NULL;
        int             Cflag, qflag;
        int             c, fd = -1;
@@ -152,20 +151,7 @@ sendfile_f(
        gettimeofday(&t2, NULL);
        t2 = tsub(t2, t1);
 
-       /* Finally, report back -- -C gives a parsable format */
-       timestr(&t2, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0);
-       if (!Cflag) {
-               cvtstr((double)total, s1, sizeof(s1));
-               cvtstr(tdiv((double)total, t2), s2, sizeof(s2));
-               printf(_("sent %lld/%lld bytes from offset %lld\n"),
-                       total, count, (long long)offset);
-               printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"),
-                       s1, c, ts, s2, tdiv((double)c, t2));
-       } else {/* bytes,ops,time,bytes/sec,ops/sec */
-               printf("%lld,%d,%s,%.3f,%.3f\n",
-                       total, c, ts,
-                       tdiv((double)total, t2), tdiv((double)c, t2));
-       }
+       report_io_times("sent", &t2, (long long)offset, count, total, c, Cflag);
 done:
        if (infile)
                close(fd);
index 42a77e997927708a1ac2c034e647e5b3080ab3d7..dd0034cc6d832ae5eb9ae6d68f9647b06fada3d9 100644 (file)
@@ -192,3 +192,30 @@ command_loop(void)
                doneline(input, v);
        }
 }
+
+void
+report_io_times(
+       const char              *verb,
+       struct timeval          *t2,
+       long long               offset,
+       long long               count,
+       long long               total,
+       int                     ops,
+       int                     compact)
+{
+       char                    s1[64], s2[64], ts[64];
+
+       timestr(t2, ts, sizeof(ts), compact ? VERBOSE_FIXED_TIME : 0);
+       if (!compact) {
+               cvtstr((double)total, s1, sizeof(s1));
+               cvtstr(tdiv((double)total, *t2), s2, sizeof(s2));
+               printf(_("%s %lld/%lld bytes at offset %lld\n"),
+                       verb, total, count, (long long)offset);
+               printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"),
+                       s1, ops, ts, s2, tdiv((double)ops, *t2));
+       } else {/* bytes,ops,time,bytes/sec,ops/sec */
+               printf("%lld,%d,%s,%.3f,%.3f\n",
+                       total, ops, ts,
+                       tdiv((double)total, *t2), tdiv((double)ops, *t2));
+       }
+}