summaryrefslogtreecommitdiff
path: root/yjit.rb
diff options
context:
space:
mode:
authorDave Schwantes <dorkrawk@github.com>2022-06-30 09:24:34 -0500
committerGitHub <noreply@github.com>2022-06-30 10:24:34 -0400
commit2366e14976cd875e0b98321eb339d23016268b72 (patch)
tree8175d4d8d802992bcd1f4f1cccc86a01c28fa56f /yjit.rb
parentb0c639f249165d759596f9579fa985cb30533de6 (diff)
downloadruby-2366e14976cd875e0b98321eb339d23016268b72.tar.gz
YJIT: Handle 0 total_exits YJIT Status Display (#6079)
handle case in YJIT stats where 0 exits causes NaN in the display
Diffstat (limited to 'yjit.rb')
-rw-r--r--yjit.rb30
1 files changed, 17 insertions, 13 deletions
diff --git a/yjit.rb b/yjit.rb
index b0ddb475ac..b3c1efdbd4 100644
--- a/yjit.rb
+++ b/yjit.rb
@@ -233,19 +233,23 @@ module RubyVM::YJIT
exits = exits.sort_by { |name, count| -count }[0...how_many]
total_exits = total_exit_count(stats)
- top_n_total = exits.map { |name, count| count }.sum
- top_n_exit_pct = 100.0 * top_n_total / total_exits
-
- $stderr.puts "Top-#{how_many} most frequent exit ops (#{"%.1f" % top_n_exit_pct}% of exits):"
-
- longest_insn_name_len = exits.map { |name, count| name.length }.max
- exits.each do |name, count|
- padding = longest_insn_name_len + left_pad
- padded_name = "%#{padding}s" % name
- padded_count = "%10d" % count
- percent = 100.0 * count / total_exits
- formatted_percent = "%.1f" % percent
- $stderr.puts("#{padded_name}: #{padded_count} (#{formatted_percent}%)" )
+ if total_exits > 0
+ top_n_total = exits.map { |name, count| count }.sum
+ top_n_exit_pct = 100.0 * top_n_total / total_exits
+
+ $stderr.puts "Top-#{how_many} most frequent exit ops (#{"%.1f" % top_n_exit_pct}% of exits):"
+
+ longest_insn_name_len = exits.map { |name, count| name.length }.max
+ exits.each do |name, count|
+ padding = longest_insn_name_len + left_pad
+ padded_name = "%#{padding}s" % name
+ padded_count = "%10d" % count
+ percent = 100.0 * count / total_exits
+ formatted_percent = "%.1f" % percent
+ $stderr.puts("#{padded_name}: #{padded_count} (#{formatted_percent}%)" )
+ end
+ else
+ $stderr.puts "total_exits: " + ("%10d" % total_exits)
end
end