summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2023-10-19 13:41:38 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2023-10-19 15:14:20 -0400
commit9047fe5ea4e8c989c1081aa10f741a413c546534 (patch)
treec35e4e3e9bc5d2dbbcd01c511ccfa41c6c5a7203
parentcdc2a18541a42e63a8a0a3c2c5b72978ace01afa (diff)
YJIT: Print exit reasons on failure in test_yjit.rb
For <https://bugs.ruby-lang.org/issues/19921>, I suspect the test is failing due to a timing related interrupt, which on paper could happen with slow-enough GC runs. In any case, it's helpful for debugging to have more information when tests fail. Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
-rw-r--r--test/ruby/test_yjit.rb13
-rw-r--r--yjit.rb19
2 files changed, 23 insertions, 9 deletions
diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
index fa357b4977..1fe9d68b30 100644
--- a/test/ruby/test_yjit.rb
+++ b/test/ruby/test_yjit.rb
@@ -10,6 +10,8 @@ require_relative '../lib/jit_support'
return unless JITSupport.yjit_supported?
+require 'stringio'
+
# Tests for YJIT with assertions on compilation and side exits
# insipired by the RJIT tests in test/ruby/test_rjit.rb
class TestYJIT < Test::Unit::TestCase
@@ -1470,8 +1472,15 @@ class TestYJIT < Test::Unit::TestCase
if exits != :any &&
exits != recorded_exits &&
(exits.keys != recorded_exits.keys || !exits.all? { |k, v| v === recorded_exits[k] }) # triple-equal checks range membership or integer equality
- flunk "Expected #{exits.empty? ? "no" : exits.inspect} exits" \
- ", but got\n#{recorded_exits.inspect}"
+ stats_reasons = StringIO.new
+ ::RubyVM::YJIT.send(:_print_stats_reasons, runtime_stats, stats_reasons)
+ stats_reasons = stats_reasons.string
+ flunk <<~EOM
+ Expected #{exits.empty? ? "no" : exits.inspect} exits, but got:
+ #{recorded_exits.inspect}
+ Reasons:
+ #{stats_reasons}
+ EOM
end
end
diff --git a/yjit.rb b/yjit.rb
index 295e88ef34..c39175d12d 100644
--- a/yjit.rb
+++ b/yjit.rb
@@ -245,13 +245,8 @@ module RubyVM::YJIT
$stderr.puts("YJIT exit locations dumped to `#{filename}`.")
end
- # Format and print out counters
- def _print_stats(out: $stderr) # :nodoc:
- stats = runtime_stats(context: true)
- return unless Primitive.rb_yjit_stats_enabled_p
-
- out.puts("***YJIT: Printing YJIT statistics on exit***")
-
+ # Print a summary of reasons for adverse performance events (e.g. exits)
+ def _print_stats_reasons(stats, out) # :nodoc:
print_counters(stats, out: out, prefix: 'send_', prompt: 'method call fallback reasons: ')
print_counters(stats, out: out, prefix: 'invokeblock_', prompt: 'invokeblock fallback reasons: ')
print_counters(stats, out: out, prefix: 'invokesuper_', prompt: 'invokesuper fallback reasons: ')
@@ -286,6 +281,16 @@ module RubyVM::YJIT
end
print_counters(stats, out: out, prefix: 'lshift_', prompt: 'left shift (ltlt) exit reasons: ')
print_counters(stats, out: out, prefix: 'invalidate_', prompt: 'invalidation reasons: ')
+ end
+
+ # Format and print out counters
+ def _print_stats(out: $stderr) # :nodoc:
+ stats = runtime_stats(context: true)
+ return unless Primitive.rb_yjit_stats_enabled_p
+
+ out.puts("***YJIT: Printing YJIT statistics on exit***")
+
+ _print_stats_reasons(stats, out)
# Number of failed compiler invocations
compilation_failure = stats[:compilation_failure]