mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
56eee285be
commit
38094dd7f4
2 changed files with 62 additions and 48 deletions
|
@ -4,66 +4,40 @@
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
#include "probes.h"
|
#include "probes.h"
|
||||||
|
|
||||||
VALUE rb_class_path_no_cache(VALUE _klass);
|
struct ruby_dtrace_method_hook_args {
|
||||||
|
const char *classname;
|
||||||
|
const char *methodname;
|
||||||
|
const char *filename;
|
||||||
|
int line_no;
|
||||||
|
volatile VALUE klass;
|
||||||
|
volatile VALUE name;
|
||||||
|
};
|
||||||
|
|
||||||
#define RUBY_DTRACE_HOOK(name, th, klazz, id) \
|
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 { \
|
do { \
|
||||||
if (RUBY_DTRACE_##name##_ENABLED()) { \
|
if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \
|
||||||
VALUE _klass = (klazz); \
|
struct ruby_dtrace_method_hook_args args; \
|
||||||
ID _id = (id); \
|
if (ruby_th_dtrace_setup(th, klazz, id, &args)) { \
|
||||||
const char * classname; \
|
RUBY_DTRACE_##name(args.classname, \
|
||||||
const char * methodname; \
|
args.methodname, \
|
||||||
const char * filename; \
|
args.filename, \
|
||||||
if (!_klass) { \
|
args.line_no); \
|
||||||
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; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
RB_GC_GUARD(_klass); \
|
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define RUBY_DTRACE_METHOD_ENTRY_HOOK(th, klass, id) \
|
#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) \
|
#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) \
|
#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) \
|
#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 */
|
#endif /* RUBY_PROBES_HELPER_H */
|
||||||
|
|
40
vm.c
40
vm.c
|
@ -179,6 +179,46 @@ rb_vm_inc_const_missing_count(void)
|
||||||
ruby_vm_const_missing_count +=1;
|
ruby_vm_const_missing_count +=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE rb_class_path_no_cache(VALUE _klass);
|
||||||
|
|
||||||
|
int
|
||||||
|
ruby_th_dtrace_setup(rb_thread_t *th, VALUE klass, ID id,
|
||||||
|
struct ruby_dtrace_method_hook_args *args)
|
||||||
|
{
|
||||||
|
enum ruby_value_type type;
|
||||||
|
if (!klass) {
|
||||||
|
if (!th) th = GET_THREAD();
|
||||||
|
if (!rb_thread_method_id_and_class(th, &id, &klass) || !klass)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (RB_TYPE_P(klass, T_ICLASS)) {
|
||||||
|
klass = RBASIC(klass)->klass;
|
||||||
|
}
|
||||||
|
else if (FL_TEST(klass, FL_SINGLETON)) {
|
||||||
|
klass = rb_attr_get(klass, id__attached__);
|
||||||
|
if (NIL_P(klass)) return FALSE;
|
||||||
|
}
|
||||||
|
type = BUILTIN_TYPE(klass);
|
||||||
|
if (type == T_CLASS || type == T_ICLASS || type == T_MODULE) {
|
||||||
|
VALUE name = rb_class_path_no_cache(klass);
|
||||||
|
const char *classname;
|
||||||
|
const char *methodname = rb_id2name(id);
|
||||||
|
const char *filename = rb_sourcefile();
|
||||||
|
if (methodname && filename) {
|
||||||
|
if (NIL_P(name) || !(classname = StringValuePtr(name)))
|
||||||
|
classname = "<unknown>";
|
||||||
|
args->classname = classname;
|
||||||
|
args->methodname = methodname;
|
||||||
|
args->filename = filename;
|
||||||
|
args->line_no = rb_sourceline();
|
||||||
|
args->klass = klass;
|
||||||
|
args->name = name;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* RubyVM.stat -> Hash
|
* RubyVM.stat -> Hash
|
||||||
|
|
Loading…
Add table
Reference in a new issue