summaryrefslogtreecommitdiff
path: root/yjit.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2024-02-12 08:56:24 -0800
committerGitHub <noreply@github.com>2024-02-12 11:56:24 -0500
commitc04782c2cb56c512e1d1b34630cb942da3aeb366 (patch)
tree639a34a3b5288d9045cc867c31433c8d470a7e48 /yjit.rb
parentb9f25b100f801a0f1d00dfa7afcd450eab58b411 (diff)
YJIT: Adjust the padding size of counts automatically (#9912)
Diffstat (limited to 'yjit.rb')
-rw-r--r--yjit.rb19
1 files changed, 10 insertions, 9 deletions
diff --git a/yjit.rb b/yjit.rb
index 8ceb2b23cc..805c8a84a2 100644
--- a/yjit.rb
+++ b/yjit.rb
@@ -239,7 +239,7 @@ module RubyVM::YJIT
private
# Print stats and dump exit locations
- def print_and_dump_stats
+ def print_and_dump_stats # :nodoc:
if Primitive.rb_yjit_print_stats_p
_print_stats
end
@@ -396,8 +396,7 @@ module RubyVM::YJIT
# Sort calls by decreasing frequency and keep the top N
pairs = calls.map { |k,v| [k, v] }
- pairs.sort_by! {|pair| pair[1] }
- pairs.reverse!
+ pairs.sort_by! {|pair| -pair[1] }
pairs = pairs[0...how_many]
top_n_total = pairs.sum { |name, count| count }
@@ -405,9 +404,10 @@ module RubyVM::YJIT
out.puts "Top-#{pairs.size} most frequent #{type} calls (#{"%.1f" % top_n_pct}% of #{type} calls):"
+ count_width = format_number(0, pairs[0][1]).length
pairs.each do |name, count|
- padded_count = format_number_pct(10, count, num_calls)
- out.puts("#{padded_count}: #{name}")
+ padded_count = format_number_pct(count_width, count, num_calls)
+ out.puts(" #{padded_count}: #{name}")
end
end
@@ -429,9 +429,10 @@ module RubyVM::YJIT
out.puts "Top-#{exits.size} most frequent exit ops (#{"%.1f" % top_n_exit_pct}% of exits):"
+ count_width = format_number(0, exits[0][1]).length
exits.each do |name, count|
- padded_count = format_number_pct(10, count, total_exits)
- out.puts("#{padded_count}: #{name}")
+ padded_count = format_number_pct(count_width, count, total_exits)
+ out.puts(" #{padded_count}: #{name}")
end
else
out.puts "total_exits: " + format_number(10, total_exits)
@@ -474,7 +475,7 @@ module RubyVM::YJIT
end
# Format large numbers with comma separators for readability
- def format_number(pad, number)
+ def format_number(pad, number) # :nodoc:
s = number.to_s
i = s.index('.') || s.size
s.insert(i -= 3, ',') while i > 3
@@ -482,7 +483,7 @@ module RubyVM::YJIT
end
# Format a number along with a percentage over a total value
- def format_number_pct(pad, number, total)
+ def format_number_pct(pad, number, total) # :nodoc:
padded_count = format_number(pad, number)
percentage = number.fdiv(total) * 100
formatted_pct = "%4.1f%%" % percentage