[前][次][番号順一覧][スレッド一覧]

ruby-changes:74399

From: Takashi <ko1@a...>
Date: Wed, 9 Nov 2022 02:36:56 +0900 (JST)
Subject: [ruby-changes:74399] 5643d2bb9a (master): YJIT: Make more stats accessible from Ruby code (#6685)

https://git.ruby-lang.org/ruby.git/commit/?id=5643d2bb9a

From 5643d2bb9aae3417cfc1b9dc85bf28dfb2574a55 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Tue, 8 Nov 2022 09:36:29 -0800
Subject: YJIT: Make more stats accessible from Ruby code (#6685)

---
 yjit.rb | 49 +++++++++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/yjit.rb b/yjit.rb
index 71cbaf7edb..5a00dcca57 100644
--- a/yjit.rb
+++ b/yjit.rb
@@ -133,7 +133,30 @@ module RubyVM::YJIT https://github.com/ruby/ruby/blob/trunk/yjit.rb#L133
   # Return a hash for statistics generated for the --yjit-stats command line option.
   # Return nil when option is not passed or unavailable.
   def self.runtime_stats
-    Primitive.rb_yjit_get_stats
+    stats = Primitive.rb_yjit_get_stats
+    return stats if stats.nil? || !Primitive.rb_yjit_stats_enabled_p
+
+    side_exits = total_exit_count(stats)
+    total_exits = side_exits + stats[:leave_interp_return]
+
+    # Number of instructions that finish executing in YJIT.
+    # See :count-placement: about the subtraction.
+    retired_in_yjit = stats[:exec_instruction] - side_exits
+
+    # Average length of instruction sequences executed by YJIT
+    avg_len_in_yjit = retired_in_yjit.to_f / total_exits
+
+    # Proportion of instructions that retire in YJIT
+    total_insns_count = retired_in_yjit + stats[:vm_insns_count]
+    yjit_ratio_pct = 100.0 * retired_in_yjit.to_f / total_insns_count
+
+    # Make those stats available in RubyVM::YJIT.runtime_stats as well
+    stats[:side_exit_count]  = side_exits
+    stats[:total_exit_count] = total_exits
+    stats[:ratio_in_yjit]    = yjit_ratio_pct
+    stats[:avg_len_in_yjit]  = avg_len_in_yjit
+
+    stats
   end
 
   # Produce disassembly for an iseq
@@ -198,20 +221,6 @@ module RubyVM::YJIT https://github.com/ruby/ruby/blob/trunk/yjit.rb#L221
       print_counters(stats, prefix: 'opt_getinlinecache_', prompt: 'opt_getinlinecache exit reasons: ')
       print_counters(stats, prefix: 'invalidate_', prompt: 'invalidation reasons: ')
 
-      side_exits = total_exit_count(stats)
-      total_exits = side_exits + stats[:leave_interp_return]
-
-      # Number of instructions that finish executing in YJIT.
-      # See :count-placement: about the subtraction.
-      retired_in_yjit = stats[:exec_instruction] - side_exits
-
-      # Average length of instruction sequences executed by YJIT
-      avg_len_in_yjit = retired_in_yjit.to_f / total_exits
-
-      # Proportion of instructions that retire in YJIT
-      total_insns_count = retired_in_yjit + stats[:vm_insns_count]
-      yjit_ratio_pct = 100.0 * retired_in_yjit.to_f / total_insns_count
-
       # Number of failed compiler invocations
       compilation_failure = stats[:compilation_failure]
 
@@ -231,13 +240,13 @@ module RubyVM::YJIT https://github.com/ruby/ruby/blob/trunk/yjit.rb#L240
       $stderr.puts "code_gc_count:         " + ("%10d" % stats[:code_gc_count])
       $stderr.puts "num_gc_obj_refs:       " + ("%10d" % stats[:num_gc_obj_refs])
 
-      $stderr.puts "side_exit_count:       " + ("%10d" % side_exits)
-      $stderr.puts "total_exit_count:      " + ("%10d" % total_exits)
-      $stderr.puts "total_insns_count:     " + ("%10d" % total_insns_count)
+      $stderr.puts "side_exit_count:       " + ("%10d" % stats[:side_exit_count])
+      $stderr.puts "total_exit_count:      " + ("%10d" % stats[:side_exit_count])
+      $stderr.puts "total_insns_count:     " + ("%10d" % stats[:total_exit_count])
       $stderr.puts "vm_insns_count:        " + ("%10d" % stats[:vm_insns_count])
       $stderr.puts "yjit_insns_count:      " + ("%10d" % stats[:exec_instruction])
-      $stderr.puts "ratio_in_yjit:         " + ("%9.1f" % yjit_ratio_pct) + "%"
-      $stderr.puts "avg_len_in_yjit:       " + ("%10.1f" % avg_len_in_yjit)
+      $stderr.puts "ratio_in_yjit:         " + ("%9.1f" % stats[:ratio_in_yjit]) + "%"
+      $stderr.puts "avg_len_in_yjit:       " + ("%10.1f" % stats[:avg_len_in_yjit])
 
       print_sorted_exit_counts(stats, prefix: "exit_")
     end
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]