aboutsummaryrefslogtreecommitdiffstats
path: root/yjit.rb
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2023-11-27 17:49:53 -0500
committerGitHub <noreply@github.com>2023-11-27 22:49:53 +0000
commit7f50c705742dd92509ae9fc3003eb7561baa7e8a (patch)
treeb3b4b5a084b460a80a9b3b60622fb621c4cf301b /yjit.rb
parent94015e0dce38d238d428b60b46dcb9f3caef445f (diff)
downloadruby-7f50c705742dd92509ae9fc3003eb7561baa7e8a.tar.gz
YJIT: add top C function call counts to `--yjit-stats` (#9047)
* YJIT: gather call counts for individual cfuncs Co-authored by Takashi Kokubun
Diffstat (limited to 'yjit.rb')
-rw-r--r--yjit.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/yjit.rb b/yjit.rb
index 8691a43cd6..7100242aff 100644
--- a/yjit.rb
+++ b/yjit.rb
@@ -369,6 +369,35 @@ module RubyVM::YJIT
out.puts "avg_len_in_yjit: " + ("%13.1f" % stats[:avg_len_in_yjit])
print_sorted_exit_counts(stats, out: out, prefix: "exit_")
+
+ print_sorted_cfunc_calls(stats, out:out)
+ end
+
+ def print_sorted_cfunc_calls(stats, out:, how_many: 20, left_pad: 4) # :nodoc:
+ calls = stats[:cfunc_calls]
+ #puts calls
+
+ # Total number of cfunc calls
+ num_send_cfunc = stats[:num_send_cfunc]
+
+ # 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 = pairs[0...how_many]
+
+ top_n_total = pairs.sum { |name, count| count }
+ top_n_pct = 100.0 * top_n_total / num_send_cfunc
+ longest_name_len = pairs.max_by { |name, count| name.length }.first.length
+
+ out.puts "Top-#{pairs.size} most frequent C calls (#{"%.1f" % top_n_pct}% of C calls):"
+
+ pairs.each do |name, count|
+ padding = longest_name_len + left_pad
+ padded_name = "%#{padding}s" % name
+ padded_count = format_number_pct(10, count, num_send_cfunc)
+ out.puts("#{padded_name}: #{padded_count}")
+ end
end
def print_sorted_exit_counts(stats, out:, prefix:, how_many: 20, left_pad: 4) # :nodoc: