Class: RubyProf::CallTreePrinter
Overview
Generate profiling information in callgrind format for use by kcachegrind and similar tools.
Note: when profiling for a callgrind printer, one should use the merge_fibers: true option when creating the profile. Otherwise each fiber would appear as a separate profile.
Class Method Summary
collapse
Instance Method Summary
collapse
#editor_uri, #initialize, #method_name, #min_percent, #print_file, #print_footer, #print_header, #setup_options, #sort_method
Class Method Details
.needs_dir? ⇒ Boolean
91
92
93
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 91
def self.needs_dir?
true
end
|
Instance Method Details
#base_name ⇒ Object
95
96
97
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 95
def base_name
@options[:profile] || "profile"
end
|
#convert(value) ⇒ Object
70
71
72
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 70
def convert(value)
(value * @value_scale).round
end
|
#determine_event_specification_and_value_scale ⇒ Object
#file(method) ⇒ Object
74
75
76
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 74
def file(method)
File.expand_path(method.source_file)
end
|
#file_name_for_thread(thread) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 105
def file_name_for_thread(thread)
if thread.fiber_id == Fiber.current.object_id
[base_name, "callgrind.out", $$].join(".")
else
[base_name, "callgrind.out", $$, thread.fiber_id].join(".")
end
end
|
#file_path_for_thread(thread) ⇒ Object
113
114
115
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 113
def file_path_for_thread(thread)
File.join(path, file_name_for_thread(thread))
end
|
#path ⇒ Object
87
88
89
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 87
def path
@options[:path] || "."
end
|
#print(options = {}) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 46
def print(options = {})
validate_print_params(options)
setup_options(options)
determine_event_specification_and_value_scale
print_threads
end
|
117
118
119
120
121
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 117
def (output, thread)
output << "#{@event_specification}\n\n"
end
|
#print_method(output, method) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 123
def print_method(output, method)
output << "fl=#{file(method)}\n"
output << "fn=#{method.calltree_name}\n"
output << "#{method.line} #{convert(method.self_time)}\n"
method.children.each do |callee|
output << "cfl=#{file(callee.target)}\n"
output << "cfn=#{callee.target.calltree_name}\n"
output << "calls=#{callee.called} #{callee.line}\n"
output << "#{callee.line} #{convert(callee.total_time)}\n"
end
output << "\n"
end
|
#print_thread(thread) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 78
def print_thread(thread)
File.open(file_path_for_thread(thread), "w") do |f|
(f, thread)
thread.methods.reverse_each do |method|
print_method(f, method)
end
end
end
|
#print_threads ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 61
def print_threads
remove_subsidiary_files_from_previous_profile_runs
@result.threads.each do |thread|
print_thread(thread)
end
end
|
#remove_subsidiary_files_from_previous_profile_runs ⇒ Object
99
100
101
102
103
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 99
def remove_subsidiary_files_from_previous_profile_runs
pattern = [base_name, "callgrind.out", $$, "*"].join(".")
files = Dir.glob(File.join(path, pattern))
FileUtils.rm_f(files)
end
|
#validate_print_params(options) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/ruby-prof/printers/call_tree_printer.rb', line 53
def validate_print_params(options)
if options.is_a?(IO)
raise ArgumentError, "#{self.class.name}#print cannot print to IO objects"
elsif !options.is_a?(Hash)
raise ArgumentError, "#{self.class.name}#print requires an options hash"
end
end
|