Increase precision of duration to milliseconds.
Some heuristics to avoid overflow in calculation attempted.
This commit is contained in:
parent
b430a4f0ed
commit
77dfeccef6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=19694
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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). */
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user