ruby-changes:69062
From: Jean <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:43 +0900 (JST)
Subject: [ruby-changes:69062] b5a0baf1c0 (master): Allow to toggle YJIT stats collection from runtime
https://git.ruby-lang.org/ruby.git/commit/?id=b5a0baf1c0 From b5a0baf1c0f969bba966ca0791f27487de5b1067 Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Thu, 26 Aug 2021 16:11:15 +0200 Subject: Allow to toggle YJIT stats collection from runtime For use cases where you want to collect the metrics for a specific piece of code (typically a web request) you can have the stats turned off by default and then turn them on at runtime before executing the code you care about. --- yjit.rb | 8 ++++++++ yjit_iface.c | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/yjit.rb b/yjit.rb index afd1071250..9556f07ad6 100644 --- a/yjit.rb +++ b/yjit.rb @@ -134,6 +134,14 @@ module YJIT https://github.com/ruby/ruby/blob/trunk/yjit.rb#L134 Primitive.reset_stats_bang end + def self.stats_enabled? + Primitive.cexpr! 'rb_yjit_opts.gen_stats ? Qtrue : Qfalse' + end + + def self.stats_enabled=(enabled) + Primitive.set_stats_enabled(enabled) + end + def self.enabled? Primitive.cexpr! 'rb_yjit_enabled_p() ? Qtrue : Qfalse' end diff --git a/yjit_iface.c b/yjit_iface.c index 473ff2cec1..dfd0f58760 100644 --- a/yjit_iface.c +++ b/yjit_iface.c @@ -808,6 +808,13 @@ reset_stats_bang(rb_execution_context_t *ec, VALUE self) https://github.com/ruby/ruby/blob/trunk/yjit_iface.c#L808 return Qnil; } +static VALUE +set_stats_enabled(rb_execution_context_t *ec, VALUE self, VALUE enabled) +{ + rb_yjit_opts.gen_stats = RB_TEST(enabled); + return enabled; +} + #include "yjit.rbinc" #if YJIT_STATS -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/