Ruby  2.0.0p247(2013-06-27revision41674)
probes_helper.h
Go to the documentation of this file.
00001 #ifndef RUBY_PROBES_HELPER_H
00002 #define RUBY_PROBES_HELPER_H
00003 
00004 #include "ruby/ruby.h"
00005 #include "probes.h"
00006 
00007 VALUE rb_class_path_no_cache(VALUE _klass);
00008 
00009 #define RUBY_DTRACE_HOOK(name, th, klazz, id) \
00010 do { \
00011     if (RUBY_DTRACE_##name##_ENABLED()) { \
00012         VALUE _klass = (klazz); \
00013         VALUE _id = (id); \
00014         const char * classname; \
00015         const char * methodname; \
00016         const char * filename; \
00017         if (!_klass) { \
00018             rb_thread_method_id_and_class((th), &_id, &_klass); \
00019         } \
00020         if (_klass) { \
00021             if (RB_TYPE_P(_klass, T_ICLASS)) { \
00022                 _klass = RBASIC(_klass)->klass; \
00023             } \
00024             else if (FL_TEST(_klass, FL_SINGLETON)) { \
00025                 _klass = rb_iv_get(_klass, "__attached__"); \
00026             } \
00027             switch (TYPE(_klass)) { \
00028                 case T_CLASS: \
00029                 case T_ICLASS: \
00030                 case T_MODULE: \
00031                 { \
00032                     VALUE _name = rb_class_path_no_cache(_klass); \
00033                     if (!NIL_P(_name)) { \
00034                         classname = StringValuePtr(_name); \
00035                     } \
00036                     else {                       \
00037                         classname = "<unknown>"; \
00038                     } \
00039                     methodname = rb_id2name(_id); \
00040                     filename   = rb_sourcefile(); \
00041                     if (classname && methodname && filename) { \
00042                         RUBY_DTRACE_##name( \
00043                                 classname, \
00044                                 methodname, \
00045                                 filename, \
00046                                 rb_sourceline()); \
00047                     } \
00048                     break; \
00049                 } \
00050             } \
00051         } \
00052     } \
00053 } while (0)
00054 
00055 #define RUBY_DTRACE_METHOD_ENTRY_HOOK(th, klass, id) \
00056     RUBY_DTRACE_HOOK(METHOD_ENTRY, th, klass, id)
00057 
00058 #define RUBY_DTRACE_METHOD_RETURN_HOOK(th, klass, id) \
00059     RUBY_DTRACE_HOOK(METHOD_RETURN, th, klass, id)
00060 
00061 #define RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, klass, id) \
00062     RUBY_DTRACE_HOOK(CMETHOD_ENTRY, th, klass, id)
00063 
00064 #define RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, klass, id) \
00065     RUBY_DTRACE_HOOK(CMETHOD_RETURN, th, klass, id)
00066 
00067 #endif /* RUBY_PROBES_HELPER_H */
00068