Uh, sorry, I have forgotten to attach the patch. It is against 1.15.2.
On Mon, 12 Oct 2009 01:36:02 +0200, Gabor Heja <[email protected]>
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.
>
> Best regards,
> Gabor
diff -urpN busybox-1.15.2/coreutils/Config.in
busybox-1.15.2-dd/coreutils/Config.in
--- busybox-1.15.2/coreutils/Config.in 2009-10-08 02:59:09.000000000 +0200
+++ busybox-1.15.2-dd/coreutils/Config.in 2009-10-11 23:54:27.000000000
+0200
@@ -119,7 +119,16 @@ config FEATURE_DD_SIGNAL_HANDLING
$ dd if=/dev/zero of=/dev/null&
$ pid=$! kill -USR1 $pid; sleep 1; kill $pid
- 10899206+0 records in 10899206+0 records out
+ 10899206+0 records in
+ 10899206+0 records out
+
+config FEATURE_DD_THIRD_STATUS_LINE
+ bool "Enable the third status line upon signal"
+ default n
+ depends on DD && FEATURE_DD_SIGNAL_HANDLING
+ help
+ Displays a coreutils-like third status line with transferred bytes,
+ elapsed time and speed.
config FEATURE_DD_IBS_OBS
bool "Enable ibs, obs and conv options"
diff -urpN busybox-1.15.2/coreutils/dd.c busybox-1.15.2-dd/coreutils/dd.c
--- busybox-1.15.2/coreutils/dd.c 2009-10-08 03:04:40.000000000 +0200
+++ busybox-1.15.2-dd/coreutils/dd.c 2009-10-11 23:55:20.000000000 +0200
@@ -34,6 +34,10 @@ static const struct suffix_mult dd_suffi
struct globals {
off_t out_full, out_part, in_full, in_part;
+#ifdef ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+ off_t total_bytes;
+ unsigned long long begin_time;
+#endif
};
#define G (*(struct globals*)&bb_common_bufsiz1)
/* We have to zero it out because of NOEXEC */
@@ -42,11 +46,23 @@ struct globals {
static void dd_output_status(int UNUSED_PARAM cur_signal)
{
+#ifdef ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+ long long unsigned now = monotonic_us();
+#endif
+
/* Deliberately using %u, not %d */
fprintf(stderr, "%"OFF_FMT"u+%"OFF_FMT"u records in\n"
"%"OFF_FMT"u+%"OFF_FMT"u records out\n",
G.in_full, G.in_part,
G.out_full, G.out_part);
+
+#ifdef ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+ fprintf(stderr, "%"OFF_FMT"u bytes (%"OFF_FMT"u MB) copied, "
+ "%f seconds, %f MB/s\n",
+ G.total_bytes, G.total_bytes / 1024 / 1024,
+ (now - G.begin_time) / 1000000.0,
+ (G.total_bytes / 1024 / 1024) / ((now - G.begin_time) /
1000000.0));
+#endif
}
static ssize_t full_write_or_warn(const void *buf, size_t len,
@@ -68,6 +84,9 @@ static bool write_and_stats(const void *
G.out_full++;
else if (n) /* > 0 */
G.out_part++;
+#ifdef ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+ G.total_bytes += n;
+#endif
return 0;
}
@@ -159,6 +178,10 @@ int dd_main(int argc UNUSED_PARAM, char
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
#endif
+#ifdef ENABLE_FEATURE_DD_THIRD_STATUS_LINE
+ G.begin_time = monotonic_us();
+#endif
+
for (n = 1; argv[n]; n++) {
int what;
char *val;
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox