dd(1) human-readable output

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

dd(1) human-readable output

Thomas Pfaff-5
This patch makes dd(1) output change from e.g.

$ dd if=/dev/sd0c of=/dev/null bs=512 count=16000                        
16000+0 records in
16000+0 records out
8192000 bytes transferred in 3.002 secs (2728488 bytes/sec)

to

$ obj/dd if=/dev/sd0c of=/dev/null bs=512 count=16000
16000+0 records in
16000+0 records out
8192000 bytes (7.8MB) transferred in 3.009 seconds (2.6MB/s)

Any interest?

Index: Makefile
===================================================================
RCS file: /cvs/src/bin/dd/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- Makefile 29 May 1998 04:34:20 -0000 1.5
+++ Makefile 23 Aug 2011 18:43:43 -0000
@@ -2,5 +2,7 @@
 
 PROG= dd
 SRCS= args.c conv.c conv_tab.c dd.c misc.c position.c
+DPADD= ${LIBUTIL}
+LDADD= -lutil
 
 .include <bsd.prog.mk>
Index: misc.c
===================================================================
RCS file: /cvs/src/bin/dd/misc.c,v
retrieving revision 1.16
diff -u -p -r1.16 misc.c
--- misc.c 27 Oct 2009 23:59:21 -0000 1.16
+++ misc.c 23 Aug 2011 18:43:43 -0000
@@ -45,6 +45,7 @@
 #include <errno.h>
 #include <time.h>
 #include <unistd.h>
+#include <util.h>
 
 #include "dd.h"
 #include "extern.h"
@@ -57,6 +58,7 @@ summary(void)
  struct iovec iov[4];
  double microsecs;
  int i = 0;
+ char sizebuf[FMT_SCALED_STRSIZE], ratebuf[FMT_SCALED_STRSIZE];
 
  (void)gettimeofday(&nowtv, (struct timezone *)NULL);
  timersub(&nowtv, &st.startv, &nowtv);
@@ -85,10 +87,19 @@ summary(void)
  iov[i].iov_base = buf[2];
  iov[i++].iov_len = strlen(buf[2]);
  }
+
+ strlcpy(sizebuf, "?", sizeof sizebuf);
+ fmt_scaled(st.bytes, sizebuf);
+ sizebuf[strcspn(sizebuf, "B")] = '\0';
+
+ strlcpy(ratebuf, "?", sizeof ratebuf);
+ fmt_scaled(st.bytes * 1000000.0 / microsecs, ratebuf);
+ ratebuf[strcspn(ratebuf, "B")] = '\0';
+
  (void)snprintf(buf[3], sizeof(buf[3]),
-    "%qd bytes transferred in %ld.%03ld secs (%0.0f bytes/sec)\n",
-    (long long)st.bytes, nowtv.tv_sec, nowtv.tv_usec / 1000,
-    ((double)st.bytes * 1000000) / microsecs);
+    "%qd bytes (%sB) transferred in %ld.%03ld seconds (%sB/s)\n",
+    (long long)st.bytes, sizebuf, nowtv.tv_sec, nowtv.tv_usec / 1000,
+    ratebuf);
 
  iov[i].iov_base = buf[3];
  iov[i++].iov_len = strlen(buf[3]);

Reply | Threaded
Open this post in threaded view
|

Re: dd(1) human-readable output

Thordur Bjornsson-2
On 2011 Aug 23 (Tue) at 20:48:09 +0200 (+0200), Thomas Pfaff wrote:

> This patch makes dd(1) output change from e.g.
>
> $ dd if=/dev/sd0c of=/dev/null bs=512 count=16000                        
> 16000+0 records in
> 16000+0 records out
> 8192000 bytes transferred in 3.002 secs (2728488 bytes/sec)
>
> to
>
> $ obj/dd if=/dev/sd0c of=/dev/null bs=512 count=16000
> 16000+0 records in
> 16000+0 records out
> 8192000 bytes (7.8MB) transferred in 3.009 seconds (2.6MB/s)
>
> Any interest?
Yes. But with a caveat.

This is going to break atleast 3 scripts that get run periodically
on all of my development machines, while I'm happy with adjusting
them (this change would make them smaller actually) I'm unsure if
we want to throw this into the wild, since this output behaviour
is _old_.

Now, a -h button or similar would solve that, but thats fugly.

So, while I'm all for it, I think the greybeards need to weigh
in on this :)

So, assuming we are fine with breaking script compatability
(that I personally hate), the diff looks OK to me.


> Index: Makefile
> ===================================================================
> RCS file: /cvs/src/bin/dd/Makefile,v
> retrieving revision 1.5
> diff -u -p -r1.5 Makefile
> --- Makefile 29 May 1998 04:34:20 -0000 1.5
> +++ Makefile 23 Aug 2011 18:43:43 -0000
> @@ -2,5 +2,7 @@
>  
>  PROG= dd
>  SRCS= args.c conv.c conv_tab.c dd.c misc.c position.c
> +DPADD= ${LIBUTIL}
> +LDADD= -lutil
>  
>  .include <bsd.prog.mk>
> Index: misc.c
> ===================================================================
> RCS file: /cvs/src/bin/dd/misc.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 misc.c
> --- misc.c 27 Oct 2009 23:59:21 -0000 1.16
> +++ misc.c 23 Aug 2011 18:43:43 -0000
> @@ -45,6 +45,7 @@
>  #include <errno.h>
>  #include <time.h>
>  #include <unistd.h>
> +#include <util.h>
>  
>  #include "dd.h"
>  #include "extern.h"
> @@ -57,6 +58,7 @@ summary(void)
>   struct iovec iov[4];
>   double microsecs;
>   int i = 0;
> + char sizebuf[FMT_SCALED_STRSIZE], ratebuf[FMT_SCALED_STRSIZE];
>  
>   (void)gettimeofday(&nowtv, (struct timezone *)NULL);
>   timersub(&nowtv, &st.startv, &nowtv);
> @@ -85,10 +87,19 @@ summary(void)
>   iov[i].iov_base = buf[2];
>   iov[i++].iov_len = strlen(buf[2]);
>   }
> +
> + strlcpy(sizebuf, "?", sizeof sizebuf);
> + fmt_scaled(st.bytes, sizebuf);
> + sizebuf[strcspn(sizebuf, "B")] = '\0';
> +
> + strlcpy(ratebuf, "?", sizeof ratebuf);
> + fmt_scaled(st.bytes * 1000000.0 / microsecs, ratebuf);
> + ratebuf[strcspn(ratebuf, "B")] = '\0';
> +
>   (void)snprintf(buf[3], sizeof(buf[3]),
> -    "%qd bytes transferred in %ld.%03ld secs (%0.0f bytes/sec)\n",
> -    (long long)st.bytes, nowtv.tv_sec, nowtv.tv_usec / 1000,
> -    ((double)st.bytes * 1000000) / microsecs);
> +    "%qd bytes (%sB) transferred in %ld.%03ld seconds (%sB/s)\n",
> +    (long long)st.bytes, sizebuf, nowtv.tv_sec, nowtv.tv_usec / 1000,
> +    ratebuf);
>  
>   iov[i].iov_base = buf[3];
>   iov[i++].iov_len = strlen(buf[3]);

Reply | Threaded
Open this post in threaded view
|

Re: dd(1) human-readable output

Grumpy-3
> This is going to break atleast 3 scripts that get run periodically
> on all of my development machines, while I'm happy with adjusting
> them (this change would make them smaller actually) I'm unsure if
> we want to throw this into the wild, since this output behaviour
> is _old_.

That's the point, exactly. People (well, scripts written by people)
depend on the dd report output format.

> Now, a -h button or similar would solve that, but thats fugly.

Given dd is non-unixy in its commandline syntax, this would rather be a
``conv='' suboption. Or its own ``summary=human-readable'' option.
Definitely not a dash-prefixed option.

> So, while I'm all for it, I think the greybeards need to weigh
> in on this :)

It's not grey, you damn kid. It's ``exhausted tone''.

Grumpy

Reply | Threaded
Open this post in threaded view
|

Re: dd(1) human-readable output

Thomas Pfaff-5
On Tue, 23 Aug 2011 19:36:53 +0000
Grumpy <[hidden email]> wrote:
[...]

> > I'm unsure if we want to throw this into the wild, since this
> > output behaviour is _old_.
>
> That's the point, exactly. People (well, scripts written by people)
> depend on the dd report output format.
>
> > Now, a -h button or similar would solve that, but thats fugly.
>
> Given dd is non-unixy in its commandline syntax, this would rather
> be a ``conv='' suboption. Or its own ``summary=human-readable''
> option. Definitely not a dash-prefixed option.
>

Any interest in having something like summary=human-readable then?

I got what I wanted and I'm fine running a patched version on
my system, but if there is general interest in getting a human-
readable summary as an option, I might give it a shot.