Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH] gdb: fix nan in scoped_time_it output
Date: Mon, 28 Sep 2026 14:18:48 -0400	[thread overview]
Message-ID: <20260928181855.3217561-1-simon.marchi@polymtl.ca> (raw)

From: Simon Marchi <simon.marchi@efficios.com>

With "maintenance set per-command time on", a scope that takes less
than a millisecond prints:

  Time for "...": wall 0.000, user 0.000, sys 0.000, user+sys 0.000, -nan % CPU

The durations are converted to an integer millisecond count before the
CPU usage is computed, so a sub-millisecond scope truncates the wall
time to zero, and the division produces a NaN (or an infinity, if the
CPU time is not zero).  We don't really care about sub-millisecond
durations for the purpose of this tool, so just add a check for
`wall_ms == 0`, and report the CPU usage as 0% if true.  This is purely
cosmetic.

Change-Id: Iaf682bef4b537d6dbb58e82f7727c0ea079088aa
---
 gdb/maint.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/maint.c b/gdb/maint.c
index 8027429e6d39..22954f624efe 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1230,7 +1230,8 @@ scoped_time_it::~scoped_time_it ()
 		     "user+sys %.03f, %.01f %% CPU\n",
 		     m_what, wall_ms / 1000.0, user_ms / 1000.0,
 		     sys_ms / 1000.0, user_plus_sys_ms / 1000.0,
-		     user_plus_sys_ms * 100.0 / wall_ms);
+		     (wall_ms == 0
+		      ? 0.0 : user_plus_sys_ms * 100.0 / wall_ms));
   gdb_stdlog->write_async_safe (str.data (), str.size ());
 }
 

base-commit: 421bec796fa3a06179856da870a13cf71ddf5df2
-- 
2.55.0


             reply	other threads:[~2026-09-28 18:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 18:18 simon.marchi [this message]
2026-09-28 21:59 ` Andrew Burgess

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=20260928181855.3217561-1-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox