From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Anthony Perard <anthony.perard@citrix.com>, Wei Liu <wl@xen.org>
Subject: [PATCH 1/3] xenbaked: properly use time_t in dump_stats()
Date: Thu, 18 Aug 2022 16:05:37 +0200 [thread overview]
Message-ID: <c87ae25d-5aa8-bb70-7d2b-ea6485a01f59@suse.com> (raw)
In-Reply-To: <68e71e3b-19a7-e062-9ebe-2e6f6aae0549@suse.com>
"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@suse.com>
--- unstable.orig/tools/xenmon/xenbaked.c 2022-01-06 16:12:39.000000000 +0100
+++ unstable/tools/xenmon/xenbaked.c 2022-08-18 15:36:39.918706853 +0200
@@ -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();
}
next prev parent reply other threads:[~2022-08-18 14:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-18 14:03 [PATCH 0/3] tools: address recently reported Coverity issues Jan Beulich
2022-08-18 14:05 ` Jan Beulich [this message]
2022-08-18 16:34 ` [PATCH 1/3] xenbaked: properly use time_t in dump_stats() Anthony PERARD
2022-08-19 5:56 ` Jan Beulich
2022-08-18 14:06 ` [PATCH 2/3] console/client: properly use time_t in get_pty_fd() Jan Beulich
2022-08-18 16:40 ` Anthony PERARD
2022-08-18 14:07 ` [PATCH 3/3] libxl: use time_t for qmp_synchronous_send()'s last parameter Jan Beulich
2022-08-18 14:20 ` Juergen Gross
2022-08-18 14:35 ` Jan Beulich
2022-08-18 16:14 ` Anthony PERARD
2022-08-19 7:59 ` [PATCH v2] xenbaked: properly use time_t in dump_stats() Jan Beulich
2022-08-19 8:27 ` Anthony PERARD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c87ae25d-5aa8-bb70-7d2b-ea6485a01f59@suse.com \
--to=jbeulich@suse.com \
--cc=anthony.perard@citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.