ruby-prof 0.13.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,56 +1,127 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module RubyProf
|
4
|
-
# Helper class to simplify printing profiles of several types from
|
5
|
-
# one profiling run. Currently prints a flat profile, a callgrind
|
6
|
-
# profile, a call stack profile and a graph profile.
|
7
|
-
class MultiPrinter
|
8
|
-
def initialize(result)
|
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
|
-
end
|
44
|
-
|
45
|
-
# the name of the
|
46
|
-
def
|
47
|
-
"#{@directory}/#{@profile}.
|
48
|
-
end
|
49
|
-
|
50
|
-
# the name of the
|
51
|
-
def
|
52
|
-
"#{@directory}/#{@profile}.
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RubyProf
|
4
|
+
# Helper class to simplify printing profiles of several types from
|
5
|
+
# one profiling run. Currently prints a flat profile, a callgrind
|
6
|
+
# profile, a call stack profile and a graph profile.
|
7
|
+
class MultiPrinter
|
8
|
+
def initialize(result, printers = [:flat, :graph_html])
|
9
|
+
@flat_printer = FlatPrinter.new(result) if printers.include?(:flat)
|
10
|
+
|
11
|
+
@graph_printer = GraphPrinter.new(result) if printers.include?(:graph)
|
12
|
+
@graph_html_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph_html)
|
13
|
+
|
14
|
+
@tree_printer = CallTreePrinter.new(result) if printers.include?(:tree)
|
15
|
+
@call_info_printer = CallInfoPrinter.new(result) if printers.include?(:call_tree)
|
16
|
+
|
17
|
+
@stack_printer = CallStackPrinter.new(result) if printers.include?(:stack)
|
18
|
+
@dot_printer = DotPrinter.new(result) if printers.include?(:dot)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.needs_dir?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
# create profile files under options[:path] or the current
|
26
|
+
# directory. options[:profile] is used as the base name for the
|
27
|
+
# profile file, defaults to "profile".
|
28
|
+
def print(options)
|
29
|
+
validate_print_params(options)
|
30
|
+
|
31
|
+
@profile = options.delete(:profile) || "profile"
|
32
|
+
@directory = options.delete(:path) || File.expand_path(".")
|
33
|
+
|
34
|
+
print_to_flat(options) if @flat_printer
|
35
|
+
|
36
|
+
print_to_graph(options) if @graph_printer
|
37
|
+
print_to_graph_html(options) if @graph_html_printer
|
38
|
+
|
39
|
+
print_to_stack(options) if @stack_printer
|
40
|
+
print_to_call_info(options) if @call_info_printer
|
41
|
+
print_to_tree(options) if @tree_printer
|
42
|
+
print_to_dot(options) if @dot_printer
|
43
|
+
end
|
44
|
+
|
45
|
+
# the name of the flat profile file
|
46
|
+
def flat_report
|
47
|
+
"#{@directory}/#{@profile}.flat.txt"
|
48
|
+
end
|
49
|
+
|
50
|
+
# the name of the graph profile file
|
51
|
+
def graph_report
|
52
|
+
"#{@directory}/#{@profile}.graph.txt"
|
53
|
+
end
|
54
|
+
|
55
|
+
def graph_html_report
|
56
|
+
"#{@directory}/#{@profile}.graph.html"
|
57
|
+
end
|
58
|
+
|
59
|
+
# the name of the callinfo profile file
|
60
|
+
def call_info_report
|
61
|
+
"#{@directory}/#{@profile}.call_tree.txt"
|
62
|
+
end
|
63
|
+
|
64
|
+
# the name of the callgrind profile file
|
65
|
+
def tree_report
|
66
|
+
"#{@directory}/#{@profile}.callgrind.out.#{$$}"
|
67
|
+
end
|
68
|
+
|
69
|
+
# the name of the call stack profile file
|
70
|
+
def stack_report
|
71
|
+
"#{@directory}/#{@profile}.stack.html"
|
72
|
+
end
|
73
|
+
|
74
|
+
# the name of the call stack profile file
|
75
|
+
def dot_report
|
76
|
+
"#{@directory}/#{@profile}.dot"
|
77
|
+
end
|
78
|
+
|
79
|
+
def print_to_flat(options)
|
80
|
+
File.open(flat_report, "wb") do |file|
|
81
|
+
@flat_printer.print(file, options)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def print_to_graph(options)
|
86
|
+
File.open(graph_report, "wb") do |file|
|
87
|
+
@graph_printer.print(file, options)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def print_to_graph_html(options)
|
92
|
+
File.open(graph_html_report, "wb") do |file|
|
93
|
+
@graph_html_printer.print(file, options)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def print_to_call_info(options)
|
98
|
+
File.open(call_info_report, "wb") do |file|
|
99
|
+
@call_info_printer.print(file, options)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def print_to_tree(options)
|
104
|
+
@tree_printer.print(options.merge(:path => @directory, :profile => @profile))
|
105
|
+
end
|
106
|
+
|
107
|
+
def print_to_stack(options)
|
108
|
+
File.open(stack_report, "wb") do |file|
|
109
|
+
@stack_printer.print(file, options.merge(:graph => "#{@profile}.graph.html"))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def print_to_dot(options)
|
114
|
+
File.open(dot_report, "wb") do |file|
|
115
|
+
@dot_printer.print(file, options)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def validate_print_params(options)
|
120
|
+
if options.is_a?(IO)
|
121
|
+
raise ArgumentError, "#{self.class.name}#print cannot print to IO objects"
|
122
|
+
elsif !options.is_a?(Hash)
|
123
|
+
raise ArgumentError, "#{self.class.name}#print requires an options hash"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/ruby-prof/profile.rb
CHANGED
@@ -1,77 +1,37 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
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
|
-
def eliminate_methods!(matchers)
|
39
|
-
matchers = read_regexps_from_file(matchers) if matchers.is_a?(String)
|
40
|
-
eliminated = []
|
41
|
-
threads.each do |thread|
|
42
|
-
matchers.each{ |matcher| eliminated.concat(eliminate_methods(thread.methods, matcher)) }
|
43
|
-
end
|
44
|
-
eliminated
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
# read regexps from file
|
50
|
-
def read_regexps_from_file(file_name)
|
51
|
-
matchers = []
|
52
|
-
File.open(file_name).each_line do |l|
|
53
|
-
next if (l =~ /^(#.*|\s*)$/) # emtpy lines and lines starting with #
|
54
|
-
matchers << Regexp.new(l.strip)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# eliminate methods matching matcher
|
59
|
-
def eliminate_methods(methods, matcher)
|
60
|
-
eliminated = []
|
61
|
-
i = 0
|
62
|
-
while i < methods.size
|
63
|
-
method_info = methods[i]
|
64
|
-
method_name = method_info.full_name
|
65
|
-
if matcher === method_name
|
66
|
-
raise "can't eliminate root method" if method_info.root?
|
67
|
-
eliminated << methods.delete_at(i)
|
68
|
-
method_info.eliminate!
|
69
|
-
else
|
70
|
-
i += 1
|
71
|
-
end
|
72
|
-
end
|
73
|
-
eliminated
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'ruby-prof/exclude_common_methods'
|
4
|
+
|
5
|
+
module RubyProf
|
6
|
+
class Profile
|
7
|
+
# :nodoc:
|
8
|
+
def measure_mode_string
|
9
|
+
case self.measure_mode
|
10
|
+
when WALL_TIME
|
11
|
+
"wall_time"
|
12
|
+
when PROCESS_TIME
|
13
|
+
"process_time"
|
14
|
+
when ALLOCATIONS
|
15
|
+
"allocations"
|
16
|
+
when MEMORY
|
17
|
+
"memory"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Hides methods that, when represented as a call graph, have
|
22
|
+
# extremely large in and out degrees and make navigation impossible.
|
23
|
+
def exclude_common_methods!
|
24
|
+
ExcludeCommonMethods.apply!(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def exclude_methods!(mod, *method_or_methods)
|
28
|
+
[method_or_methods].flatten.each do |name|
|
29
|
+
exclude_method!(mod, name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def exclude_singleton_methods!(mod, *method_or_methods)
|
34
|
+
exclude_methods!(mod.singleton_class, *method_or_methods)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/ruby-prof/rack.rb
CHANGED
@@ -7,42 +7,89 @@ module Rack
|
|
7
7
|
@app = app
|
8
8
|
@options = options
|
9
9
|
@options[:min_percent] ||= 1
|
10
|
+
|
10
11
|
@tmpdir = options[:path] || Dir.tmpdir
|
12
|
+
FileUtils.mkdir_p(@tmpdir)
|
13
|
+
|
11
14
|
@printer_klasses = @options[:printers] || {::RubyProf::FlatPrinter => 'flat.txt',
|
12
15
|
::RubyProf::GraphPrinter => 'graph.txt',
|
13
16
|
::RubyProf::GraphHtmlPrinter => 'graph.html',
|
14
17
|
::RubyProf::CallStackPrinter => 'call_stack.html'}
|
15
18
|
|
16
|
-
@skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.css
|
19
|
+
@skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.(css|js|png|jpeg|jpg|gif)$}]
|
20
|
+
@only_paths = options[:only_paths]
|
17
21
|
end
|
18
22
|
|
19
23
|
def call(env)
|
20
24
|
request = Rack::Request.new(env)
|
21
25
|
|
22
|
-
if
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
if should_profile?(request.path)
|
27
|
+
begin
|
28
|
+
result = nil
|
29
|
+
data = ::RubyProf::Profile.profile(profiling_options) do
|
30
|
+
result = @app.call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
path = request.path.gsub('/', '-')
|
34
|
+
path.slice!(0)
|
35
|
+
|
36
|
+
print(data, path)
|
37
|
+
result
|
28
38
|
end
|
39
|
+
else
|
40
|
+
@app.call(env)
|
41
|
+
end
|
42
|
+
end
|
29
43
|
|
30
|
-
|
31
|
-
path.slice!(0)
|
44
|
+
private
|
32
45
|
|
33
|
-
|
34
|
-
|
46
|
+
def should_profile?(path)
|
47
|
+
return false if paths_match?(path, @skip_paths)
|
48
|
+
|
49
|
+
@only_paths ? paths_match?(path, @only_paths) : true
|
50
|
+
end
|
51
|
+
|
52
|
+
def paths_match?(path, paths)
|
53
|
+
paths.any? { |skip_path| skip_path =~ path }
|
54
|
+
end
|
55
|
+
|
56
|
+
def profiling_options
|
57
|
+
options = {}
|
58
|
+
options[:measure_mode] = ::RubyProf.measure_mode
|
59
|
+
options[:exclude_threads] =
|
60
|
+
if @options[:ignore_existing_threads]
|
61
|
+
Thread.list.select{|t| t != Thread.current}
|
62
|
+
else
|
63
|
+
::RubyProf.exclude_threads
|
64
|
+
end
|
65
|
+
if @options[:request_thread_only]
|
66
|
+
options[:include_threads] = [Thread.current]
|
67
|
+
end
|
68
|
+
if @options[:merge_fibers]
|
69
|
+
options[:merge_fibers] = true
|
35
70
|
end
|
71
|
+
options
|
36
72
|
end
|
37
73
|
|
38
74
|
def print(data, path)
|
39
75
|
@printer_klasses.each do |printer_klass, base_name|
|
40
76
|
printer = printer_klass.new(data)
|
41
|
-
|
42
|
-
|
43
|
-
|
77
|
+
|
78
|
+
if base_name.respond_to?(:call)
|
79
|
+
base_name = base_name.call
|
80
|
+
end
|
81
|
+
|
82
|
+
if printer_klass == ::RubyProf::MultiPrinter
|
83
|
+
printer.print(@options.merge(:profile => "#{path}-#{base_name}"))
|
84
|
+
elsif printer_klass == ::RubyProf::CallTreePrinter
|
85
|
+
printer.print(@options.merge(:profile => "#{path}-#{base_name}"))
|
86
|
+
else
|
87
|
+
file_name = ::File.join(@tmpdir, "#{path}-#{base_name}")
|
88
|
+
::File.open(file_name, 'wb') do |file|
|
89
|
+
printer.print(file, @options)
|
90
|
+
end
|
44
91
|
end
|
45
92
|
end
|
46
93
|
end
|
47
94
|
end
|
48
|
-
end
|
95
|
+
end
|
data/lib/ruby-prof/task.rb
CHANGED
@@ -1,147 +1,147 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'rake'
|
5
|
-
require 'rake/testtask'
|
6
|
-
require 'fileutils'
|
7
|
-
|
8
|
-
module RubyProf
|
9
|
-
|
10
|
-
# Define a task library for profiling unit tests with ruby-prof.
|
11
|
-
#
|
12
|
-
# All of the options provided by
|
13
|
-
# the Rake:TestTask are supported except the loader
|
14
|
-
# which is set to ruby-prof. For detailed information
|
15
|
-
# please refer to the Rake:TestTask documentation.
|
16
|
-
#
|
17
|
-
# ruby-prof specific options include:
|
18
|
-
#
|
19
|
-
# output_dir - For each file specified an output
|
20
|
-
# file with profile information will be
|
21
|
-
# written to the output directory.
|
22
|
-
# By default, the output directory is
|
23
|
-
# called "profile" and is created underneath
|
24
|
-
# the current working directory.
|
25
|
-
#
|
26
|
-
# printer - Specifies the output printer. Valid values include
|
27
|
-
# :flat, :graph, :graph_html and :call_tree.
|
28
|
-
#
|
29
|
-
# min_percent - Methods that take less than the specified percent
|
30
|
-
# will not be written out.
|
31
|
-
#
|
32
|
-
# Example:
|
33
|
-
#
|
34
|
-
# require 'ruby-prof/task'
|
35
|
-
#
|
36
|
-
# RubyProf::ProfileTask.new do |t|
|
37
|
-
# t.test_files = FileList['test/test*.rb']
|
38
|
-
# t.output_dir = "c:/temp"
|
39
|
-
# t.printer = :graph
|
40
|
-
# t.min_percent = 10
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# If rake is invoked with a "TEST=filename" command line option,
|
44
|
-
# then the list of test files will be overridden to include only the
|
45
|
-
# filename specified on the command line. This provides an easy way
|
46
|
-
# to run just one test.
|
47
|
-
#
|
48
|
-
# If rake is invoked with a "TESTOPTS=options" command line option,
|
49
|
-
# then the given options are passed to the test process after a
|
50
|
-
# '--'. This allows Test::Unit options to be passed to the test
|
51
|
-
# suite.
|
52
|
-
#
|
53
|
-
# Examples:
|
54
|
-
#
|
55
|
-
# rake profile # run tests normally
|
56
|
-
# rake profile TEST=just_one_file.rb # run just one test file.
|
57
|
-
# rake profile TESTOPTS="-v" # run in verbose mode
|
58
|
-
# rake profile TESTOPTS="--runner=fox" # use the fox test runner
|
59
|
-
|
60
|
-
class ProfileTask < Rake::TestTask
|
61
|
-
attr_accessor :output_dir
|
62
|
-
attr_accessor :min_percent
|
63
|
-
attr_accessor :printer
|
64
|
-
|
65
|
-
def initialize(name = :profile)
|
66
|
-
super(name)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Create the tasks defined by this task lib.
|
70
|
-
def define
|
71
|
-
lib_path = @libs.join(File::PATH_SEPARATOR)
|
72
|
-
desc "Profile" + (@name==:profile ? "" : " for #{@name}")
|
73
|
-
|
74
|
-
task @name do
|
75
|
-
create_output_directory
|
76
|
-
|
77
|
-
@ruby_opts.unshift( "-I#{lib_path}" )
|
78
|
-
@ruby_opts.unshift( "-w" ) if @warning
|
79
|
-
@ruby_opts.push("-S ruby-prof")
|
80
|
-
@ruby_opts.push("--printer #{@printer}")
|
81
|
-
@ruby_opts.push("--min_percent #{@min_percent}")
|
82
|
-
|
83
|
-
file_list.each do |file_path|
|
84
|
-
run_script(file_path)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
self
|
88
|
-
end
|
89
|
-
|
90
|
-
# Run script
|
91
|
-
def run_script(script_path)
|
92
|
-
run_code = ''
|
93
|
-
RakeFileUtils.verbose(@verbose) do
|
94
|
-
file_name = File.basename(script_path, File.extname(script_path))
|
95
|
-
case @printer
|
96
|
-
when :flat, :graph, :call_tree
|
97
|
-
file_name += ".txt"
|
98
|
-
when :graph_html
|
99
|
-
file_name += ".html"
|
100
|
-
else
|
101
|
-
file_name += ".txt"
|
102
|
-
end
|
103
|
-
|
104
|
-
output_file_path = File.join(output_directory, file_name)
|
105
|
-
|
106
|
-
command_line = @ruby_opts.join(" ") +
|
107
|
-
" --file=" + output_file_path +
|
108
|
-
" " + script_path
|
109
|
-
|
110
|
-
puts "ruby " + command_line
|
111
|
-
# We have to catch the exeption to continue on. However,
|
112
|
-
# the error message will have been output to STDERR
|
113
|
-
# already by the time we get here so we don't have to
|
114
|
-
# do that again
|
115
|
-
begin
|
116
|
-
ruby command_line
|
117
|
-
rescue => e
|
118
|
-
STDOUT << e << "\n"
|
119
|
-
STDOUT.flush
|
120
|
-
end
|
121
|
-
puts ""
|
122
|
-
puts ""
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def output_directory
|
127
|
-
File.expand_path(@output_dir)
|
128
|
-
end
|
129
|
-
|
130
|
-
def create_output_directory
|
131
|
-
if not File.exist?(output_directory)
|
132
|
-
Dir.mkdir(output_directory)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def clean_output_directory
|
137
|
-
if File.exist?(output_directory)
|
138
|
-
files = Dir.glob(output_directory + '/*')
|
139
|
-
FileUtils.rm(files)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def option_list # :nodoc:
|
144
|
-
ENV['OPTIONS'] || @options.join(" ") || ""
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
module RubyProf
|
9
|
+
|
10
|
+
# Define a task library for profiling unit tests with ruby-prof.
|
11
|
+
#
|
12
|
+
# All of the options provided by
|
13
|
+
# the Rake:TestTask are supported except the loader
|
14
|
+
# which is set to ruby-prof. For detailed information
|
15
|
+
# please refer to the Rake:TestTask documentation.
|
16
|
+
#
|
17
|
+
# ruby-prof specific options include:
|
18
|
+
#
|
19
|
+
# output_dir - For each file specified an output
|
20
|
+
# file with profile information will be
|
21
|
+
# written to the output directory.
|
22
|
+
# By default, the output directory is
|
23
|
+
# called "profile" and is created underneath
|
24
|
+
# the current working directory.
|
25
|
+
#
|
26
|
+
# printer - Specifies the output printer. Valid values include
|
27
|
+
# :flat, :graph, :graph_html and :call_tree.
|
28
|
+
#
|
29
|
+
# min_percent - Methods that take less than the specified percent
|
30
|
+
# will not be written out.
|
31
|
+
#
|
32
|
+
# Example:
|
33
|
+
#
|
34
|
+
# require 'ruby-prof/task'
|
35
|
+
#
|
36
|
+
# RubyProf::ProfileTask.new do |t|
|
37
|
+
# t.test_files = FileList['test/test*.rb']
|
38
|
+
# t.output_dir = "c:/temp"
|
39
|
+
# t.printer = :graph
|
40
|
+
# t.min_percent = 10
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# If rake is invoked with a "TEST=filename" command line option,
|
44
|
+
# then the list of test files will be overridden to include only the
|
45
|
+
# filename specified on the command line. This provides an easy way
|
46
|
+
# to run just one test.
|
47
|
+
#
|
48
|
+
# If rake is invoked with a "TESTOPTS=options" command line option,
|
49
|
+
# then the given options are passed to the test process after a
|
50
|
+
# '--'. This allows Test::Unit options to be passed to the test
|
51
|
+
# suite.
|
52
|
+
#
|
53
|
+
# Examples:
|
54
|
+
#
|
55
|
+
# rake profile # run tests normally
|
56
|
+
# rake profile TEST=just_one_file.rb # run just one test file.
|
57
|
+
# rake profile TESTOPTS="-v" # run in verbose mode
|
58
|
+
# rake profile TESTOPTS="--runner=fox" # use the fox test runner
|
59
|
+
|
60
|
+
class ProfileTask < Rake::TestTask
|
61
|
+
attr_accessor :output_dir
|
62
|
+
attr_accessor :min_percent
|
63
|
+
attr_accessor :printer
|
64
|
+
|
65
|
+
def initialize(name = :profile)
|
66
|
+
super(name)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Create the tasks defined by this task lib.
|
70
|
+
def define
|
71
|
+
lib_path = @libs.join(File::PATH_SEPARATOR)
|
72
|
+
desc "Profile" + (@name==:profile ? "" : " for #{@name}")
|
73
|
+
|
74
|
+
task @name do
|
75
|
+
create_output_directory
|
76
|
+
|
77
|
+
@ruby_opts.unshift( "-I#{lib_path}" )
|
78
|
+
@ruby_opts.unshift( "-w" ) if @warning
|
79
|
+
@ruby_opts.push("-S ruby-prof")
|
80
|
+
@ruby_opts.push("--printer #{@printer}")
|
81
|
+
@ruby_opts.push("--min_percent #{@min_percent}")
|
82
|
+
|
83
|
+
file_list.each do |file_path|
|
84
|
+
run_script(file_path)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
# Run script
|
91
|
+
def run_script(script_path)
|
92
|
+
run_code = ''
|
93
|
+
RakeFileUtils.verbose(@verbose) do
|
94
|
+
file_name = File.basename(script_path, File.extname(script_path))
|
95
|
+
case @printer
|
96
|
+
when :flat, :graph, :call_tree
|
97
|
+
file_name += ".txt"
|
98
|
+
when :graph_html
|
99
|
+
file_name += ".html"
|
100
|
+
else
|
101
|
+
file_name += ".txt"
|
102
|
+
end
|
103
|
+
|
104
|
+
output_file_path = File.join(output_directory, file_name)
|
105
|
+
|
106
|
+
command_line = @ruby_opts.join(" ") +
|
107
|
+
" --file=" + output_file_path +
|
108
|
+
" " + script_path
|
109
|
+
|
110
|
+
puts "ruby " + command_line
|
111
|
+
# We have to catch the exeption to continue on. However,
|
112
|
+
# the error message will have been output to STDERR
|
113
|
+
# already by the time we get here so we don't have to
|
114
|
+
# do that again
|
115
|
+
begin
|
116
|
+
ruby command_line
|
117
|
+
rescue => e
|
118
|
+
STDOUT << e << "\n"
|
119
|
+
STDOUT.flush
|
120
|
+
end
|
121
|
+
puts ""
|
122
|
+
puts ""
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def output_directory
|
127
|
+
File.expand_path(@output_dir)
|
128
|
+
end
|
129
|
+
|
130
|
+
def create_output_directory
|
131
|
+
if not File.exist?(output_directory)
|
132
|
+
Dir.mkdir(output_directory)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def clean_output_directory
|
137
|
+
if File.exist?(output_directory)
|
138
|
+
files = Dir.glob(output_directory + '/*')
|
139
|
+
FileUtils.rm(files)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def option_list # :nodoc:
|
144
|
+
ENV['OPTIONS'] || @options.join(" ") || ""
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|