Skip to content

Commit

Permalink
internal.h: RUBY_DTRACE_HOOK
Browse files Browse the repository at this point in the history
* internal.h (RUBY_DTRACE_HOOK): extract from
  RUBY_DTRACE_CREATE_HOOK for other type hooks.

* gc.c (RUBY_DTRACE_GC_HOOK): ditto.

* parse.y (RUBY_DTRACE_PARSE_HOOK): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Oct 31, 2015
1 parent 1546ffe commit 9d64a54
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 59 deletions.
6 changes: 1 addition & 5 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
18 changes: 6 additions & 12 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
36 changes: 6 additions & 30 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 5 additions & 7 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions vm_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9d64a54

Please sign in to comment.