diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-14 17:43:41 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-14 17:43:41 +0200 |
| commit | 7eabffafa5b6faaaa87ff8ba0efbf637aaa364e8 (patch) | |
| tree | ea5aeb122d13f8fa14d5fe2d0d7692f053914c07 /coreutils | |
| parent | 04bb6b6a5af24f9a458132a5d002c54f901ae323 (diff) | |
| download | busybox-w32-7eabffafa5b6faaaa87ff8ba0efbf637aaa364e8.tar.gz busybox-w32-7eabffafa5b6faaaa87ff8ba0efbf637aaa364e8.tar.bz2 busybox-w32-7eabffafa5b6faaaa87ff8ba0efbf637aaa364e8.zip | |
dd: use correct multiplication factor and simplify code
function old new delta
dd_output_status 332 364 +32
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/dd.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index f2e1a1683..8bba62ce1 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
| @@ -49,9 +49,9 @@ struct globals { | |||
| 49 | static void dd_output_status(int UNUSED_PARAM cur_signal) | 49 | static void dd_output_status(int UNUSED_PARAM cur_signal) |
| 50 | { | 50 | { |
| 51 | #if ENABLE_FEATURE_DD_THIRD_STATUS_LINE | 51 | #if ENABLE_FEATURE_DD_THIRD_STATUS_LINE |
| 52 | unsigned long long total; | 52 | double seconds; |
| 53 | unsigned long long diff_scaled; | 53 | unsigned long long bytes_sec; |
| 54 | unsigned long long diff_us = monotonic_us(); /* before fprintf */ | 54 | unsigned long long now_us = monotonic_us(); /* before fprintf */ |
| 55 | #endif | 55 | #endif |
| 56 | 56 | ||
| 57 | /* Deliberately using %u, not %d */ | 57 | /* Deliberately using %u, not %d */ |
| @@ -72,24 +72,12 @@ static void dd_output_status(int UNUSED_PARAM cur_signal) | |||
| 72 | * (echo DONE) | ./busybox dd >/dev/null | 72 | * (echo DONE) | ./busybox dd >/dev/null |
| 73 | * (sleep 1; echo DONE) | ./busybox dd >/dev/null | 73 | * (sleep 1; echo DONE) | ./busybox dd >/dev/null |
| 74 | */ | 74 | */ |
| 75 | diff_us -= G.begin_time_us; | 75 | seconds = (now_us - G.begin_time_us) / 1000000.0; |
| 76 | /* We need to calculate "(total * 1000000) / usec" without overflow. | 76 | bytes_sec = G.total_bytes / seconds; |
| 77 | * this would work too, but is bigger than integer code below. | ||
| 78 | * total = G.total_bytes * (double)1000000 / (diff_us ? diff_us : 1); | ||
| 79 | */ | ||
| 80 | diff_scaled = diff_us; | ||
| 81 | total = G.total_bytes; | ||
| 82 | while (total > MAXINT(unsigned long long) / (1024 * 1024)) { | ||
| 83 | total >>= 1; | ||
| 84 | diff_scaled >>= 1; | ||
| 85 | } | ||
| 86 | total *= (1024 * 1024); /* should be 1000000, but it's +45 bytes */ | ||
| 87 | if (diff_scaled > 1) | ||
| 88 | total /= diff_scaled; | ||
| 89 | fprintf(stderr, "%f seconds, %sB/s\n", | 77 | fprintf(stderr, "%f seconds, %sB/s\n", |
| 90 | diff_us / 1000000.0, | 78 | seconds, |
| 91 | /* show fractional digit, use suffixes */ | 79 | /* show fractional digit, use suffixes */ |
| 92 | make_human_readable_str(total, 1, 0) | 80 | make_human_readable_str(bytes_sec, 1, 0) |
| 93 | ); | 81 | ); |
| 94 | #endif | 82 | #endif |
| 95 | } | 83 | } |
