dd patch for coreutils-like third status line

Denys Vlasenko vda.linux at googlemail.com
Tue Oct 13 22:30:43 UTC 2009


On Monday 12 October 2009 01:36, Gabor Heja wrote:
> 
> Hi all,
> 
> I have attached a patch that adds a third status line with transferred
> bytes, transferred amount of data in human readable format, elapsed seconds
> and speed of transfer for the output of the dd applet, like the one in the
> Debian's coreutils package. Actually its behaviour differs from the
> coreutils' one: it does not change the unit dynamically, instead it always
> uses megabytes for human readable format and speed.
> 
> The patch fixes a possible typo in the dd's part of Config.in: the help
> shows the status lines as one, however the real applet displays the in and
> out blocks in separate lines.
> 
> If anything should be modified in the patch, or I made something wrong,
> please let me know.

+#ifdef ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+       long long unsigned now = monotonic_us();
+#endif

Should be #if ENABLE_xxx, not #ifdef. ENABLE_FEATURE_DD_THIRD_STATUS_LINE
is always defined, to 0 or 1.


        else if (n) /* > 0 */
                G.out_part++;
+#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+               G.total_bytes += n;
+#endif

wrong indentation.


+                       G.total_bytes, G.total_bytes / 1024 / 1024,

It's a signed division. gcc won't optimize it into shift.


+                       (now - G.begin_time) / 1000000.0,
+                       (G.total_bytes / 1024 / 1024) / ((now - G.begin_time) / 1000000.0));

(1) are you sure gcc will reuse (now - G.begin_time) / 1000000.0 ?
(2) what if it will be 0?
(3) you lose a lot of precision by dividing mb / sec instead of bytes / millisec.


How about attached patch? Tests:


# ./busybox dd </dev/null >/dev/null
0+0 records in
0+0 records out
0 bytes (0B) copied, 0.000006 seconds, 0B/s

# ./busybox dd bs=1M count=2000 </dev/zero >/dev/null
2000+0 records in
2000+0 records out
2097152000 bytes (2.0GB) copied, 1.227030 seconds, 2.0GB/s

# (echo DONE) | ./busybox dd >/dev/null
0+1 records in
0+1 records out
5 bytes (5B) copied, 0.000014 seconds, 365.7KB/s

# (sleep 1; echo DONE) | ./busybox dd >/dev/null
0+1 records in
0+1 records out
5 bytes (5B) copied, 0.999956 seconds, 5B/s

Bloatcheck:

function                                             old     new   delta
dd_output_status                                      68     289    +221
dd_main                                             1463    1482     +19
write_and_stats                                       64      75     +11
packed_usage                                       26529   26526      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 251/-3)            Total: 248 bytes

I committed it to git.

--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 8.patch
Type: text/x-diff
Size: 4019 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20091014/593ad8a9/attachment.bin>


More information about the busybox mailing list