In the words of Our Fearless Leader, I am "utterly sick" of dd(1)

lying to me about transfer rates. Do some fixed point frobbing to get
stuff like: 2486864 bytes transferred in 0.272 secs (9142882 bytes/sec)
This commit is contained in:
ross 2001-04-28 22:47:23 +00:00
parent 01b66ea788
commit aecbd4c404
6 changed files with 32 additions and 21 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: args.c,v 1.14 1999/07/29 19:03:31 hubertf Exp $ */
/* $NetBSD: args.c,v 1.15 2001/04/28 22:47:23 ross Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -42,11 +42,12 @@
#if 0
static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: args.c,v 1.14 1999/07/29 19:03:31 hubertf Exp $");
__RCSID("$NetBSD: args.c,v 1.15 2001/04/28 22:47:23 ross Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <err.h>
#include <errno.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: conv.c,v 1.10 2001/01/16 02:41:17 cgd Exp $ */
/* $NetBSD: conv.c,v 1.11 2001/04/28 22:47:23 ross Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -42,11 +42,12 @@
#if 0
static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: conv.c,v 1.10 2001/01/16 02:41:17 cgd Exp $");
__RCSID("$NetBSD: conv.c,v 1.11 2001/04/28 22:47:23 ross Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <err.h>
#include <string.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: dd.c,v 1.19 2000/10/25 10:57:20 kleink Exp $ */
/* $NetBSD: dd.c,v 1.20 2001/04/28 22:47:23 ross Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: dd.c,v 1.19 2000/10/25 10:57:20 kleink Exp $");
__RCSID("$NetBSD: dd.c,v 1.20 2001/04/28 22:47:23 ross Exp $");
#endif
#endif /* not lint */
@ -55,6 +55,7 @@ __RCSID("$NetBSD: dd.c,v 1.19 2000/10/25 10:57:20 kleink Exp $");
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mtio.h>
#include <sys/time.h>
#include <ctype.h>
#include <err.h>
@ -64,7 +65,6 @@ __RCSID("$NetBSD: dd.c,v 1.19 2000/10/25 10:57:20 kleink Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "dd.h"
@ -225,7 +225,7 @@ setup()
#endif /* NO_CONV */
}
(void)time(&st.start); /* Statistics timestamp. */
(void)gettimeofday(&st.start, NULL); /* Statistics timestamp. */
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: dd.h,v 1.5 1998/02/04 06:42:31 enami Exp $ */
/* $NetBSD: dd.h,v 1.6 2001/04/28 22:47:23 ross Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -71,7 +71,7 @@ typedef struct {
u_long trunc; /* # of truncated records */
u_long swab; /* # of odd-length swab blocks */
u_quad_t bytes; /* # of bytes written */
time_t start; /* start time of dd */
struct timeval start; /* start time of dd */
} STAT;
/* Flags (in ddflags). */

View File

@ -1,4 +1,4 @@
/* $NetBSD: misc.c,v 1.10 2001/01/04 15:39:50 lukem Exp $ */
/* $NetBSD: misc.c,v 1.11 2001/04/28 22:47:23 ross Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -42,34 +42,39 @@
#if 0
static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: misc.c,v 1.10 2001/01/04 15:39:50 lukem Exp $");
__RCSID("$NetBSD: misc.c,v 1.11 2001/04/28 22:47:23 ross Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <inttypes.h>
#include "dd.h"
#include "extern.h"
#define tv2mS(tv) ((tv).tv_sec * 1000LL + ((tv).tv_usec + 500) / 1000)
void
summary()
{
time_t secs;
char buf[100];
int64_t mS;
struct timeval tv;
if (progress)
(void)write(STDERR_FILENO, "\n", 1);
(void)time(&secs);
if ((secs -= st.start) == 0)
secs = 1;
(void)gettimeofday(&tv, NULL);
mS = tv2mS(tv) - tv2mS(st.start);
if (mS == 0)
mS = 1;
/* Use snprintf(3) so that we don't reenter stdio(3). */
(void)snprintf(buf, sizeof(buf),
"%lu+%lu records in\n%lu+%lu records out\n",
@ -86,8 +91,11 @@ summary()
(void)write(STDERR_FILENO, buf, strlen(buf));
}
(void)snprintf(buf, sizeof(buf),
"%llu bytes transferred in %lu secs (%llu bytes/sec)\n",
(long long) st.bytes, (long) secs, (long long) (st.bytes / secs));
"%llu bytes transferred in %lu.%03d secs (%llu bytes/sec)\n",
(long long) st.bytes,
(long) (mS / 1000),
(int) (mS % 1000),
(long long unsigned) (st.bytes * 1000LL / mS));
(void)write(STDERR_FILENO, buf, strlen(buf));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: position.c,v 1.9 2000/08/02 16:46:16 christos Exp $ */
/* $NetBSD: position.c,v 1.10 2001/04/28 22:47:23 ross Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: position.c,v 1.9 2000/08/02 16:46:16 christos Exp $");
__RCSID("$NetBSD: position.c,v 1.10 2001/04/28 22:47:23 ross Exp $");
#endif
#endif /* not lint */
@ -50,6 +50,7 @@ __RCSID("$NetBSD: position.c,v 1.9 2000/08/02 16:46:16 christos Exp $");
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mtio.h>
#include <sys/time.h>
#include <err.h>
#include <errno.h>