ruby-prof 0.13.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES +579 -371
- data/LICENSE +24 -23
- data/README.rdoc +5 -433
- data/Rakefile +98 -110
- data/bin/ruby-prof +328 -329
- data/bin/ruby-prof-check-trace +45 -0
- data/ext/ruby_prof/extconf.rb +16 -59
- data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
- data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
- data/ext/ruby_prof/rp_allocation.c +287 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_tree.c +369 -0
- data/ext/ruby_prof/rp_call_tree.h +43 -0
- data/ext/ruby_prof/rp_call_trees.c +288 -0
- data/ext/ruby_prof/rp_call_trees.h +28 -0
- data/ext/ruby_prof/rp_measure_allocations.c +50 -65
- data/ext/ruby_prof/rp_measure_memory.c +42 -73
- data/ext/ruby_prof/rp_measure_process_time.c +65 -71
- data/ext/ruby_prof/rp_measure_wall_time.c +64 -42
- data/ext/ruby_prof/rp_measurement.c +237 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +491 -420
- data/ext/ruby_prof/rp_method.h +62 -57
- data/ext/ruby_prof/rp_profile.c +908 -0
- data/ext/ruby_prof/rp_profile.h +35 -0
- data/ext/ruby_prof/rp_stack.c +212 -128
- data/ext/ruby_prof/rp_stack.h +53 -51
- data/ext/ruby_prof/rp_thread.c +362 -268
- data/ext/ruby_prof/rp_thread.h +39 -27
- data/ext/ruby_prof/ruby_prof.c +52 -695
- data/ext/ruby_prof/ruby_prof.h +26 -55
- data/ext/ruby_prof/vc/ruby_prof.sln +28 -21
- data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +56 -8
- data/lib/ruby-prof.rb +52 -67
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
- data/lib/ruby-prof/call_tree.rb +57 -0
- data/lib/ruby-prof/call_tree_visitor.rb +36 -0
- data/lib/ruby-prof/compatibility.rb +99 -169
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +17 -0
- data/lib/ruby-prof/method_info.rb +78 -131
- data/lib/ruby-prof/printers/abstract_printer.rb +137 -85
- data/lib/ruby-prof/printers/call_info_printer.rb +53 -41
- data/lib/ruby-prof/printers/call_stack_printer.rb +180 -773
- data/lib/ruby-prof/printers/call_tree_printer.rb +151 -92
- data/lib/ruby-prof/printers/dot_printer.rb +132 -132
- data/lib/ruby-prof/printers/flat_printer.rb +53 -69
- data/lib/ruby-prof/printers/graph_html_printer.rb +63 -255
- data/lib/ruby-prof/printers/graph_printer.rb +113 -116
- data/lib/ruby-prof/printers/multi_printer.rb +127 -56
- data/lib/ruby-prof/profile.rb +37 -77
- data/lib/ruby-prof/rack.rb +62 -15
- data/lib/ruby-prof/task.rb +147 -147
- data/lib/ruby-prof/thread.rb +10 -12
- data/lib/ruby-prof/version.rb +3 -0
- data/lib/unprof.rb +10 -10
- data/ruby-prof.gemspec +65 -61
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +126 -0
- data/test/basic_test.rb +43 -128
- data/test/call_tree_visitor_test.rb +32 -0
- data/test/call_trees_test.rb +66 -0
- data/test/duplicate_names_test.rb +32 -32
- data/test/dynamic_method_test.rb +53 -74
- data/test/enumerable_test.rb +21 -16
- data/test/exceptions_test.rb +24 -16
- data/test/exclude_methods_test.rb +151 -0
- data/test/exclude_threads_test.rb +53 -54
- data/test/fiber_test.rb +129 -65
- data/test/gc_test.rb +90 -0
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +158 -71
- data/test/marshal_test.rb +113 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +375 -25
- data/test/measure_allocations_trace_test.rb +375 -0
- data/test/measure_memory_trace_test.rb +1101 -0
- data/test/measure_process_time_test.rb +785 -62
- data/test/measure_times.rb +56 -0
- data/test/measure_wall_time_test.rb +434 -254
- data/test/multi_printer_test.rb +71 -82
- data/test/no_method_class_test.rb +15 -15
- data/test/pause_resume_test.rb +175 -166
- data/test/prime.rb +54 -54
- data/test/prime_script.rb +6 -0
- data/test/printer_call_stack_test.rb +27 -0
- data/test/printer_call_tree_test.rb +30 -0
- data/test/printer_flat_test.rb +99 -0
- data/test/printer_graph_html_test.rb +59 -0
- data/test/printer_graph_test.rb +40 -0
- data/test/printers_test.rb +141 -257
- data/test/printing_recursive_graph_test.rb +81 -0
- data/test/profile_test.rb +16 -0
- data/test/rack_test.rb +93 -0
- data/test/recursive_test.rb +206 -215
- data/test/singleton_test.rb +38 -38
- data/test/stack_printer_test.rb +64 -78
- data/test/start_stop_test.rb +109 -112
- data/test/test_helper.rb +13 -115
- data/test/thread_test.rb +144 -178
- data/test/unique_call_path_test.rb +120 -224
- data/test/yarv_test.rb +56 -0
- metadata +77 -133
- data/doc/LICENSE.html +0 -155
- data/doc/README_rdoc.html +0 -648
- data/doc/Rack.html +0 -167
- data/doc/Rack/RubyProf.html +0 -319
- data/doc/RubyProf.html +0 -1000
- data/doc/RubyProf/AbstractPrinter.html +0 -580
- data/doc/RubyProf/AggregateCallInfo.html +0 -570
- data/doc/RubyProf/CallInfo.html +0 -512
- data/doc/RubyProf/CallInfoPrinter.html +0 -190
- data/doc/RubyProf/CallInfoVisitor.html +0 -332
- data/doc/RubyProf/CallStackPrinter.html +0 -1600
- data/doc/RubyProf/CallTreePrinter.html +0 -413
- data/doc/RubyProf/Cmd.html +0 -669
- data/doc/RubyProf/DotPrinter.html +0 -312
- data/doc/RubyProf/FlatPrinter.html +0 -229
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -267
- data/doc/RubyProf/GraphHtmlPrinter.html +0 -630
- data/doc/RubyProf/GraphPrinter.html +0 -209
- data/doc/RubyProf/MethodInfo.html +0 -713
- data/doc/RubyProf/MultiPrinter.html +0 -407
- data/doc/RubyProf/Profile.html +0 -821
- data/doc/RubyProf/ProfileTask.html +0 -532
- data/doc/RubyProf/Test.html +0 -578
- data/doc/RubyProf/Thread.html +0 -262
- data/doc/created.rid +0 -32
- data/doc/examples/flat_txt.html +0 -191
- data/doc/examples/graph_txt.html +0 -305
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -647
- data/doc/js/darkfish.js +0 -155
- data/doc/js/jquery.js +0 -18
- data/doc/js/navigation.js +0 -142
- data/doc/js/search.js +0 -94
- data/doc/js/search_index.js +0 -1
- data/doc/js/searcher.js +0 -228
- data/doc/rdoc.css +0 -543
- data/doc/table_of_contents.html +0 -462
- data/examples/empty.png +0 -0
- data/examples/flat.txt +0 -55
- data/examples/graph.dot +0 -106
- data/examples/graph.html +0 -823
- data/examples/graph.png +0 -0
- data/examples/graph.txt +0 -170
- data/examples/minus.png +0 -0
- data/examples/multi.flat.txt +0 -23
- data/examples/multi.graph.html +0 -906
- data/examples/multi.grind.dat +0 -194
- data/examples/multi.stack.html +0 -573
- data/examples/plus.png +0 -0
- data/examples/stack.html +0 -573
- data/ext/ruby_prof/rp_call_info.c +0 -407
- data/ext/ruby_prof/rp_call_info.h +0 -48
- data/ext/ruby_prof/rp_measure.c +0 -48
- data/ext/ruby_prof/rp_measure.h +0 -45
- data/ext/ruby_prof/rp_measure_cpu_time.c +0 -112
- data/ext/ruby_prof/rp_measure_gc_runs.c +0 -65
- data/ext/ruby_prof/rp_measure_gc_time.c +0 -57
- data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
- data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
- data/ext/ruby_prof/version.h +0 -7
- data/lib/ruby-prof/aggregate_call_info.rb +0 -72
- data/lib/ruby-prof/call_info.rb +0 -89
- data/lib/ruby-prof/call_info_visitor.rb +0 -44
- data/lib/ruby-prof/images/empty.png +0 -0
- data/lib/ruby-prof/images/minus.png +0 -0
- data/lib/ruby-prof/images/plus.png +0 -0
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -57
- data/lib/ruby-prof/test.rb +0 -150
- data/test/aggregate_test.rb +0 -136
- data/test/call_info_test.rb +0 -78
- data/test/call_info_visitor_test.rb +0 -31
- data/test/exec_test.rb +0 -14
- data/test/measure_cpu_time_test.rb +0 -220
- data/test/measure_gc_runs_test.rb +0 -32
- data/test/measure_gc_time_test.rb +0 -36
- data/test/measure_memory_test.rb +0 -31
- data/test/method_elimination_test.rb +0 -84
- data/test/module_test.rb +0 -45
- data/test/stack_test.rb +0 -138
- data/test/test_suite.rb +0 -37
@@ -0,0 +1,17 @@
|
|
1
|
+
module RubyProf
|
2
|
+
# The Measurement class is a helper class used by RubyProf::MethodInfo to store information about the method.
|
3
|
+
# You cannot create a CallTree object directly, they are generated while running a profile.
|
4
|
+
class Measurement
|
5
|
+
def children_time
|
6
|
+
self.total_time - self.self_time - self.wait_time
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
"c: #{called}, tt: #{total_time}, st: #{self_time}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
super + "(#{self.to_s})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,131 +1,78 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module RubyProf
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def recursive?
|
80
|
-
call_infos.detect do |call_info|
|
81
|
-
call_info.recursive
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def children
|
86
|
-
@children ||= begin
|
87
|
-
call_infos.map do |call_info|
|
88
|
-
call_info.children
|
89
|
-
end.flatten
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def aggregate_parents
|
94
|
-
# Group call info's based on their parents
|
95
|
-
groups = self.call_infos.inject(Hash.new) do |hash, call_info|
|
96
|
-
key = call_info.parent ? call_info.parent.target : self
|
97
|
-
(hash[key] ||= []) << call_info
|
98
|
-
hash
|
99
|
-
end
|
100
|
-
|
101
|
-
groups.map do |key, value|
|
102
|
-
AggregateCallInfo.new(value)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def aggregate_children
|
107
|
-
# Group call info's based on their targets
|
108
|
-
groups = self.children.inject(Hash.new) do |hash, call_info|
|
109
|
-
key = call_info.target
|
110
|
-
(hash[key] ||= []) << call_info
|
111
|
-
hash
|
112
|
-
end
|
113
|
-
|
114
|
-
groups.map do |key, value|
|
115
|
-
AggregateCallInfo.new(value)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def to_s
|
120
|
-
"#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, ct: #{self.children_time})"
|
121
|
-
end
|
122
|
-
|
123
|
-
# remove method from the call graph. should not be called directly.
|
124
|
-
def eliminate!
|
125
|
-
# $stderr.puts "eliminating #{self}"
|
126
|
-
call_infos.each{ |call_info| call_info.eliminate! }
|
127
|
-
call_infos.clear
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RubyProf
|
4
|
+
# The MethodInfo class is used to track information about each method that is profiled.
|
5
|
+
# You cannot create a MethodInfo object directly, they are generated while running a profile.
|
6
|
+
class MethodInfo
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
# Returns the full name of a class. The interpretation of method names is:
|
10
|
+
#
|
11
|
+
# * MyObject#test - An method defined in a class
|
12
|
+
# * <Class:MyObject>#test - A method defined in a singleton class.
|
13
|
+
# * <Module:MyObject>#test - A method defined in a singleton module.
|
14
|
+
# * <Object:MyObject>#test - A method defined in a singleton object.
|
15
|
+
def full_name
|
16
|
+
decorated_class_name = case self.klass_flags
|
17
|
+
when 0x2
|
18
|
+
"<Class::#{klass_name}>"
|
19
|
+
when 0x4
|
20
|
+
"<Module::#{klass_name}>"
|
21
|
+
when 0x8
|
22
|
+
"<Object::#{klass_name}>"
|
23
|
+
else
|
24
|
+
klass_name
|
25
|
+
end
|
26
|
+
|
27
|
+
"#{decorated_class_name}##{method_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
# The number of times this method was called
|
31
|
+
def called
|
32
|
+
self.measurement.called
|
33
|
+
end
|
34
|
+
|
35
|
+
# The total time this method took - includes self time + wait time + child time
|
36
|
+
def total_time
|
37
|
+
self.measurement.total_time
|
38
|
+
end
|
39
|
+
|
40
|
+
# The time this method took to execute
|
41
|
+
def self_time
|
42
|
+
self.measurement.self_time
|
43
|
+
end
|
44
|
+
|
45
|
+
# The time this method waited for other fibers/threads to execute
|
46
|
+
def wait_time
|
47
|
+
self.measurement.wait_time
|
48
|
+
end
|
49
|
+
|
50
|
+
# The time this method's children took to execute
|
51
|
+
def children_time
|
52
|
+
self.total_time - self.self_time - self.wait_time
|
53
|
+
end
|
54
|
+
|
55
|
+
# :enddoc:
|
56
|
+
def <=>(other)
|
57
|
+
if other.nil?
|
58
|
+
-1
|
59
|
+
elsif self.full_name == other.full_name
|
60
|
+
0
|
61
|
+
elsif self.total_time < other.total_time
|
62
|
+
-1
|
63
|
+
elsif self.total_time > other.total_time
|
64
|
+
1
|
65
|
+
elsif self.call_trees.min_depth < other.call_trees.min_depth
|
66
|
+
1
|
67
|
+
elsif self.call_trees.min_depth > other.call_trees.min_depth
|
68
|
+
-1
|
69
|
+
else
|
70
|
+
self.full_name <=> other.full_name
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_s
|
75
|
+
"#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, wt: #{wait_time}, ct: #{self.children_time})"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,85 +1,137 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module RubyProf
|
4
|
-
class
|
5
|
-
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
def sort_method
|
42
|
-
@options[:sort_method]
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RubyProf
|
4
|
+
# This is the base class for all Printers. It is never used directly.
|
5
|
+
class AbstractPrinter
|
6
|
+
# :stopdoc:
|
7
|
+
def self.needs_dir?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
# :startdoc:
|
11
|
+
|
12
|
+
# Create a new printer.
|
13
|
+
#
|
14
|
+
# result should be the output generated from a profiling run
|
15
|
+
def initialize(result)
|
16
|
+
@result = result
|
17
|
+
@output = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the min_percent of time a method must take to be included in a profiling report
|
21
|
+
def min_percent
|
22
|
+
@options[:min_percent] || 0
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the max_percent of time a method can take to be included in a profiling report
|
26
|
+
def max_percent
|
27
|
+
@options[:max_percent] || 100
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the method to filter methods by (when using min_percent and max_percent)
|
31
|
+
def filter_by
|
32
|
+
@options[:filter_by] || :self_time
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the time format used to show when a profile was run
|
36
|
+
def time_format
|
37
|
+
'%A, %B %-d at %l:%M:%S %p (%Z)'
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns how profile data should be sorted
|
41
|
+
def sort_method
|
42
|
+
@options[:sort_method]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Prints a report to the provided output.
|
46
|
+
#
|
47
|
+
# output - Any IO object, including STDOUT or a file.
|
48
|
+
# The default value is STDOUT.
|
49
|
+
#
|
50
|
+
# options - Hash of print options. Note that each printer can
|
51
|
+
# define its own set of options.
|
52
|
+
#
|
53
|
+
# :min_percent - Number 0 to 100 that specifes the minimum
|
54
|
+
# %self (the methods self time divided by the
|
55
|
+
# overall total time) that a method must take
|
56
|
+
# for it to be printed out in the report.
|
57
|
+
# Default value is 0.
|
58
|
+
#
|
59
|
+
# :sort_method - Specifies method used for sorting method infos.
|
60
|
+
# Available values are :total_time, :self_time,
|
61
|
+
# :wait_time, :children_time
|
62
|
+
# Default value is :total_time
|
63
|
+
def print(output = STDOUT, options = {})
|
64
|
+
@output = output
|
65
|
+
setup_options(options)
|
66
|
+
print_threads
|
67
|
+
end
|
68
|
+
|
69
|
+
# :nodoc:
|
70
|
+
def setup_options(options = {})
|
71
|
+
@options = options
|
72
|
+
end
|
73
|
+
|
74
|
+
def method_location(method)
|
75
|
+
if method.source_file
|
76
|
+
"#{method.source_file}:#{method.line}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def method_href(thread, method)
|
81
|
+
h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s)
|
82
|
+
end
|
83
|
+
|
84
|
+
def open_asset(file)
|
85
|
+
path = File.join(File.expand_path('../../assets', __FILE__), file)
|
86
|
+
File.open(path, 'rb').read
|
87
|
+
end
|
88
|
+
|
89
|
+
def print_threads
|
90
|
+
@result.threads.each do |thread|
|
91
|
+
print_thread(thread)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def print_thread(thread)
|
96
|
+
print_header(thread)
|
97
|
+
print_methods(thread)
|
98
|
+
print_footer(thread)
|
99
|
+
end
|
100
|
+
|
101
|
+
def print_header(thread)
|
102
|
+
@output << "Measure Mode: %s\n" % @result.measure_mode_string
|
103
|
+
@output << "Thread ID: %d\n" % thread.id
|
104
|
+
@output << "Fiber ID: %d\n" % thread.fiber_id unless thread.id == thread.fiber_id
|
105
|
+
@output << "Total: %0.6f\n" % thread.total_time
|
106
|
+
@output << "Sort by: #{sort_method}\n"
|
107
|
+
@output << "\n"
|
108
|
+
print_column_headers
|
109
|
+
end
|
110
|
+
|
111
|
+
def print_column_headers
|
112
|
+
end
|
113
|
+
|
114
|
+
def print_footer(thread)
|
115
|
+
@output << <<~EOT
|
116
|
+
|
117
|
+
* recursively called methods
|
118
|
+
|
119
|
+
Columns are:
|
120
|
+
|
121
|
+
%self - The percentage of time spent in this method, derived from self_time/total_time.
|
122
|
+
total - The time spent in this method and its children.
|
123
|
+
self - The time spent in this method.
|
124
|
+
wait - The amount of time this method waited for other threads.
|
125
|
+
child - The time spent in this method's children.
|
126
|
+
calls - The number of times this method was called.
|
127
|
+
name - The name of the method.
|
128
|
+
location - The location of the method.
|
129
|
+
|
130
|
+
The interpretation of method names is:
|
131
|
+
|
132
|
+
* MyObject#test - An instance method "test" of the class "MyObject"
|
133
|
+
* <Object:MyObject>#test - The <> characters indicate a method on a singleton class.
|
134
|
+
EOT
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -1,41 +1,53 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module RubyProf
|
4
|
-
# Prints out the call graph based on
|
5
|
-
# is mainly for debugging purposes as it provides access into
|
6
|
-
# into RubyProf's internals.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@output << "
|
36
|
-
@output <<
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RubyProf
|
4
|
+
# Prints out the call graph based on CallTree instances. This
|
5
|
+
# is mainly for debugging purposes as it provides access into
|
6
|
+
# into RubyProf's internals.
|
7
|
+
#
|
8
|
+
# To use the printer:
|
9
|
+
#
|
10
|
+
# result = RubyProf.profile do
|
11
|
+
# [code to profile]
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# printer = RubyProf::CallInfoPrinter.new(result)
|
15
|
+
# printer.print(STDOUT)
|
16
|
+
class CallInfoPrinter < AbstractPrinter
|
17
|
+
TIME_WIDTH = 0
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def print_header(thread)
|
22
|
+
@output << "----------------------------------------------------\n"
|
23
|
+
@output << "Thread ID: #{thread.id}\n"
|
24
|
+
@output << "Fiber ID: #{thread.fiber_id}\n"
|
25
|
+
@output << "Total Time: #{thread.total_time}\n"
|
26
|
+
@output << "Sort by: #{sort_method}\n"
|
27
|
+
@output << "\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
def print_methods(thread)
|
31
|
+
visitor = CallTreeVisitor.new(thread.call_tree)
|
32
|
+
|
33
|
+
visitor.visit do |call_tree, event|
|
34
|
+
if event == :enter
|
35
|
+
@output << " " * call_tree.depth
|
36
|
+
@output << call_tree.target.full_name
|
37
|
+
@output << " ("
|
38
|
+
@output << "tt:#{sprintf("%#{TIME_WIDTH}.2f", call_tree.total_time)}, "
|
39
|
+
@output << "st:#{sprintf("%#{TIME_WIDTH}.2f", call_tree.self_time)}, "
|
40
|
+
@output << "wt:#{sprintf("%#{TIME_WIDTH}.2f", call_tree.wait_time)}, "
|
41
|
+
@output << "ct:#{sprintf("%#{TIME_WIDTH}.2f", call_tree.children_time)}, "
|
42
|
+
@output << "call:#{call_tree.called}, "
|
43
|
+
@output << ")"
|
44
|
+
@output << "\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def print_footer(thread)
|
50
|
+
@output << "\n" << "\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|