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

ruby-changes:68950

From: Noah <ko1@a...>
Date: Thu, 21 Oct 2021 08:19:25 +0900 (JST)
Subject: [ruby-changes:68950] 33227b1094 (master): Add exit counters and inline/outlined code size to stats hash

https://git.ruby-lang.org/ruby.git/commit/?id=33227b1094

From 33227b1094d349bd64a2a588825cdf530ea5c459 Mon Sep 17 00:00:00 2001
From: Noah Gibbs <noah.gibbs@s...>
Date: Tue, 29 Jun 2021 15:37:12 +0100
Subject: Add exit counters and inline/outlined code size to stats hash

---
 yjit.rb      |  4 ++--
 yjit_iface.c | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/yjit.rb b/yjit.rb
index 80cd729fb5..3998e4fda8 100644
--- a/yjit.rb
+++ b/yjit.rb
@@ -125,7 +125,7 @@ module YJIT https://github.com/ruby/ruby/blob/trunk/yjit.rb#L125
   # Return nil when option is not passed or unavailable.
   def self.runtime_stats
     # defined in yjit_iface.c
-    Primitive.get_stat_counters
+    Primitive.get_yjit_stats
   end
 
   # Discard statistics collected for --yjit-stats.
@@ -142,7 +142,7 @@ module YJIT https://github.com/ruby/ruby/blob/trunk/yjit.rb#L142
       counters = runtime_stats
       return unless counters
 
-      $stderr.puts("***YJIT: Printing runtime counters from yjit.rb***")
+      $stderr.puts("***YJIT: Printing YJIT statistics on exit***")
       $stderr.puts("Number of bindings allocated: %d\n" % counters[:binding_allocations])
       $stderr.puts("Number of locals modified through binding: %d\n" % counters[:binding_set])
 
diff --git a/yjit_iface.c b/yjit_iface.c
index 0794ac9c32..e8a6dde969 100644
--- a/yjit_iface.c
+++ b/yjit_iface.c
@@ -29,6 +29,8 @@ static VALUE cYjitBlock; https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L29
 static int64_t exit_op_count[VM_INSTRUCTION_SIZE] = { 0 };
 struct rb_yjit_runtime_counters yjit_runtime_counters = { 0 };
 static VALUE cYjitCodeComment;
+
+extern const int rb_vm_max_insn_name_size;
 #endif
 
 // Machine code blocks (executable memory)
@@ -707,15 +709,26 @@ comments_for(rb_execution_context_t *ec, VALUE self, VALUE start_address, VALUE https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L709
     return comment_array;
 }
 
-// Primitive called in yjit.rb. Export all runtime counters as a Ruby hash.
+// Primitive called in yjit.rb. Export all YJIT statistics as a Ruby hash.
 static VALUE
-get_stat_counters(rb_execution_context_t *ec, VALUE self)
+get_yjit_stats(rb_execution_context_t *ec, VALUE self)
 {
 #if RUBY_DEBUG
     if (!rb_yjit_opts.gen_stats) return Qnil;
 
     VALUE hash = rb_hash_new();
     RB_VM_LOCK_ENTER();
+
+    {
+        VALUE key = ID2SYM(rb_intern("inline_code_size"));
+        VALUE value = LL2NUM((long long)cb->write_pos);
+        rb_hash_aset(hash, key, value);
+
+        key = ID2SYM(rb_intern("outlined_code_size"));
+        value = LL2NUM((long long)ocb->write_pos);
+        rb_hash_aset(hash, key, value);
+    }
+
     {
         int64_t *counter_reader = (int64_t *)&yjit_runtime_counters;
         int64_t *counter_reader_end = &yjit_runtime_counters.last_member;
@@ -747,6 +760,22 @@ get_stat_counters(rb_execution_context_t *ec, VALUE self) https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L760
             name_reader = name_end;
         }
     }
+
+    {
+        // Iterate through exit_op_count
+
+        char key_string[rb_vm_max_insn_name_size + 6]; // Leave room for exit_ and a final NUL
+        strcpy(key_string, "exit_");
+        for (int i = 0; i < VM_INSTRUCTION_SIZE; i++) {
+            const char *i_name = insn_name(i);
+            strcpy(key_string + 5, i_name);
+
+            VALUE key = ID2SYM(rb_intern(key_string));
+            VALUE value = LL2NUM((long long)exit_op_count[i]);
+            rb_hash_aset(hash, key, value);
+        }
+    }
+
     RB_VM_LOCK_LEAVE();
     return hash;
 #else
-- 
cgit v1.2.1


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

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