[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] xenbaked: properly use time_t in dump_stats()
- To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Fri, 19 Aug 2022 09:59:26 +0200
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5Ve5o4lLxkQ+Thb31feEDXDXRKgB/+dn8OOmJlU4ZWY=; b=CAyKl6wxzNLUranOyf0Ar1STx3aZItAMkjKkiprz9qf8Uyl78krTPZX4e6BlhwrpA1JQyzU5STyIzV5d1FQxWH/qVGE2H1vU5pQnVyxmJRaDOOgbeApE2B4oji2IcFsPqiYOY8wedwOaR1mNC0P+kZ2sJ5YliLP5GQ+XEITXDZibseVsI2KBbimGFYKQbGcuEzJVbpDgT/IAa0UIqYi0ciSetmptHGqPzNgRb4PYuje6JRsMN3Fvf+OhG3RUQoMw6apwdqjh8Oiwis9Du1w6sJZkTwza56xdHXpjvvIedqaSYYq6u5RtSllHEGTTCMYZrsrBVAYFaDgFSDuXKF7H9A==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MWbfvqxR/1iF7uhxjRX/rKzI21okdRgmYeDotACwkgRDunBaQ4K2Ha6A9wDeTVwn/8aiU/C469yWVxe2AJehGNlY4FuCRUIN6EwVbJHVNstypGm/vYAkgaKD6wsyTxAk/wWRK3Hml40gc77zWvNn9IYUrHLTShmV9kyq96C5MDZ3IkDjWlcBiK0k1qIMENt99y9ph0UldL4nCzRWi/e0tGPUAJqpMQsG01ktHCvMYNX1Pdh68p0owKWNj4oCsQK882eSI2MckJ9dS+ZCs7zuDAZvIhMLx7S7oiRVsC2aIpf2Wb/FV4Oo8IJ5vsni9f7FjD5oU1AbshfqD1MTIwnlTw==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Cc: Anthony Perard <anthony.perard@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
- Delivery-date: Fri, 19 Aug 2022 07:59:34 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
"int" is not a suitable type to convert time()'s return value to. Avoid
casts and other extra fiddling by using difftime(), on the assumption
that the overhead of using "double" doesn't matter here.
Coverity ID: 1509374
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v2: Properly use %.0f everywhere.
--- a/tools/xenmon/xenbaked.c
+++ b/tools/xenmon/xenbaked.c
@@ -230,11 +230,7 @@ static void check_gotten_sum(void)
static void dump_stats(void)
{
stat_map_t *smt = stat_map;
- time_t end_time, run_time;
-
- time(&end_time);
-
- run_time = end_time - start_time;
+ double run_time = difftime(time(NULL), start_time);
printf("Event counts:\n");
while (smt->text != NULL) {
@@ -242,13 +238,11 @@ static void dump_stats(void)
smt++;
}
- printf("processed %d total records in %d seconds (%ld per second)\n",
- rec_count, (int)run_time,
- run_time ? (long)(rec_count/run_time) : 0L);
+ printf("processed %d total records in %.0f seconds (%.0f per second)\n",
+ rec_count, run_time, run_time ? rec_count / run_time : 0);
- printf("woke up %d times in %d seconds (%ld per second)\n",
- wakeups, (int) run_time,
- run_time ? (long)(wakeups/run_time) : 0L);
+ printf("woke up %d times in %.0f seconds (%.0f per second)\n",
+ wakeups, run_time, run_time ? wakeups / run_time : 0);
check_gotten_sum();
}
|