[Midnightbsd-cvs] src [9133] trunk/usr.bin/ctlstat/ctlstat.c: fix a time calc error

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Oct 1 20:41:09 EDT 2016


Revision: 9133
          http://svnweb.midnightbsd.org/src/?rev=9133
Author:   laffer1
Date:     2016-10-01 20:41:09 -0400 (Sat, 01 Oct 2016)
Log Message:
-----------
fix a time calc error

Modified Paths:
--------------
    trunk/usr.bin/ctlstat/ctlstat.c

Modified: trunk/usr.bin/ctlstat/ctlstat.c
===================================================================
--- trunk/usr.bin/ctlstat/ctlstat.c	2016-10-02 00:40:24 UTC (rev 9132)
+++ trunk/usr.bin/ctlstat/ctlstat.c	2016-10-02 00:41:09 UTC (rev 9133)
@@ -404,7 +404,7 @@
 
 static void
 ctlstat_standard(struct ctlstat_context *ctx) {
-	long double cur_secs, prev_secs, etime;
+	long double etime;
 	uint64_t delta_jiffies, delta_idle;
 	uint32_t port;
 	long double cpu_percentage;
@@ -416,12 +416,9 @@
 	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);
-	prev_secs = ctx->prev_time.tv_sec +
-	     (ctx->prev_time.tv_nsec / 1000000000);
+	etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec +                  
+	    (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9; 
 
-	etime = cur_secs - prev_secs;
-
 	if (F_CPU(ctx)) {
 		ctx->prev_total_jiffies = ctx->cur_total_jiffies;
 		ctx->cur_total_jiffies = ctx->cur_cpu.user +



More information about the Midnightbsd-cvs mailing list