Permalink
Browse files

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 4f7c10f commit 4092574257645118e98224318b89cf80fd18a144 @tmm1 tmm1 committed Dec 9, 2013
Showing with 61 additions and 1 deletion.
  1. +9 −0 ChangeLog
  2. +6 −0 doc/dtrace_probes.rdoc
  3. +11 −0 probes.d
  4. +28 −0 test/dtrace/test_method_cache.rb
  5. +7 −1 vm_method.c
View
@@ -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.
View
@@ -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)
View
@@ -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
@@ -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)
View
@@ -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 {

0 comments on commit 4092574

Please sign in to comment.