ruby-changes:32024
From: tmm1 <ko1@a...>
Date: Tue, 10 Dec 2013 07:50:50 +0900 (JST)
Subject: [ruby-changes:32024] tmm1:r44103 (trunk): vm_method.c: add new ruby::method-cache-clear dtrace probe
tmm1 2013-12-10 07:50:44 +0900 (Tue, 10 Dec 2013) New Revision: 44103 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44103 Log: vm_method.c: add new ruby::method-cache-clear dtrace probe * 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 Added files: trunk/test/dtrace/test_method_cache.rb Modified files: trunk/ChangeLog trunk/doc/dtrace_probes.rdoc trunk/probes.d trunk/vm_method.c Index: doc/dtrace_probes.rdoc =================================================================== --- doc/dtrace_probes.rdoc (revision 44102) +++ doc/dtrace_probes.rdoc (revision 44103) @@ -169,4 +169,10 @@ with when they are fired and the argumen https://github.com/ruby/ruby/blob/trunk/doc/dtrace_probes.rdoc#L169 [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) Index: ChangeLog =================================================================== --- ChangeLog (revision 44102) +++ ChangeLog (revision 44103) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Dec 10 07:48:29 2013 Aman Gupta <ruby@t...> + + * 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@s...> * ext/.document: Remove curses from documentable directories. Index: probes.d =================================================================== --- probes.d (revision 44102) +++ probes.d (revision 44103) @@ -214,6 +214,17 @@ provider ruby { https://github.com/ruby/ruby/blob/trunk/probes.d#L214 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 Index: vm_method.c =================================================================== --- vm_method.c (revision 44102) +++ vm_method.c (revision 44103) @@ -61,7 +61,13 @@ void https://github.com/ruby/ruby/blob/trunk/vm_method.c#L61 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 { Index: test/dtrace/test_method_cache.rb =================================================================== --- test/dtrace/test_method_cache.rb (revision 0) +++ test/dtrace/test_method_cache.rb (revision 44103) @@ -0,0 +1,28 @@ https://github.com/ruby/ruby/blob/trunk/test/dtrace/test_method_cache.rb#L1 +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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/