diff --git a/ext/rblineprof.c b/ext/rblineprof.c index 2169657..61009cd 100644 --- a/ext/rblineprof.c +++ b/ext/rblineprof.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -194,14 +195,15 @@ profiler_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass) * we use ruby_current_node here to get the caller's file/line info, * (as opposed to node, which points to the callee method being invoked) */ - if (!ruby_current_node) return; + NODE *caller_node = ruby_frame->node; + if (!caller_node) return; - file = ruby_current_node->nd_file; - line = nd_line(ruby_current_node); + file = caller_node->nd_file; + line = nd_line(caller_node); if (!file) return; if (line <= 0) return; - if (ruby_current_node->nd_file != node->nd_file) + if (caller_node->nd_file != node->nd_file) srcfile = sourcefile_lookup(file); if (!srcfile) return; /* skip line profiling for this file */ @@ -230,7 +232,7 @@ profiler_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass) else frame = NULL; rblineprof.stack_depth--; - } while (frame && frame->node != node && frame->self != self && frame->mid != mid && frame->klass != klass); + } while (frame && frame->self != self && frame->mid != mid && frame->klass != klass); if (frame) stackframe_record(frame, now); diff --git a/rblineprof.gemspec b/rblineprof.gemspec index 0c7ce2a..2900326 100644 --- a/rblineprof.gemspec +++ b/rblineprof.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'rblineprof' - s.version = '0.2.4' + s.version = '0.2.5' s.homepage = 'http://github.com/tmm1/rblineprof' s.authors = 'Aman Gupta' diff --git a/test.rb b/test.rb index 0cee5c8..f0594bf 100644 --- a/test.rb +++ b/test.rb @@ -1,6 +1,16 @@ $:.unshift 'ext' require 'rblineprof' +class Obj + define_method(:inner_block) do + sleep 0.001 + end + + def another(options={}) + sleep 0.001 + end +end + def inner sleep 0.001 1*2*3 @@ -8,6 +18,10 @@ def inner 7*8*9*10*11*12*13*14*15 2**32 2**128 + + o = Obj.new + o.inner_block + o.another end def outer @@ -27,7 +41,7 @@ def outer File.readlines(__FILE__).each_with_index do |line, num| time, calls = profile[__FILE__][num+1] if calls && calls > 0 - printf "% 8.1fms (% 5d) | %s", time/1000.0, calls, line + printf "% 8.1fms (% 5d) | %s", time/1000.0, calls, line else printf " | %s", line end