diff --git a/eval.c b/eval.c index e7f95deadb..cd1f78047c 100644 --- a/eval.c +++ b/eval.c @@ -560,11 +560,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause) } if (tag != TAG_FATAL) { - if (RUBY_DTRACE_RAISE_ENABLED()) { - RUBY_DTRACE_RAISE(rb_obj_classname(th->errinfo), - rb_sourcefile(), - rb_sourceline()); - } + RUBY_DTRACE_HOOK(RAISE, rb_obj_classname(th->errinfo)); EXEC_EVENT_HOOK(th, RUBY_EVENT_RAISE, th->cfp->self, 0, 0, mesg); } } diff --git a/gc.c b/gc.c index fcfd53da49..1f8c84967f 100644 --- a/gc.c +++ b/gc.c @@ -8414,12 +8414,12 @@ gc_prof_timer_stop(rb_objspace_t *objspace) } } +#define RUBY_DTRACE_GC_HOOK(name) \ + do {if (RUBY_DTRACE_GC_##name##_ENABLED()) RUBY_DTRACE_GC_##name();} while (0) static inline void gc_prof_mark_timer_start(rb_objspace_t *objspace) { - if (RUBY_DTRACE_GC_MARK_BEGIN_ENABLED()) { - RUBY_DTRACE_GC_MARK_BEGIN(); - } + RUBY_DTRACE_GC_HOOK(MARK_BEGIN); #if GC_PROFILE_MORE_DETAIL if (gc_prof_enabled(objspace)) { gc_prof_record(objspace)->gc_mark_time = getrusage_time(); @@ -8430,9 +8430,7 @@ gc_prof_mark_timer_start(rb_objspace_t *objspace) static inline void gc_prof_mark_timer_stop(rb_objspace_t *objspace) { - if (RUBY_DTRACE_GC_MARK_END_ENABLED()) { - RUBY_DTRACE_GC_MARK_END(); - } + RUBY_DTRACE_GC_HOOK(MARK_END); #if GC_PROFILE_MORE_DETAIL if (gc_prof_enabled(objspace)) { gc_profile_record *record = gc_prof_record(objspace); @@ -8444,9 +8442,7 @@ gc_prof_mark_timer_stop(rb_objspace_t *objspace) static inline void gc_prof_sweep_timer_start(rb_objspace_t *objspace) { - if (RUBY_DTRACE_GC_SWEEP_BEGIN_ENABLED()) { - RUBY_DTRACE_GC_SWEEP_BEGIN(); - } + RUBY_DTRACE_GC_HOOK(SWEEP_BEGIN); if (gc_prof_enabled(objspace)) { gc_profile_record *record = gc_prof_record(objspace); @@ -8459,9 +8455,7 @@ gc_prof_sweep_timer_start(rb_objspace_t *objspace) static inline void gc_prof_sweep_timer_stop(rb_objspace_t *objspace) { - if (RUBY_DTRACE_GC_SWEEP_END_ENABLED()) { - RUBY_DTRACE_GC_SWEEP_END(); - } + RUBY_DTRACE_GC_HOOK(SWEEP_END); if (gc_prof_enabled(objspace)) { double sweep_time; diff --git a/internal.h b/internal.h index 163fb65041..d135035607 100644 --- a/internal.h +++ b/internal.h @@ -1341,12 +1341,14 @@ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0) RUBY_SYMBOL_EXPORT_END #define RUBY_DTRACE_CREATE_HOOK(name, arg) \ + RUBY_DTRACE_HOOK(name##_CREATE, arg) +#define RUBY_DTRACE_HOOK(name, arg) \ do { \ - if (UNLIKELY(RUBY_DTRACE_##name##_CREATE_ENABLED())) { \ + if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \ int dtrace_line; \ const char *dtrace_file = rb_source_loc(&dtrace_line); \ if (!dtrace_file) dtrace_file = ""; \ - RUBY_DTRACE_##name##_CREATE(arg, dtrace_file, dtrace_line); \ + RUBY_DTRACE_##name(arg, dtrace_file, dtrace_line); \ } \ } while (0) diff --git a/load.c b/load.c index 0a8aedaa4d..3f5e143084 100644 --- a/load.c +++ b/load.c @@ -698,11 +698,7 @@ rb_f_load(int argc, VALUE *argv) rb_scan_args(argc, argv, "11", &fname, &wrap); - if (RUBY_DTRACE_LOAD_ENTRY_ENABLED()) { - RUBY_DTRACE_LOAD_ENTRY(StringValuePtr(fname), - rb_sourcefile(), - rb_sourceline()); - } + RUBY_DTRACE_HOOK(LOAD_ENTRY, StringValuePtr(fname)); orig_fname = FilePathValue(fname); fname = rb_str_encode_ospath(orig_fname); @@ -714,11 +710,7 @@ rb_f_load(int argc, VALUE *argv) } rb_load_internal(path, RTEST(wrap)); - if (RUBY_DTRACE_LOAD_RETURN_ENABLED()) { - RUBY_DTRACE_LOAD_RETURN(StringValuePtr(fname), - rb_sourcefile(), - rb_sourceline()); - } + RUBY_DTRACE_HOOK(LOAD_RETURN, StringValuePtr(fname)); return Qtrue; } @@ -967,11 +959,7 @@ rb_require_internal(VALUE fname, int safe) } volatile saved; char *volatile ftptr = 0; - if (RUBY_DTRACE_REQUIRE_ENTRY_ENABLED()) { - RUBY_DTRACE_REQUIRE_ENTRY(StringValuePtr(fname), - rb_sourcefile(), - rb_sourceline()); - } + RUBY_DTRACE_HOOK(REQUIRE_ENTRY, StringValuePtr(fname)); TH_PUSH_TAG(th); saved.safe = rb_safe_level(); @@ -984,20 +972,12 @@ rb_require_internal(VALUE fname, int safe) FilePathValue(fname); rb_set_safe_level_force(0); - if (RUBY_DTRACE_FIND_REQUIRE_ENTRY_ENABLED()) { - RUBY_DTRACE_FIND_REQUIRE_ENTRY(StringValuePtr(fname), - rb_sourcefile(), - rb_sourceline()); - } + RUBY_DTRACE_HOOK(FIND_REQUIRE_ENTRY, StringValuePtr(fname)); path = rb_str_encode_ospath(fname); found = search_required(path, &path, safe); - if (RUBY_DTRACE_FIND_REQUIRE_RETURN_ENABLED()) { - RUBY_DTRACE_FIND_REQUIRE_RETURN(StringValuePtr(fname), - rb_sourcefile(), - rb_sourceline()); - } + RUBY_DTRACE_HOOK(FIND_REQUIRE_RETURN, StringValuePtr(fname)); if (found) { if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) { result = 0; @@ -1036,11 +1016,7 @@ rb_require_internal(VALUE fname, int safe) th->errinfo = errinfo; - if (RUBY_DTRACE_REQUIRE_RETURN_ENABLED()) { - RUBY_DTRACE_REQUIRE_RETURN(StringValuePtr(fname), - rb_sourcefile(), - rb_sourceline()); - } + RUBY_DTRACE_HOOK(REQUIRE_RETURN, StringValuePtr(fname)); return result; } diff --git a/parse.y b/parse.y index ca64942cb3..4f3d9554b4 100644 --- a/parse.y +++ b/parse.y @@ -5520,17 +5520,15 @@ yycompile0(VALUE arg) parser->token_info_enabled = !compile_for_eval && RTEST(ruby_verbose); #endif #ifndef RIPPER - if (RUBY_DTRACE_PARSE_BEGIN_ENABLED()) { - RUBY_DTRACE_PARSE_BEGIN(ruby_sourcefile, - ruby_sourceline); +#define RUBY_DTRACE_PARSE_HOOK(name) \ + if (RUBY_DTRACE_PARSE_##name##_ENABLED()) { \ + RUBY_DTRACE_PARSE_##name(ruby_sourcefile, ruby_sourceline); \ } + RUBY_DTRACE_PARSE_HOOK(BEGIN); #endif n = yyparse((void*)parser); #ifndef RIPPER - if (RUBY_DTRACE_PARSE_END_ENABLED()) { - RUBY_DTRACE_PARSE_END(ruby_sourcefile, - ruby_sourceline); - } + RUBY_DTRACE_PARSE_HOOK(END); #endif ruby_debug_lines = 0; ruby_coverage = 0; diff --git a/vm_method.c b/vm_method.c index 1e57176fcf..7d658b003e 100644 --- a/vm_method.c +++ b/vm_method.c @@ -85,9 +85,7 @@ rb_clear_method_cache_by_class(VALUE klass) if (klass && klass != Qundef) { int global = klass == rb_cBasicObject || klass == rb_cObject || klass == rb_mKernel; - if (RUBY_DTRACE_METHOD_CACHE_CLEAR_ENABLED()) { - RUBY_DTRACE_METHOD_CACHE_CLEAR(global ? "global" : rb_class2name(klass), rb_sourcefile(), rb_sourceline()); - } + RUBY_DTRACE_HOOK(METHOD_CACHE_CLEAR, (global ? "global" : rb_class2name(klass))); if (global) { INC_GLOBAL_METHOD_STATE();