Feature #9190
closedExpose serial helper macros
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!
Updated by simeonwillbanks (Simeon Willbanks) almost 11 years ago
After addressing a Pull Request comment, the methods are defined on RubyVM:
RubyVM.method_serial
RubyVM.constant_serial
Updated by nobu (Nobuyoshi Nakada) almost 11 years ago
- Category set to core
- % Done changed from 100 to 0
Why do you need those internal values?
Updated by nobu (Nobuyoshi Nakada) almost 11 years ago
- Status changed from Open to Feedback
Updated by Anonymous almost 11 years ago
Why do you need those internal values?
We have something similar in our custom build of Ruby. It's very useful for performance metrics.
Updated by tmm1 (Aman Karmani) almost 11 years ago
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.
Updated by simeonwillbanks (Simeon Willbanks) almost 11 years ago
@charliesome and @tmm1 (Aman Karmani), thanks for the support, and I concur.
@nobu (Nobuyoshi Nakada) I've hacked together a gem. It's an alpha version, and it depends upon this patch.
https://github.com/simeonwillbanks/busted
The gem is a continuation of the description's example. Basically, an application wraps code in a block. Once the block executes, it reports whether or not the constant or method cache was busted. The tests have specific examples.
https://github.com/simeonwillbanks/busted/blob/master/test/busted_test.rb
Hope this helps. If you have anymore questions, please ask. Thanks!
Updated by tmm1 (Aman Karmani) almost 11 years ago
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.
Updated by tmm1 (Aman Karmani) almost 11 years ago
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).
Updated by simeonwillbanks (Simeon Willbanks) almost 11 years ago
I'm cool with RubyVM.stat; copying the GC.stat implementation is a good idea.
RubyVM.stat
=> {
:method_serial => 200,
:constant_serial => 210,
}
Updated by nobu (Nobuyoshi Nakada) almost 11 years ago
It sounds better than exposing those values directly.
Updated by simeonwillbanks (Simeon Willbanks) almost 11 years ago
OK, cool. I'll refactor the Pull Request. Thanks!
Updated by tmm1 (Aman Karmani) almost 11 years ago
- 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
Updated by simeonwillbanks (Simeon Willbanks) almost 11 years ago
Thanks everyone!