summaryrefslogtreecommitdiffstats
path: root/usr.bin/ctlstat/ctlstat.c
diff options
context:
space:
mode:
authorken <ken@FreeBSD.org>2013-04-10 16:01:45 +0000
committerken <ken@FreeBSD.org>2013-04-10 16:01:45 +0000
commit65d2502f2d302c544a23463277bf296d7847d0fe (patch)
tree83ccb1d7c38eba4e29acd6841884d34b744c0da0 /usr.bin/ctlstat/ctlstat.c
parentdc49969f25f515c25eeefd924182c537cd128335 (diff)
downloadFreeBSD-src-65d2502f2d302c544a23463277bf296d7847d0fe.zip
FreeBSD-src-65d2502f2d302c544a23463277bf296d7847d0fe.tar.gz
Fix a time calculation error in ctlstat_standard().
ctlstat.c: When converting a timeval to a floating point number in ctlstat_standard(), cast the nanoseconds calculation to a long double, so we don't lose precision. Without the cast, we wind up with a time in whole seconds only. Sponsored by: Spectra Logic MFC after: 3 days
Diffstat (limited to 'usr.bin/ctlstat/ctlstat.c')
-rw-r--r--usr.bin/ctlstat/ctlstat.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.bin/ctlstat/ctlstat.c b/usr.bin/ctlstat/ctlstat.c
index 1462ab9..ff67bf6 100644
--- a/usr.bin/ctlstat/ctlstat.c
+++ b/usr.bin/ctlstat/ctlstat.c
@@ -416,9 +416,10 @@ ctlstat_standard(struct ctlstat_context *ctx) {
if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0))
errx(1, "error returned from getcpu()");
- cur_secs = ctx->cur_time.tv_sec + (ctx->cur_time.tv_nsec / 1000000000);
+ cur_secs = ctx->cur_time.tv_sec +
+ ((long double)ctx->cur_time.tv_nsec / 1000000000);
prev_secs = ctx->prev_time.tv_sec +
- (ctx->prev_time.tv_nsec / 1000000000);
+ ((long double)ctx->prev_time.tv_nsec / 1000000000);
etime = cur_secs - prev_secs;
OpenPOWER on IntegriCloud