]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - io/sendfile.c
Improve the statistics reporting for xfs_io.
[thirdparty/xfsprogs-dev.git] / io / sendfile.c
index f5d57b1a36769b2889d5bea1ea60e7928228a6d9..5607e8f088f97afaaee75a966c1bc144d1946c6f 100644 (file)
@@ -98,11 +98,15 @@ sendfile_f(
        struct timeval  t1, t2;
        char            s1[64], s2[64], ts[64];
        char            *infile = NULL;
+       int             Cflag;
        int             c, fd = -1;
 
+       Cflag = 0;
        init_cvtnum(&blocksize, &sectsize);
-       while ((c = getopt(argc, argv, "f:i:")) != EOF) {
+       while ((c = getopt(argc, argv, "Cf:i:")) != EOF) {
                switch (c) {
+               case 'C':
+                       Cflag = 1;
                case 'f':
                        fd = atoi(argv[1]);
                        if (fd < 0 || fd >= filecount) {
@@ -157,13 +161,20 @@ sendfile_f(
        gettimeofday(&t2, NULL);
        t2 = tsub(t2, t1);
 
-       printf(_("sent %lld/%lld bytes from offset %lld\n"),
-               total, count, (long long)offset);
-       cvtstr((double)total, s1, sizeof(s1));
-       cvtstr(tdiv((double)total, t2), s2, sizeof(s2));
-       timestr(&t2, ts, sizeof(ts));
-       printf(_("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n"),
-               s1, c, ts, s2, tdiv((double)c, t2));
+       /* 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));
+       }
 done:
        if (infile)
                close(fd);
@@ -177,7 +188,7 @@ sendfile_init(void)
        sendfile_cmd.altname = _("send");
        sendfile_cmd.cfunc = sendfile_f;
        sendfile_cmd.argmin = 2;
-       sendfile_cmd.argmax = 4;
+       sendfile_cmd.argmax = -1;
        sendfile_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
        sendfile_cmd.args =
                _("-i infile | -f N [off len]");