Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: fix nan in scoped_time_it output
@ 2026-09-28 18:18 simon.marchi
  2026-09-28 21:59 ` Andrew Burgess
  0 siblings, 1 reply; 2+ messages in thread
From: simon.marchi @ 2026-09-28 18:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gdb: fix nan in scoped_time_it output
  2026-09-28 18:18 [PATCH] gdb: fix nan in scoped_time_it output simon.marchi
@ 2026-09-28 21:59 ` Andrew Burgess
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2026-09-28 21:59 UTC (permalink / raw)
  To: simon.marchi, gdb-patches; +Cc: Simon Marchi

simon.marchi@polymtl.ca writes:

> 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.

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-28 21:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-28 18:18 [PATCH] gdb: fix nan in scoped_time_it output simon.marchi
2026-09-28 21:59 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox