ext/ruby_prof.c in ruby-prof-0.7.6 vs ext/ruby_prof.c in ruby-prof-0.7.7

- old
+ new

@@ -47,10 +47,11 @@ hierarchy in ruby - which is very helpful for creating call graphs. */ #include "ruby_prof.h" #include <stdio.h> +#include <assert.h> /* ================ Helper Functions =================*/ static VALUE figure_singleton_name(VALUE klass) { @@ -1029,10 +1030,15 @@ st_foreach(threads_tbl, pop_frames, (st_data_t) &now); } #ifdef RUBY_VM +void prof_install_hook(); +void prof_remove_hook(); +#endif + +#ifdef RUBY_VM static void prof_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE klass) #else static void prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE klass) @@ -1048,10 +1054,11 @@ #ifdef RUBY_VM if (event != RUBY_EVENT_C_CALL && event != RUBY_EVENT_C_RETURN) { rb_frame_method_id_and_class(&mid, &klass); } + #endif #ifdef DEBUG /* This code is here for debug purposes - uncomment it out when debugging to see a print out of exactly what the @@ -1094,10 +1101,16 @@ now = get_measurement(); /* Get the current thread information. */ thread = rb_thread_current(); thread_id = rb_obj_id(thread); + +#ifdef RUBY_VM + /* ensure that new threads are hooked [sigh] */ + prof_remove_hook(); + prof_install_hook(); +#endif if (exclude_threads_tbl && st_lookup(exclude_threads_tbl, (st_data_t) thread_id, 0)) { return; @@ -1147,21 +1160,23 @@ #else method = get_method(event, node, klass, mid, 0, thread_data->method_table); #endif /* Check for a recursive call */ - while (method->active) + while (method->active) // it's while because if you replace this while with an if, the assertion fails... [ltodo figure out why] { /* Yes, this method is already active */ #ifdef RUBY_VM method = get_method(event, klass, mid, method->key->depth + 1, thread_data->method_table); #else method = get_method(event, node, klass, mid, method->key->depth + 1, thread_data->method_table); #endif } + assert(!method->active); + method->active = 1; - + if (!frame) { call_info = prof_call_info_create(method, NULL); prof_add_call_info(method->call_infos, call_info); @@ -1410,10 +1425,10 @@ { #ifdef RUBY_VM rb_add_event_hook(prof_event_hook, RUBY_EVENT_CALL | RUBY_EVENT_RETURN | RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN - | RUBY_EVENT_LINE | RUBY_EVENT_SWITCH, Qnil); + | RUBY_EVENT_LINE, Qnil); // | RUBY_EVENT_SWITCH #else rb_add_event_hook(prof_event_hook, RUBY_EVENT_CALL | RUBY_EVENT_RETURN | RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN | RUBY_EVENT_LINE);