From 8737a976bf36161f7625bac222f828b06aa9cc4d Mon Sep 17 00:00:00 2001 From: ken Date: Thu, 11 Apr 2013 21:18:04 +0000 Subject: Fix bugs in the elapsed time calculation in ctlstat_standard() pointed out by bde: - Casting to long double isn't needed. - The division isn't needed, multiplication can be used. "When 1 nanosecond is in a floating point literal, the whole expression is automatically promoted correctly." - non-KNF indentation (1 tab) for the newly split line - different non-KNF indentation (5 spaces) for the previously split line - exessive parentheses around the division operation - bogus blank line which splits up the etime initialization - general verboseness from the above. Submitted by: bde MFC after: 3 days --- usr.bin/ctlstat/ctlstat.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'usr.bin/ctlstat/ctlstat.c') diff --git a/usr.bin/ctlstat/ctlstat.c b/usr.bin/ctlstat/ctlstat.c index ff67bf6..e04aa54 100644 --- a/usr.bin/ctlstat/ctlstat.c +++ b/usr.bin/ctlstat/ctlstat.c @@ -404,7 +404,7 @@ ctlstat_json(struct ctlstat_context *ctx) { 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,8 @@ 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 + - ((long double)ctx->cur_time.tv_nsec / 1000000000); - prev_secs = ctx->prev_time.tv_sec + - ((long double)ctx->prev_time.tv_nsec / 1000000000); - - etime = cur_secs - prev_secs; + etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec + + (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9; if (F_CPU(ctx)) { ctx->prev_total_jiffies = ctx->cur_total_jiffies; -- cgit v1.1