aboutsummaryrefslogtreecommitdiffstats
path: root/probes_helper.h
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-29 05:32:19 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-29 05:32:19 +0000
commitbf91b74a321daa428b2e68fd2c556b0f66d3ead1 (patch)
treed112dcdc0f34898811f8a1db6be9cc83390d092e /probes_helper.h
parentd9da8f44d17a69f65f354980aca48f18c1b91f6f (diff)
downloadruby-bf91b74a321daa428b2e68fd2c556b0f66d3ead1.tar.gz
vm.c: ruby_th_dtrace_setup
* vm.c (ruby_th_dtrace_setup): extract setup for calling dtrace hook from RUBY_DTRACE_HOOK macro. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'probes_helper.h')
-rw-r--r--probes_helper.h72
1 files changed, 23 insertions, 49 deletions
diff --git a/probes_helper.h b/probes_helper.h
index 53eaf57d73..1becae5a8d 100644
--- a/probes_helper.h
+++ b/probes_helper.h
@@ -4,66 +4,40 @@
#include "ruby/ruby.h"
#include "probes.h"
-VALUE rb_class_path_no_cache(VALUE _klass);
-
-#define RUBY_DTRACE_HOOK(name, th, klazz, id) \
+struct ruby_dtrace_method_hook_args {
+ const char *classname;
+ const char *methodname;
+ const char *filename;
+ int line_no;
+ volatile VALUE klass;
+ volatile VALUE name;
+};
+
+NOINLINE(int ruby_th_dtrace_setup(rb_thread_t *, VALUE, ID, struct ruby_dtrace_method_hook_args *));
+
+#define RUBY_DTRACE_METHOD_HOOK(name, th, klazz, id) \
do { \
- if (RUBY_DTRACE_##name##_ENABLED()) { \
- VALUE _klass = (klazz); \
- ID _id = (id); \
- const char * classname; \
- const char * methodname; \
- const char * filename; \
- if (!_klass) { \
- rb_thread_method_id_and_class((th), &_id, &_klass); \
- } \
- 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()); \
- } \
- RB_GC_GUARD(_name); \
- break; \
- } \
- } \
+ if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \
+ struct ruby_dtrace_method_hook_args args; \
+ if (ruby_th_dtrace_setup(th, klazz, id, &args)) { \
+ RUBY_DTRACE_##name(args.classname, \
+ args.methodname, \
+ args.filename, \
+ args.line_no); \
} \
- RB_GC_GUARD(_klass); \
} \
} while (0)
#define RUBY_DTRACE_METHOD_ENTRY_HOOK(th, klass, id) \
- RUBY_DTRACE_HOOK(METHOD_ENTRY, th, klass, id)
+ RUBY_DTRACE_METHOD_HOOK(METHOD_ENTRY, th, klass, id)
#define RUBY_DTRACE_METHOD_RETURN_HOOK(th, klass, id) \
- RUBY_DTRACE_HOOK(METHOD_RETURN, th, klass, id)
+ RUBY_DTRACE_METHOD_HOOK(METHOD_RETURN, th, klass, id)
#define RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, klass, id) \
- RUBY_DTRACE_HOOK(CMETHOD_ENTRY, th, klass, id)
+ RUBY_DTRACE_METHOD_HOOK(CMETHOD_ENTRY, th, klass, id)
#define RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, klass, id) \
- RUBY_DTRACE_HOOK(CMETHOD_RETURN, th, klass, id)
+ RUBY_DTRACE_METHOD_HOOK(CMETHOD_RETURN, th, klass, id)
#endif /* RUBY_PROBES_HELPER_H */