2012-11-18 20:30:10 +04:00
|
|
|
#ifndef RUBY_PROBES_HELPER_H
|
|
|
|
#define RUBY_PROBES_HELPER_H
|
|
|
|
|
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "probes.h"
|
|
|
|
|
2012-12-01 06:13:06 +04:00
|
|
|
VALUE rb_class_path_no_cache(VALUE _klass);
|
2012-11-18 20:30:10 +04:00
|
|
|
|
2012-12-01 06:13:06 +04:00
|
|
|
#define RUBY_DTRACE_HOOK(name, th, klazz, id) \
|
2012-12-11 07:37:19 +04:00
|
|
|
do { \
|
2012-12-01 06:13:06 +04:00
|
|
|
if (RUBY_DTRACE_##name##_ENABLED()) { \
|
|
|
|
VALUE _klass = (klazz); \
|
2012-11-29 21:55:54 +04:00
|
|
|
VALUE _id = (id); \
|
|
|
|
const char * classname; \
|
|
|
|
const char * methodname; \
|
|
|
|
const char * filename; \
|
|
|
|
if (!_klass) { \
|
|
|
|
rb_thread_method_id_and_class((th), &_id, &_klass); \
|
|
|
|
} \
|
2012-12-01 06:13:06 +04:00
|
|
|
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__"); \
|
|
|
|
} \
|
2012-12-01 19:25:28 +04:00
|
|
|
switch (TYPE(_klass)) { \
|
2012-12-01 06:13:06 +04:00
|
|
|
case T_CLASS: \
|
|
|
|
case T_ICLASS: \
|
|
|
|
case T_MODULE: \
|
|
|
|
{ \
|
|
|
|
VALUE _name = rb_class_path_no_cache(_klass); \
|
|
|
|
if (!NIL_P(_name)) { \
|
|
|
|
classname = StringValuePtr(_name); \
|
2012-12-01 19:25:28 +04:00
|
|
|
} \
|
|
|
|
else { \
|
2012-12-01 06:13:06 +04:00
|
|
|
classname = "<unknown>"; \
|
|
|
|
} \
|
|
|
|
methodname = rb_id2name(_id); \
|
|
|
|
filename = rb_sourcefile(); \
|
|
|
|
if (classname && methodname && filename) { \
|
|
|
|
RUBY_DTRACE_##name( \
|
|
|
|
classname, \
|
|
|
|
methodname, \
|
|
|
|
filename, \
|
|
|
|
rb_sourceline()); \
|
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
2012-11-18 20:30:10 +04:00
|
|
|
} \
|
|
|
|
} \
|
2012-12-11 07:37:19 +04:00
|
|
|
} while (0)
|
2012-11-18 20:30:10 +04:00
|
|
|
|
2012-12-01 06:13:06 +04:00
|
|
|
#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)
|
|
|
|
|
2012-11-18 20:30:10 +04:00
|
|
|
#endif /* RUBY_PROBES_HELPER_H */
|