Class: RubyProf::CallTreePrinter
Overview
Generate profiling information in calltree format for use by kcachegrind and similar tools.
Instance Method Summary
collapse
#initialize, #method_name, #min_percent, #print_file, #setup_options
Instance Method Details
#convert(value) ⇒ Object
35
36
37
|
# File 'lib/ruby-prof/call_tree_printer.rb', line 35
def convert(value)
(value * 1000).round
end
|
#file(method) ⇒ Object
39
40
41
|
# File 'lib/ruby-prof/call_tree_printer.rb', line 39
def file(method)
File.expand_path(method.source_file)
end
|
#name(method) ⇒ Object
43
44
45
|
# File 'lib/ruby-prof/call_tree_printer.rb', line 43
def name(method)
"#{method.klass_name}::#{method.method_name}"
end
|
#print(output = STDOUT, options = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ruby-prof/call_tree_printer.rb', line 8
def print(output = STDOUT, options = {})
@output = output
setup_options(options)
@output << "events: "
case RubyProf.measure_mode
when RubyProf::PROCESS_TIME
@output << 'process_time'
when RubyProf::WALL_TIME
@output << 'wall_time'
when RubyProf::CPU_TIME
@output << 'cpu_time'
when RubyProf::ALLOCATIONS
@output << 'allocations'
end
@output << "\n\n"
print_threads
end
|
#print_methods(thread_id, methods) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/ruby-prof/call_tree_printer.rb', line 47
def print_methods(thread_id, methods)
methods.reverse_each do |method|
@output << "fl=#{file(method)}\n"
@output << "fn=#{name(method)}\n"
@output << "#{method.line} #{convert(method.self_time)}\n"
method.children.each do |callee|
@output << "cfl=#{file(callee.target)}\n"
@output << "cfn=#{name(callee.target)}\n"
@output << "calls=#{callee.called} #{callee.line}\n"
@output << "#{callee.line} #{convert(callee.total_time)}\n"
end
@output << "\n"
end
end
|
#print_threads ⇒ Object
29
30
31
32
33
|
# File 'lib/ruby-prof/call_tree_printer.rb', line 29
def print_threads
@result.threads.each do |thread_id, methods|
print_methods(thread_id ,methods)
end
end
|