Skip to content

Commit

Permalink
better caller tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Jan 18, 2013
1 parent 95dd56d commit ee7766d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 7 additions & 5 deletions ext/rblineprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <ruby.h>
#include <node.h>
#include <env.h>
#include <intern.h>
#include <st.h>
#include <re.h>
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion rblineprof.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
16 changes: 15 additions & 1 deletion test.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
$:.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
4*5*6
7*8*9*10*11*12*13*14*15
2**32
2**128

o = Obj.new
o.inner_block
o.another
end

def outer
Expand All @@ -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
Expand Down

0 comments on commit ee7766d

Please sign in to comment.