diff options
author | phk <phk@FreeBSD.org> | 1996-11-12 23:09:15 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1996-11-12 23:09:15 +0000 |
commit | 74bda8433b8407a6199e7840fb48fde136cd1c8f (patch) | |
tree | cf9743a63f5092eca553c4787aa943a896b48572 | |
parent | a81549782df942af453c4fc58169a57de424af37 (diff) | |
download | FreeBSD-src-74bda8433b8407a6199e7840fb48fde136cd1c8f.zip FreeBSD-src-74bda8433b8407a6199e7840fb48fde136cd1c8f.tar.gz |
Increase precision of duration to milliseconds.
Some heuristics to avoid overflow in calculation attempted.
-rw-r--r-- | bin/dd/args.c | 3 | ||||
-rw-r--r-- | bin/dd/conv.c | 3 | ||||
-rw-r--r-- | bin/dd/dd.c | 4 | ||||
-rw-r--r-- | bin/dd/dd.h | 4 | ||||
-rw-r--r-- | bin/dd/misc.c | 34 |
5 files changed, 34 insertions, 14 deletions
diff --git a/bin/dd/args.c b/bin/dd/args.c index 61b4794..59ccefe 100644 --- a/bin/dd/args.c +++ b/bin/dd/args.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: args.c,v 1.3 1994/09/24 02:54:42 davidg Exp $ */ #ifndef lint @@ -49,6 +49,7 @@ static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94"; #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/time.h> #include "dd.h" #include "extern.h" diff --git a/bin/dd/conv.c b/bin/dd/conv.c index e87c396..41c5909 100644 --- a/bin/dd/conv.c +++ b/bin/dd/conv.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: conv.c,v 1.3 1994/09/24 02:54:44 davidg Exp $ */ #ifndef lint @@ -45,6 +45,7 @@ static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94"; #include <err.h> #include <string.h> +#include <sys/time.h> #include "dd.h" #include "extern.h" diff --git a/bin/dd/dd.c b/bin/dd/dd.c index 55c4e76..a0c6f7a 100644 --- a/bin/dd/dd.c +++ b/bin/dd/dd.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: dd.c,v 1.4 1995/01/17 23:04:29 ache Exp $ + * $Id: dd.c,v 1.5 1995/10/23 21:31:48 ache Exp $ */ #ifndef lint @@ -213,7 +213,7 @@ setup() ctab[cnt] = cnt; } } - (void)time(&st.start); /* Statistics timestamp. */ + (void)gettimeofday(&st.start, 0); /* Statistics timestamp. */ } static void diff --git a/bin/dd/dd.h b/bin/dd/dd.h index 4ad9747..6ebc3a7 100644 --- a/bin/dd/dd.h +++ b/bin/dd/dd.h @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * @(#)dd.h 8.3 (Berkeley) 4/2/94 - * $Id$ + * $Id: dd.h,v 1.2 1994/09/24 02:54:54 davidg Exp $ */ /* Input/output stream state. */ @@ -70,7 +70,7 @@ typedef struct { u_long trunc; /* # of truncated records */ u_long swab; /* # of odd-length swab blocks */ u_long bytes; /* # of bytes written */ - time_t start; /* start time of dd */ + struct timeval start; /* start time of dd */ } STAT; /* Flags (in ddflags). */ diff --git a/bin/dd/misc.c b/bin/dd/misc.c index a135c85..7e6932f 100644 --- a/bin/dd/misc.c +++ b/bin/dd/misc.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: misc.c,v 1.2 1994/09/24 02:55:01 davidg Exp $ */ #ifndef lint @@ -49,6 +49,7 @@ static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; #include <string.h> #include <time.h> #include <unistd.h> +#include <sys/time.h> #include "dd.h" #include "extern.h" @@ -56,12 +57,23 @@ static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; void summary() { - time_t secs; + struct timeval tv; + long msec; char buf[100]; - (void)time(&secs); - if ((secs -= st.start) == 0) - secs = 1; + (void)gettimeofday(&tv, 0); + tv.tv_sec -= st.start.tv_sec; + tv.tv_usec -= st.start.tv_usec; + if (tv.tv_usec < 0) { + tv.tv_usec += 1000000; + tv.tv_sec--; + } + + msec = tv.tv_sec * 1000; + msec += tv.tv_usec / 1000; + + if (msec == 0) + msec = 1; /* Use snprintf(3) so that we don't reenter stdio(3). */ (void)snprintf(buf, sizeof(buf), "%u+%u records in\n%u+%u records out\n", @@ -77,9 +89,15 @@ summary() st.trunc, (st.trunc == 1) ? "block" : "blocks"); (void)write(STDERR_FILENO, buf, strlen(buf)); } - (void)snprintf(buf, sizeof(buf), - "%u bytes transferred in %u secs (%u bytes/sec)\n", - st.bytes, secs, st.bytes / secs); + if (msec > 1000000) { + (void)snprintf(buf, sizeof(buf), + "%u bytes transferred in %u.%03d secs (%u bytes/sec)\n", + st.bytes, tv.tv_sec, 0, st.bytes / tv.tv_sec); + } else { + (void)snprintf(buf, sizeof(buf), + "%u bytes transferred in %u.%03d secs (%u bytes/sec)\n", + st.bytes, msec/1000, msec%1000, st.bytes*1000 / msec); + } (void)write(STDERR_FILENO, buf, strlen(buf)); } |