summaryrefslogtreecommitdiff
path: root/probes_helper.h
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-01 02:13:06 (GMT)
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-01 02:13:06 (GMT)
commitafb02bbe92e55f877d50ed8705c95a41d541458d (patch)
tree8012de32b7703a09be9d25ecfa1915990f1679a4 /probes_helper.h
parentd3c6187a4d968549b689757bb360e482bd881e07 (diff)
* variable.c (rb_class_path_no_cache): add a function to get the class
path without caching the computed path. Some classes are frozen, and will raise an exception without this. * probes.d (cmethod-entry, cmethod-return): separate cmethods from regular methods to match set trace func. * probes_helper.h: refactor macros. Fix probes to avoid calling #inspect when profiling. * insns.def: update for use with new macros. * vm_eval.c: ditto * vm_insnhelper.c: ditto * test/dtrace/test_singleton_function.rb: fix test for new output. * test/dtrace/test_cmethod.rb: test the cmethod probes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'probes_helper.h')
-rw-r--r--probes_helper.h71
1 files changed, 46 insertions, 25 deletions
diff --git a/probes_helper.h b/probes_helper.h
index 7f4beb9..13bcbdb 100644
--- a/probes_helper.h
+++ b/probes_helper.h
@@ -4,23 +4,11 @@
#include "ruby/ruby.h"
#include "probes.h"
-#define RUBY_DTRACE_METHOD_ENTRY_HOOK(klass, id) \
- if (RUBY_DTRACE_METHOD_ENTRY_ENABLED()) { \
- const char * classname = rb_class2name((klass)); \
- const char * methodname = rb_id2name((id)); \
- const char * filename = rb_sourcefile(); \
- if (classname && methodname && filename) { \
- RUBY_DTRACE_METHOD_ENTRY( \
- classname, \
- methodname, \
- filename, \
- rb_sourceline()); \
- } \
- } \
+VALUE rb_class_path_no_cache(VALUE _klass);
-#define RUBY_DTRACE_METHOD_RETURN_HOOK(th, klass, id) \
- if (RUBY_DTRACE_METHOD_RETURN_ENABLED()) { \
- VALUE _klass = (klass); \
+#define RUBY_DTRACE_HOOK(name, th, klazz, id) \
+ if (RUBY_DTRACE_##name##_ENABLED()) { \
+ VALUE _klass = (klazz); \
VALUE _id = (id); \
const char * classname; \
const char * methodname; \
@@ -28,16 +16,49 @@
if (!_klass) { \
rb_thread_method_id_and_class((th), &_id, &_klass); \
} \
- classname = rb_class2name(_klass); \
- methodname = rb_id2name(_id); \
- filename = rb_sourcefile(); \
- if (classname && methodname && filename) { \
- RUBY_DTRACE_METHOD_RETURN( \
- classname, \
- methodname, \
- filename, \
- rb_sourceline()); \
+ if (_klass) { \
+ if (RB_TYPE_P(_klass, T_ICLASS)) { \
+ _klass = RBASIC(_klass)->klass; \
+ } \
+ else if (FL_TEST(_klass, FL_SINGLETON)) { \
+ _klass = rb_iv_get(_klass, "__attached__"); \
+ } \
+ switch(TYPE(_klass)) { \
+ case T_CLASS: \
+ case T_ICLASS: \
+ case T_MODULE: \
+ { \
+ VALUE _name = rb_class_path_no_cache(_klass); \
+ if (!NIL_P(_name)) { \
+ classname = StringValuePtr(_name); \
+ } else { \
+ classname = "<unknown>"; \
+ } \
+ methodname = rb_id2name(_id); \
+ filename = rb_sourcefile(); \
+ if (classname && methodname && filename) { \
+ RUBY_DTRACE_##name( \
+ classname, \
+ methodname, \
+ filename, \
+ rb_sourceline()); \
+ } \
+ break; \
+ } \
+ } \
} \
} \
+#define RUBY_DTRACE_METHOD_ENTRY_HOOK(th, klass, id) \
+ RUBY_DTRACE_HOOK(METHOD_ENTRY, th, klass, id)
+
+#define RUBY_DTRACE_METHOD_RETURN_HOOK(th, klass, id) \
+ RUBY_DTRACE_HOOK(METHOD_RETURN, th, klass, id)
+
+#define RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, klass, id) \
+ RUBY_DTRACE_HOOK(CMETHOD_ENTRY, th, klass, id)
+
+#define RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, klass, id) \
+ RUBY_DTRACE_HOOK(CMETHOD_RETURN, th, klass, id)
+
#endif /* RUBY_PROBES_HELPER_H */