Skip to content

Commit

Permalink
vm_method.c: add new ruby::method-cache-clear dtrace probe
Browse files Browse the repository at this point in the history
* vm_method.c (rb_clear_method_cache_by_class): fire
  ruby::method-cache-clear probe on global or klass-level method cache
  clear [Bug ruby#9190]
* probes.d (provider ruby): new dtrace probe
* doc/dtrace_probes.rdoc: docs for new probe
* test/dtrace/test_method_cache.rb: test for new probe

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
tmm1 committed Dec 9, 2013
1 parent 4f7c10f commit 4092574
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ChangeLog
@@ -1,3 +1,12 @@
Tue Dec 10 07:48:29 2013 Aman Gupta <ruby@tmm1.net>

* vm_method.c (rb_clear_method_cache_by_class): fire
ruby::method-cache-clear probe on global or klass-level method cache
clear [Bug #9190]
* probes.d (provider ruby): new dtrace probe
* doc/dtrace_probes.rdoc: docs for new probe
* test/dtrace/test_method_cache.rb: test for new probe

Tue Dec 10 06:14:11 2013 Eric Hodel <drbrain@segment7.net>

* ext/.document: Remove curses from documentable directories.
Expand Down
6 changes: 6 additions & 0 deletions doc/dtrace_probes.rdoc
Expand Up @@ -169,4 +169,10 @@ with when they are fired and the arguments they take:
[ruby:::gc-sweep-end();]
Fired at the end of a sweep phase.

[ruby:::method-cache-clear(class, sourcefile, lineno);]
Fired when the method cache is cleared.

class is the classname being cleared, or "global" (string)
sourcefile the file being parsed (string)
lineno the line number where the source ended (int)

11 changes: 11 additions & 0 deletions probes.d
Expand Up @@ -214,6 +214,17 @@ provider ruby {
Fired at the end of a sweep phase.
*/
probe gc__sweep__end();

/*
ruby:::method-cache-clear(class, filename, lineno);
This probe is fired when the method cache is cleared.
* `class` the name of the class or "global" (a string)
* `filename` the file name where the cache is _being cleared_ (a string)
* `lineno` the line number where the cache is _being cleared_ (an int)
*/
probe method__cache__clear(const char *class, const char *filename, int lineno);
};

#pragma D attributes Stable/Evolving/Common provider ruby provider
Expand Down
28 changes: 28 additions & 0 deletions test/dtrace/test_method_cache.rb
@@ -0,0 +1,28 @@
require_relative 'helper'

module DTrace
class TestMethodCacheClear < TestCase
def test_method_cache_clear
trap_probe(probe, <<-code) do |_,rbfile,lines|
class String; end
class String; def abc() end end
class Object; def abc() end end
code
assert_not_includes lines, "String #{rbfile} 1\n"
assert_includes lines, "String #{rbfile} 2\n"
assert_includes lines, "global #{rbfile} 3\n"
end
end

private
def probe
<<-eoprobe
ruby$target:::method-cache-clear
/arg1/
{
printf("%s %s %d\\n", copyinstr(arg0), copyinstr(arg1), arg2);
}
eoprobe
end
end
end if defined?(DTrace::TestCase)
8 changes: 7 additions & 1 deletion vm_method.c
Expand Up @@ -61,7 +61,13 @@ void
rb_clear_method_cache_by_class(VALUE klass)
{
if (klass && klass != Qundef) {
if (klass == rb_cBasicObject || klass == rb_cObject || klass == rb_mKernel) {
int global = klass == rb_cBasicObject || klass == rb_cObject || klass == rb_mKernel;

if (RUBY_DTRACE_METHOD_CACHE_CLEAR_ENABLED()) {
RUBY_DTRACE_METHOD_CACHE_CLEAR(global ? "global" : rb_class2name(klass), rb_sourcefile(), rb_sourceline());
}

if (global) {
INC_GLOBAL_METHOD_STATE();
}
else {
Expand Down

0 comments on commit 4092574

Please sign in to comment.