tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

humanize_number(3) for dd(1) summary?



As there is some discussion regarding command line/usage to make user's
life better (or worse?), is there opposition to use humanize_number(3)
in dd(1) summary()?

$ dd if=/dev/zero of=/tmp/foobar bs=1g count=1
1+0 records in
1+0 records out
1073741824 bytes transferred in 15.678 secs (68487168 bytes/sec)

$ ./dd if=/dev/zero of=/tmp/foobar bs=1g count=1
1+0 records in
1+0 records out
1073741824 bytes (1,0 GB) transferred in 15.701 secs (65 MB/sec)


Index: misc.c
===================================================================
RCS file: /cvsroot/src/bin/dd/misc.c,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 misc.c
--- misc.c      5 Oct 2007 07:23:09 -0000       1.21
+++ misc.c      3 Dec 2010 21:37:31 -0000
@@ -62,7 +62,7 @@ __RCSID("$NetBSD: misc.c,v 1.21 2007/10/
 void
 summary(void)
 {
-       char buf[100];
+       char buf[100], buf2[7], buf3[7];
        int64_t mS;
        struct timeval tv;

@@ -97,12 +97,23 @@ summary(void)
                    (st.sparse == 1) ? "block" : "blocks");
                (void)write(STDERR_FILENO, buf, strlen(buf));
        }
+
+       /* total bytes transferred */
+       if (humanize_number(buf2, sizeof(buf2), st.bytes, "B",
+           HN_AUTOSCALE, HN_DECIMAL) == -1)
+               warnx("humanize_number (bytes transferred)");
+       /* bytes per second */
+       if (humanize_number(buf3, sizeof(buf3), st.bytes * 1000LL / mS, "B",
+           HN_AUTOSCALE, HN_DECIMAL) == -1)
+               warnx("humanize_number (bytes per second)");
+
        (void)snprintf(buf, sizeof(buf),
-           "%llu bytes transferred in %lu.%03d secs (%llu bytes/sec)\n",
+           "%llu bytes (%s) transferred in %lu.%03d secs (%s/sec)\n",
            (unsigned long long) st.bytes,
+           buf2,
            (long) (mS / 1000),
            (int) (mS % 1000),
-           (unsigned long long) (st.bytes * 1000LL / mS));
+           buf3);
        (void)write(STDERR_FILENO, buf, strlen(buf));
 }

-- 
Jean-Yves Migeon
jeanyves.migeon%free.fr@localhost


Home | Main Index | Thread Index | Old Index