Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Broken ruby-prof output
require 'ruby-prof'
class Bar
def foo(a)
print "foo\n"
a.map do |x|
a = x * x
yield a
end
end
def baz(c)
c
end
end
# Profile the code
result = RubyProf.profile do
Bar.send :define_method, :bar, do |b|
a = 0
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
a = b * b - a
baz(a/b)
end
b = Bar.new
b.foo((1..10000).to_a){|x| b.bar x}
end
# Print a graph profile to text
printer = RubyProf::GraphPrinter.new(result)
printer.print(STDOUT, {})
foo
Thread ID: 15579500
Total Time: 0.365725614
%total %self total self wait child calls Name
--------------------------------------------------------------------------------
100.00% 0.00% 0.37 0.00 0.00 0.37 1 Global#[No method]
0.37 0.00 0.00 0.37 1/1 Bar#foo
0.00 0.00 0.00 0.00 1/1 Enumerable#to_a
0.00 0.00 0.00 0.00 1/1 Class#new
0.00 0.00 0.00 0.00 1/1 Module#define_method
--------------------------------------------------------------------------------
0.37 0.00 0.00 0.37 1/1 Global#[No method]
99.88% 0.00% 0.37 0.00 0.00 0.37 1 Bar#foo
0.37 0.36 0.00 0.01 1/1 Array#map
0.00 0.00 0.00 0.00 1/1 Kernel#print
--------------------------------------------------------------------------------
0.37 0.36 0.00 0.01 1/1 Bar#foo
99.87% 98.31% 0.37 0.36 0.00 0.01 1 Array#map
0.01 0.01 0.00 0.00 10000/10000 Bar#baz
--------------------------------------------------------------------------------
0.01 0.01 0.00 0.00 10000/10000 Array#map
1.56% 1.56% 0.01 0.01 0.00 0.00 10000 Bar#baz
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Global#[No method]
0.11% 0.00% 0.00 0.00 0.00 0.00 1 Enumerable#to_a
0.00 0.00 0.00 0.00 1/1 Range#each
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Enumerable#to_a
0.11% 0.11% 0.00 0.00 0.00 0.00 1 Range#each
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Bar#foo
0.01% 0.00% 0.00 0.00 0.00 0.00 1 Kernel#print
0.00 0.00 0.00 0.00 1/1 IO#write
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Kernel#print
0.00% 0.00% 0.00 0.00 0.00 0.00 1 IO#write
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Global#[No method]
0.00% 0.00% 0.00 0.00 0.00 0.00 1 Class#new
0.00 0.00 0.00 0.00 1/1 BasicObject#initialize
0.00 0.00 0.00 0.00 1/1 <Class::BasicObject>#allocate
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Global#[No method]
0.00% 0.00% 0.00 0.00 0.00 0.00 1 Module#define_method
0.00 0.00 0.00 0.00 1/1 Module#method_added
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Class#new
0.00% 0.00% 0.00 0.00 0.00 0.00 1 BasicObject#initialize
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Class#new
0.00% 0.00% 0.00 0.00 0.00 0.00 1 <Class::BasicObject>#allocate
--------------------------------------------------------------------------------
0.00 0.00 0.00 0.00 1/1 Module#define_method
0.00% 0.00% 0.00 0.00 0.00 0.00 1 Module#method_added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.