summaryrefslogtreecommitdiff
path: root/bin/dd
diff options
context:
space:
mode:
authorHugh Graham <hugh@cvs.openbsd.org>2001-08-07 14:39:28 +0000
committerHugh Graham <hugh@cvs.openbsd.org>2001-08-07 14:39:28 +0000
commit1123cf6f64f4be51a66dca47d05690ebf62b1be8 (patch)
tree8898b01cbc215f101f3a89a547d9d9302ae5b3b7 /bin/dd
parentcaf7ba66da583ab2f500dda722b13b550ed1b19e (diff)
Modify timekeeping in an effort to produce a sane bandwidth measure
for a short running dd process. Some floating point is used so that microsecond precision can be kept without shortening the off_t excessively. millert says ok.
Diffstat (limited to 'bin/dd')
-rw-r--r--bin/dd/args.c5
-rw-r--r--bin/dd/conv.c5
-rw-r--r--bin/dd/dd.c7
-rw-r--r--bin/dd/dd.h4
-rw-r--r--bin/dd/misc.c21
-rw-r--r--bin/dd/position.c5
6 files changed, 28 insertions, 19 deletions
diff --git a/bin/dd/args.c b/bin/dd/args.c
index 05e0cabf767..95e4979601c 100644
--- a/bin/dd/args.c
+++ b/bin/dd/args.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: args.c,v 1.8 1998/07/09 18:39:23 deraadt Exp $ */
+/* $OpenBSD: args.c,v 1.9 2001/08/07 14:39:27 hugh Exp $ */
/* $NetBSD: args.c,v 1.7 1996/03/01 01:18:58 jtc Exp $ */
/*-
@@ -42,11 +42,12 @@
#if 0
static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: args.c,v 1.8 1998/07/09 18:39:23 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: args.c,v 1.9 2001/08/07 14:39:27 hugh Exp $";
#endif
#endif /* not lint */
#include <sys/types.h>
+#include <sys/time.h>
#include <err.h>
#include <errno.h>
diff --git a/bin/dd/conv.c b/bin/dd/conv.c
index 71d7824df59..d0ae1e860ad 100644
--- a/bin/dd/conv.c
+++ b/bin/dd/conv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: conv.c,v 1.7 2001/01/17 00:27:14 pjanzen Exp $ */
+/* $OpenBSD: conv.c,v 1.8 2001/08/07 14:39:27 hugh Exp $ */
/* $NetBSD: conv.c,v 1.6 1996/02/20 19:29:02 jtc Exp $ */
/*-
@@ -42,11 +42,12 @@
#if 0
static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: conv.c,v 1.7 2001/01/17 00:27:14 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: conv.c,v 1.8 2001/08/07 14:39:27 hugh Exp $";
#endif
#endif /* not lint */
#include <sys/param.h>
+#include <sys/time.h>
#include <err.h>
#include <string.h>
diff --git a/bin/dd/dd.c b/bin/dd/dd.c
index 601da2b113c..b9daa89f8bf 100644
--- a/bin/dd/dd.c
+++ b/bin/dd/dd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dd.c,v 1.8 1998/04/30 05:55:02 deraadt Exp $ */
+/* $OpenBSD: dd.c,v 1.9 2001/08/07 14:39:27 hugh Exp $ */
/* $NetBSD: dd.c,v 1.6 1996/02/20 19:29:06 jtc Exp $ */
/*-
@@ -48,7 +48,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: dd.c,v 1.8 1998/04/30 05:55:02 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: dd.c,v 1.9 2001/08/07 14:39:27 hugh Exp $";
#endif
#endif /* not lint */
@@ -206,7 +206,8 @@ setup()
#endif /* NO_CONV */
}
- (void)time(&st.start); /* Statistics timestamp. */
+ /* Statistics timestamp. */
+ (void)gettimeofday(&st.startv, (struct timezone *)NULL);
}
static void
diff --git a/bin/dd/dd.h b/bin/dd/dd.h
index 461897e7651..df82a5c17db 100644
--- a/bin/dd/dd.h
+++ b/bin/dd/dd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dd.h,v 1.3 1997/02/14 07:05:20 millert Exp $ */
+/* $OpenBSD: dd.h,v 1.4 2001/08/07 14:39:27 hugh Exp $ */
/* $NetBSD: dd.h,v 1.4 1995/03/21 09:04:08 cgd Exp $ */
/*-
@@ -72,7 +72,7 @@ typedef struct {
size_t trunc; /* # of truncated records */
size_t swab; /* # of odd-length swab blocks */
off_t bytes; /* # of bytes written */
- time_t start; /* start time of dd */
+ struct timeval startv; /* start time of dd */
} STAT;
/* Flags (in ddflags). */
diff --git a/bin/dd/misc.c b/bin/dd/misc.c
index 4143791532c..2be4360a742 100644
--- a/bin/dd/misc.c
+++ b/bin/dd/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.9 2001/06/25 08:06:04 deraadt Exp $ */
+/* $OpenBSD: misc.c,v 1.10 2001/08/07 14:39:27 hugh Exp $ */
/* $NetBSD: misc.c,v 1.4 1995/03/21 09:04:10 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: misc.c,v 1.9 2001/06/25 08:06:04 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: misc.c,v 1.10 2001/08/07 14:39:27 hugh Exp $";
#endif
#endif /* not lint */
@@ -63,14 +63,17 @@ static char rcsid[] = "$OpenBSD: misc.c,v 1.9 2001/06/25 08:06:04 deraadt Exp $"
void
summary()
{
- time_t secs;
+ struct timeval nowtv;
char buf[4][100];
struct iovec iov[4];
+ double microsecs;
int i = 0;
- (void)time(&secs);
- if ((secs -= st.start) == 0)
- secs = 1;
+ (void)gettimeofday(&nowtv, (struct timezone *)NULL);
+ timersub(&nowtv, &st.startv, &nowtv);
+ if ((microsecs = (nowtv.tv_sec * 1000000) + nowtv.tv_usec) == 0)
+ microsecs = 1;
+
/* Use snprintf(3) so that we don't reenter stdio(3). */
(void)snprintf(buf[0], sizeof(buf[0]),
"%u+%u records in\n%u+%u records out\n",
@@ -93,8 +96,10 @@ summary()
iov[i++].iov_len = strlen(buf[2]);
}
(void)snprintf(buf[3], sizeof(buf[3]),
- "%qd bytes transferred in %ld secs (%qd bytes/sec)\n",
- st.bytes, (long)secs, st.bytes / secs);
+ "%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);
+
iov[i].iov_base = buf[3];
iov[i++].iov_len = strlen(buf[3]);
diff --git a/bin/dd/position.c b/bin/dd/position.c
index a02a485bb55..0d02d2f7404 100644
--- a/bin/dd/position.c
+++ b/bin/dd/position.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: position.c,v 1.3 1997/02/14 07:05:22 millert Exp $ */
+/* $OpenBSD: position.c,v 1.4 2001/08/07 14:39:27 hugh Exp $ */
/* $NetBSD: position.c,v 1.4 1995/03/21 09:04:12 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: position.c,v 1.3 1997/02/14 07:05:22 millert Exp $";
+static char rcsid[] = "$OpenBSD: position.c,v 1.4 2001/08/07 14:39:27 hugh Exp $";
#endif
#endif /* not lint */
@@ -50,6 +50,7 @@ static char rcsid[] = "$OpenBSD: position.c,v 1.3 1997/02/14 07:05:22 millert Ex
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mtio.h>
+#include <sys/time.h>
#include <err.h>
#include <errno.h>