While I was working on my RubyConf talk for tracing yjit exit locations
I realized that there were exits from the dump code included in the
stats data. For example I saw 224 interp leave exits for a simple script
that should have had 1 or 2. I realized that the dump code needs to be
called _after_ the stats are generated, otherwise the dump code will be
counted in the stats exits.

I've added a `_dump_locations` method to the `at_exit` for stats
generation to ensure that it runs last. I've updated the documentation
to add a note that if you call `dump_exit_locations` directly, your
stats will include the dump code exits as well.
This commit is contained in:
Eileen M. Uchitelle 2022-11-09 17:09:16 -05:00 коммит произвёл GitHub
Родитель 0e1e1b1980
Коммит 9ab978b718
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 27 добавлений и 3 удалений

28
yjit.rb
Просмотреть файл

@ -112,13 +112,25 @@ module RubyVM::YJIT
# #
# Usage: # Usage:
# #
# If `--yjit-exit-locations` is passed, a file named
# "yjit_exit_locations.dump" will automatically be generated.
#
# If you want to collect traces manually, call `dump_exit_locations`
# directly.
#
# Note that calling this in a script will generate stats after the
# dump is created, so the stats data may include exits from the
# dump itself.
#
# In a script call: # In a script call:
# #
# at_exit do
# RubyVM::YJIT.dump_exit_locations("my_file.dump") # RubyVM::YJIT.dump_exit_locations("my_file.dump")
# end
# #
# Then run the file with the following options: # Then run the file with the following options:
# #
# ruby --yjit --yjit-stats --yjit-trace-exits test.rb # ruby --yjit --yjit-trace-exits test.rb
# #
# Once the code is done running, use Stackprof to read the dump file. # Once the code is done running, use Stackprof to read the dump file.
# See Stackprof documentation for options. # See Stackprof documentation for options.
@ -196,12 +208,24 @@ module RubyVM::YJIT
# Avoid calling a method here to not interfere with compilation tests # Avoid calling a method here to not interfere with compilation tests
if Primitive.rb_yjit_stats_enabled_p if Primitive.rb_yjit_stats_enabled_p
at_exit { _print_stats } at_exit do
_print_stats
_dump_locations
end
end end
class << self class << self
private private
def _dump_locations
return unless trace_exit_locations_enabled?
filename = "yjit_exit_locations.dump"
dump_exit_locations(filename)
$stderr.puts("YJIT exit locations dumped to `#{filename}`.")
end
# Format and print out counters # Format and print out counters
def _print_stats def _print_stats
stats = runtime_stats stats = runtime_stats