Feature #9190
closed
Expose serial helper macros
Added by simeonwillbanks (Simeon Willbanks) almost 11 years ago.
Updated almost 11 years ago.
Description
I've defined RubyVM::InstructionHelper with singleton methods #method_serial and #constant_serial. They delegate to helper macros GET_METHOD_SERIAL() and GET_CONSTANT_SERIAL().
With these methods, users have visibility into the method and constant caches. If it makes sense, I hope this patch is included in Ruby 2.1.0.
def constants_busted?(&blk)
starting = RubyVM::InstructionHelper.constant_serial
yield
ending = RubyVM::InstructionHelper.constant_serial
ending > starting
end
busted = constants_busted? do
class Foo; end
end
puts busted.inspect
true¶
https://github.com/ruby/ruby/pull/462.patch
Thanks for considering; any input is appreciated!
After addressing a Pull Request comment, the methods are defined on RubyVM:
RubyVM.method_serial
RubyVM.constant_serial
- Category set to core
- % Done changed from 100 to 0
Why do you need those internal values?
- Status changed from Open to Feedback
Why do you need those internal values?
We have something similar in our custom build of Ruby. It's very useful for performance metrics.
I would like to see these exposed as well. They provide visibility into VM behavior, and are very useful for measuring how many constant or method table invalidations are happening in large applications.
My main use-case for exposing these serials is to collect them automatically before and after each request in a rails app and graph how many times the caches are busted per request.
I would also like to see a Tracepoint or other hook that fires whenever the cache is busted. This would allow capturing a stack trace to see exactly where the cache busting is happening.
If we're opposed to adding multiple methods to RubyVM, maybe a RubyVM.stat will suffice. It can behave the same way that GC.stat does (optional hash argument to avoid allocations).
I'm cool with RubyVM.stat; copying the GC.stat implementation is a good idea.
RubyVM.stat
=> {
:method_serial => 200,
:constant_serial => 210,
}
It sounds better than exposing those values directly.
OK, cool. I'll refactor the Pull Request. Thanks!
- Status changed from Feedback to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r44062.
Simeon, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
vm.c: add RubyVM.stat for accessing cache serials
- vm.c (ruby_vm_stat): add RubyVM.stat() for access to internal cache
counters. this methods behaves like GC.stat, accepting an optional
hash or symbol argument. [Bug #9190] [ruby-core:58750]
- test/ruby/test_rubyvm.rb: test for new method
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0