summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--doc/dtrace_probes.rdoc6
-rw-r--r--probes.d11
-rw-r--r--test/dtrace/test_method_cache.rb28
-rw-r--r--vm_method.c8
5 files changed, 61 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 96e24e714b..4e20aa5cd9 100644
--- a/ChangeLog
+++ b/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.
diff --git a/doc/dtrace_probes.rdoc b/doc/dtrace_probes.rdoc
index fe7309c5d7..a1e0fff3b0 100644
--- a/doc/dtrace_probes.rdoc
+++ b/doc/dtrace_probes.rdoc
@@ -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)
diff --git a/probes.d b/probes.d
index dd7a7bfcd3..dc20d30172 100644
--- a/probes.d
+++ b/probes.d
@@ -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
diff --git a/test/dtrace/test_method_cache.rb b/test/dtrace/test_method_cache.rb
new file mode 100644
index 0000000000..d8ddf454f4
--- /dev/null
+++ b/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)
diff --git a/vm_method.c b/vm_method.c
index a7aa496c95..0b707975bf 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -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 {