YJIT: small fix to stats formatting. (#12282)

Avoid division by zero and NaN%, e.g.
num_throw_break:                   0 ( NaN%)
num_throw_retry:                   0 ( NaN%)
num_throw_return:                  0 ( NaN%)
This commit is contained in:
Maxime Chevalier-Boisvert 2024-12-06 12:25:39 -05:00 committed by GitHub
parent c45503f957
commit 8502a549ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2024-12-06 17:26:00 +00:00
Merged-By: maximecb <maximecb@ruby-lang.org>

View File

@ -521,9 +521,14 @@ module RubyVM::YJIT
# Format a number along with a percentage over a total value
def format_number_pct(pad, number, total) # :nodoc:
padded_count = format_number(pad, number)
if total != 0
percentage = number.fdiv(total) * 100
formatted_pct = "%4.1f%%" % percentage
"#{padded_count} (#{formatted_pct})"
else
"#{padded_count}"
end
end
# :startdoc: