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
data/LICENSE
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
-
Copyright (C) 2005 -
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
are
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
IMPLIED WARRANTIES
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
Copyright (C) 2005 - 2019 Shugo Maeda <shugo@ruby-lang.org>, Charlie Savage <cfis@savagexi.com> and
|
2
|
+
Stefan Kaes <skaes@railsepxress.de>
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions
|
7
|
+
are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
19
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
21
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
22
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
23
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
24
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
24
25
|
SUCH DAMAGE.
|
data/README.rdoc
CHANGED
@@ -1,433 +1,5 @@
|
|
1
|
-
= ruby-prof
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
ruby-prof is a fast code profiler for Ruby. Its features include:
|
7
|
-
|
8
|
-
* Speed - it is a C extension and therefore many times faster than the standard Ruby profiler.
|
9
|
-
* Modes - Ruby prof can measure a number of different parameters, including call times, memory usage and object allocations.
|
10
|
-
* Reports - can generate text and cross-referenced html reports
|
11
|
-
- Flat Profiles - similar to the reports generated by the standard Ruby profiler
|
12
|
-
- Graph profiles - similar to GProf, these show how long a method runs, which methods call it and which methods it calls.
|
13
|
-
- Call tree profiles - outputs results in the calltree format suitable for the KCacheGrind profiling tool.
|
14
|
-
- Many more -- see reports section of this README.
|
15
|
-
* Threads - supports profiling multiple threads simultaneously
|
16
|
-
|
17
|
-
== Requirements
|
18
|
-
|
19
|
-
ruby-prof requires Ruby 1.8.7 or 1.9.2 and higher.
|
20
|
-
|
21
|
-
If you are running Linux or Unix you'll need a C compiler so the extension
|
22
|
-
can be compiled when it is installed.
|
23
|
-
|
24
|
-
If you are running Windows, then you may need to install the
|
25
|
-
Windows specific RubyGem which includes an already built extension (see Install section).
|
26
|
-
|
27
|
-
== Install
|
28
|
-
|
29
|
-
The easiest way to install ruby-prof is by using Ruby Gems. To install:
|
30
|
-
|
31
|
-
gem install ruby-prof
|
32
|
-
|
33
|
-
If you're on windows then a prebuilt binary gem is available. You may of course
|
34
|
-
compile it yourself via use of devkit on MinGW.
|
35
|
-
|
36
|
-
== Usage
|
37
|
-
|
38
|
-
There are two ways of running ruby-prof, via the command line or via its API.
|
39
|
-
|
40
|
-
=== ruby-prof executable
|
41
|
-
|
42
|
-
The first is to use ruby-prof to run the Ruby program you want to
|
43
|
-
profile. For more information refer to the documentation of the
|
44
|
-
ruby-prof command.
|
45
|
-
|
46
|
-
|
47
|
-
=== ruby-prof API
|
48
|
-
|
49
|
-
The second way is to use the ruby-prof API to profile
|
50
|
-
particular segments of code.
|
51
|
-
|
52
|
-
require 'ruby-prof'
|
53
|
-
|
54
|
-
# Profile the code
|
55
|
-
RubyProf.start
|
56
|
-
...
|
57
|
-
[code to profile]
|
58
|
-
...
|
59
|
-
result = RubyProf.stop
|
60
|
-
|
61
|
-
# Print a flat profile to text
|
62
|
-
printer = RubyProf::FlatPrinter.new(result)
|
63
|
-
printer.print(STDOUT)
|
64
|
-
|
65
|
-
Alternatively, you can use a block to tell ruby-prof what
|
66
|
-
to profile:
|
67
|
-
|
68
|
-
require 'ruby-prof'
|
69
|
-
|
70
|
-
# Profile the code
|
71
|
-
result = RubyProf.profile do
|
72
|
-
...
|
73
|
-
[code to profile]
|
74
|
-
...
|
75
|
-
end
|
76
|
-
|
77
|
-
# Print a graph profile to text
|
78
|
-
printer = RubyProf::GraphPrinter.new(result)
|
79
|
-
printer.print(STDOUT, {})
|
80
|
-
|
81
|
-
ruby-prof also supports pausing and resuming profiling runs.
|
82
|
-
|
83
|
-
require 'ruby-prof'
|
84
|
-
|
85
|
-
# Profile the code
|
86
|
-
RubyProf.start
|
87
|
-
[code to profile]
|
88
|
-
RubyProf.pause
|
89
|
-
[other code]
|
90
|
-
RubyProf.resume
|
91
|
-
[code to profile]
|
92
|
-
result = RubyProf.stop
|
93
|
-
|
94
|
-
Note that resume will automatically call start if a profiling run
|
95
|
-
has not yet started. In addition, resume can also take a block:
|
96
|
-
|
97
|
-
require 'ruby-prof'
|
98
|
-
|
99
|
-
# Profile the code
|
100
|
-
RubyProf.resume do
|
101
|
-
[code to profile]
|
102
|
-
end
|
103
|
-
|
104
|
-
data = RubyProf.stop
|
105
|
-
|
106
|
-
With this usage, resume will automatically call pause at the
|
107
|
-
end of the block.
|
108
|
-
|
109
|
-
|
110
|
-
== Method and Thread Elimination
|
111
|
-
|
112
|
-
ruby-prof supports eliminating specific methods and threads from profiling
|
113
|
-
results. This is useful for reducing connectivity in the call graph, making it easier to
|
114
|
-
identify the source of performance problems when using a graph printer.
|
115
|
-
|
116
|
-
For example, consider Integer#times: it's hardly ever useful to know how much time is
|
117
|
-
spent in the method itself. We're much more interested in how much the passed in block
|
118
|
-
contributes to the time spent in the method which contains the Integer#times call.
|
119
|
-
|
120
|
-
Methods are eliminated from the collected data by calling `eliminate_methods!` on the
|
121
|
-
profiling result, before submitting it to a printer.
|
122
|
-
|
123
|
-
result = RubyProf.stop
|
124
|
-
result.eliminate_methods!([/Integer#times/])
|
125
|
-
|
126
|
-
The argument given to `eliminate_methods!` is either an array of regular expressions, or
|
127
|
-
the name of a file containing a list of regular expressions (line separated text).
|
128
|
-
|
129
|
-
After eliminating methods the resulting profile will appear exactly as if those methods
|
130
|
-
had been inlined at their call sites.
|
131
|
-
|
132
|
-
In a similar manner, threads can be excluded so they are not profiled at all. To do this,
|
133
|
-
pass an array of threads to exclude to ruby-prof:
|
134
|
-
|
135
|
-
RubyProf::exclude_threads = [ thread2 ]
|
136
|
-
RubyProf.start
|
137
|
-
|
138
|
-
Note that the excluded threads must be specified *before* profiling.
|
139
|
-
|
140
|
-
|
141
|
-
== Benchmarking full load time including rubygems startup cost ==
|
142
|
-
|
143
|
-
If you want to get a more accurate measurement of what takes all of a gem's bin/xxx
|
144
|
-
command to load, you may want to also measure rubygems' startup penalty.
|
145
|
-
You can do this by calling into bin/ruby-prof directly, ex:
|
146
|
-
|
147
|
-
$ gem which ruby-prof
|
148
|
-
g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/lib/ruby-prof.rb
|
149
|
-
|
150
|
-
now run it thus (substitute lib/ruby-prof.rb with bin/ruby-prof):
|
151
|
-
|
152
|
-
$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof g:\192\bin\some_installed_gem_command
|
153
|
-
|
154
|
-
or
|
155
|
-
|
156
|
-
$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof ./some_file_that_does_a_require_rubygems_at_the_beginning.rb
|
157
|
-
|
158
|
-
== Profiling Tests
|
159
|
-
|
160
|
-
ruby-prof supports profiling tests cases
|
161
|
-
written using Ruby's built-in unit test framework (ie, test derived from
|
162
|
-
Test::Unit::TestCase). To enable profiling simply add the following line
|
163
|
-
of code to within your test class:
|
164
|
-
|
165
|
-
include RubyProf::Test
|
166
|
-
|
167
|
-
Each test method is profiled separately. ruby-prof will run each test method
|
168
|
-
once as a warmup and then ten additional times to gather profile data.
|
169
|
-
Note that the profile data will *not* include the class's setup or
|
170
|
-
teardown methods.
|
171
|
-
|
172
|
-
Separate reports are generated for each method and saved, by default,
|
173
|
-
in the test process's working directory. To change this, or other profiling
|
174
|
-
options, modify your test class's PROFILE_OPTIONS hash table. To globally
|
175
|
-
change test profiling options, modify RubyProf::Test::PROFILE_OPTIONS.
|
176
|
-
|
177
|
-
|
178
|
-
== Profiling Rails
|
179
|
-
|
180
|
-
To profile a Rails application it is vital to run it using production like
|
181
|
-
settings (cache classes, cache view lookups, etc.). Otherwise, Rail's
|
182
|
-
dependency loading code will overwhelm any time spent in the application
|
183
|
-
itself (our tests show that Rails dependency loading causes a roughly 6x
|
184
|
-
slowdown). The best way to do this is create a new Rails environment,
|
185
|
-
profile.rb.
|
186
|
-
|
187
|
-
So to profile Rails:
|
188
|
-
|
189
|
-
1. Create a new profile.rb environment. Make sure to turn on cache_classes
|
190
|
-
and cache_template_loading. Otherwise your profiling results will be
|
191
|
-
overwhelemed by the time Rails spends loading required files. You should
|
192
|
-
likely turn off caching.
|
193
|
-
|
194
|
-
2. Add the ruby-prof to your gemfile:
|
195
|
-
|
196
|
-
group :profile do
|
197
|
-
gem 'ruby-prof'
|
198
|
-
end
|
199
|
-
|
200
|
-
3. Add the ruby prof rack adapter to your middleware stack. One way to
|
201
|
-
do this is by adding the following code to config.ru:
|
202
|
-
|
203
|
-
if Rails.env.profile?
|
204
|
-
use Rack::RubyProf, :path => '/temp/profile'
|
205
|
-
end
|
206
|
-
|
207
|
-
The path is where you want profiling results to be stored. By default the
|
208
|
-
rack adapter will generate a html call graph report and flat text report.
|
209
|
-
|
210
|
-
4. Now make a request to your running server. New profiling information will
|
211
|
-
be generated for each request. Note that each request will overwrite
|
212
|
-
the profiling reports created by the previous request!
|
213
|
-
|
214
|
-
== Reports
|
215
|
-
|
216
|
-
ruby-prof can generate a number of different reports:
|
217
|
-
|
218
|
-
* Flat Reports
|
219
|
-
* Graph Reports
|
220
|
-
* HTML Graph Reports
|
221
|
-
* Call graphs
|
222
|
-
* Call stack reports
|
223
|
-
* More!
|
224
|
-
|
225
|
-
Flat profiles show the overall time spent in each method. They
|
226
|
-
are a good of quickly identifying which methods take the most time.
|
227
|
-
An example of a flat profile and an explanation can be found in
|
228
|
-
{examples/flat.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/flat.txt].
|
229
|
-
|
230
|
-
There are several varieties of these -- run $ ruby-prof --help
|
231
|
-
|
232
|
-
Graph profiles also show the overall time spent in each method. In
|
233
|
-
addition, they also show which methods call the current method and which
|
234
|
-
methods its calls. Thus they are good for understanding how methods
|
235
|
-
gets called and provide insight into the flow of your program. An
|
236
|
-
example text graph profile is located at
|
237
|
-
{examples/graph.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.txt].
|
238
|
-
|
239
|
-
HTML Graph profiles are the same as graph profiles, except output is
|
240
|
-
generated in hyper-linked HTML. Since graph profiles can be quite large,
|
241
|
-
the embedded links make it much easier to navigate the results. An
|
242
|
-
example html graph profile is located at
|
243
|
-
{examples/graph.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.html].
|
244
|
-
|
245
|
-
Call graphs output results in the calltree profile format which is used
|
246
|
-
by KCachegrind. Call graph support was generously donated by Carl
|
247
|
-
Shimer. More information about the format can be found at the
|
248
|
-
{KCachegrind}[http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindCalltreeFormat]
|
249
|
-
site.
|
250
|
-
|
251
|
-
Call stack reports produce a HTML visualization of the time spent in
|
252
|
-
each execution path of the profiled code. An example can be found at
|
253
|
-
{examples/stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/call_stack.html].
|
254
|
-
|
255
|
-
Another good example: [http://twitpic.com/28z94a]
|
256
|
-
|
257
|
-
Finally, there's a so called MultiPrinter which can generate several
|
258
|
-
reports in one profiling run. See
|
259
|
-
{examples/multi.stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/multi.stack.html].
|
260
|
-
|
261
|
-
There is also a graphviz .dot visualiser.
|
262
|
-
|
263
|
-
== Printers
|
264
|
-
|
265
|
-
Reports are created by printers. Supported printers include:
|
266
|
-
|
267
|
-
* RubyProf::FlatPrinter - Creates a flat report in text format
|
268
|
-
* RubyProf::FlatPrinterWithLineNumbers - same as above but more verbose
|
269
|
-
* RubyProf::GraphPrinter - Creates a call graph report in text format
|
270
|
-
* RubyProf::GraphHtmlPrinter - Creates a call graph report in HTML (separate files per thread)
|
271
|
-
* RubyProf::DotPrinter - Creates a call graph report in GraphViz's DOT format which can be converted to an image
|
272
|
-
* RubyProf::CallTreePrinter - Creates a call tree report compatible with KCachegrind.
|
273
|
-
* RubyProf::CallStackPrinter - Creates a HTML visualization of the Ruby stack
|
274
|
-
* RubyProf::MultiPrinter - Uses the other printers to create several reports in one profiling run
|
275
|
-
* More!
|
276
|
-
|
277
|
-
To use a printer:
|
278
|
-
|
279
|
-
...
|
280
|
-
result = RubyProf.stop
|
281
|
-
printer = RubyProf::GraphPrinter.new(result)
|
282
|
-
printer.print(STDOUT, :min_percent => 2)
|
283
|
-
|
284
|
-
The first parameter is any writable IO object such as STDOUT or a file.
|
285
|
-
The second parameter, specifies the minimum percentage a method must take
|
286
|
-
to be printed. Percentages should be specified as integers in the range 0 to 100.
|
287
|
-
For more information please see the documentation for the different printers.
|
288
|
-
|
289
|
-
The other option is :print_file => true (default false), which adds the filename to the
|
290
|
-
output (GraphPrinter only).
|
291
|
-
|
292
|
-
The MultiPrinter differs from the other printers in that it requires a directory path
|
293
|
-
and a basename for the files it produces.
|
294
|
-
|
295
|
-
printer = RubyProf::MultiPrinter.new(result)
|
296
|
-
printer.print(:path => ".", :profile => "profile")
|
297
|
-
|
298
|
-
|
299
|
-
== Measurements
|
300
|
-
|
301
|
-
Depending on the mode and platform, ruby-prof can measure various
|
302
|
-
aspects of a Ruby program. Supported measurements include:
|
303
|
-
|
304
|
-
* process time (RubyProf::PROCESS_TIME)
|
305
|
-
* wall time (RubyProf::WALL_TIME)
|
306
|
-
* cpu time (RubyProf::CPU_TIME)
|
307
|
-
* object allocations (RubyProf::ALLOCATIONS)
|
308
|
-
* memory usage (RubyProf::MEMORY)
|
309
|
-
* garbage collections runs (RubyProf::GC_RUNS)
|
310
|
-
* garbage collection time (RubyProf::GC_TIME)
|
311
|
-
|
312
|
-
Process time measures the time used by a process between any two moments.
|
313
|
-
It is unaffected by other processes concurrently running
|
314
|
-
on the system. Note that Windows does not support measuring process
|
315
|
-
times - therefore, measurements on Windows defaults to wall time.
|
316
|
-
|
317
|
-
Wall time measures the real-world time elapsed between any two moments.
|
318
|
-
If there are other processes concurrently running on the system
|
319
|
-
that use significant CPU or disk time during a profiling run
|
320
|
-
then the reported results will be too large.
|
321
|
-
|
322
|
-
CPU time uses the CPU clock counter to measure time. The returned
|
323
|
-
values are dependent on the correctly setting the CPU's frequency.
|
324
|
-
This mode is only supported on Pentium or PowerPC platforms (linux only).
|
325
|
-
|
326
|
-
Object allocation reports show how many objects each method in
|
327
|
-
a program allocates. This support was added by Sylvain Joyeux
|
328
|
-
and requires a patched Ruby interpreter. For more information and
|
329
|
-
the patch, please see:
|
330
|
-
http://rubyforge.org/tracker/index.php?func=detail&aid=11497&group_id=426&atid=1700
|
331
|
-
|
332
|
-
Memory usage reports show how much memory each method in a program
|
333
|
-
uses. This support was added by Alexander Dymo and requires a
|
334
|
-
patched Ruby interpreter. For more information, see:
|
335
|
-
http://rubyforge.org/tracker/index.php?func=detail&aid=17676&group_id=1814&atid=7062
|
336
|
-
|
337
|
-
Garbage collection runs report how many times Ruby's garbage collector
|
338
|
-
is invoked during a profiling session. This support was added by Jeremy
|
339
|
-
Kemper and requires a patched Ruby interpreter. For more information, see:
|
340
|
-
http://rubyforge.org/tracker/index.php?func=detail&aid=17676&group_id=1814&atid=7062
|
341
|
-
|
342
|
-
Garbage collection time reports how much time is spent in Ruby's garbage collector
|
343
|
-
during a profiling session. This support was added by Jeremy Kemper
|
344
|
-
and requires a patched Ruby interpreter. For more information, see:
|
345
|
-
http://rubyforge.org/tracker/index.php?func=detail&aid=17676&group_id=1814&atid=7062
|
346
|
-
|
347
|
-
To set the measurement:
|
348
|
-
|
349
|
-
* RubyProf.measure_mode = RubyProf::PROCESS_TIME
|
350
|
-
* RubyProf.measure_mode = RubyProf::WALL_TIME
|
351
|
-
* RubyProf.measure_mode = RubyProf::CPU_TIME
|
352
|
-
* RubyProf.measure_mode = RubyProf::ALLOCATIONS
|
353
|
-
* RubyProf.measure_mode = RubyProf::MEMORY
|
354
|
-
* RubyProf.measure_mode = RubyProf::GC_RUNS
|
355
|
-
* RubyProf.measure_mode = RubyProf::GC_TIME
|
356
|
-
|
357
|
-
The default value is RubyProf::PROCESS_TIME.
|
358
|
-
|
359
|
-
You may also specify the measure_mode by using the RUBY_PROF_MEASURE_MODE
|
360
|
-
environment variable:
|
361
|
-
|
362
|
-
* export RUBY_PROF_MEASURE_MODE=process
|
363
|
-
* export RUBY_PROF_MEASURE_MODE=wall
|
364
|
-
* export RUBY_PROF_MEASURE_MODE=cpu
|
365
|
-
* export RUBY_PROF_MEASURE_MODE=allocations
|
366
|
-
* export RUBY_PROF_MEASURE_MODE=memory
|
367
|
-
* export RUBY_PROF_MEASURE_MODE=gc_runs
|
368
|
-
* export RUBY_PROF_MEASURE_MODE=gc_time
|
369
|
-
|
370
|
-
On Linux, process time is measured using the clock method provided
|
371
|
-
by the C runtime library. Note that the clock method does not
|
372
|
-
report time spent in the kernel or child processes and therefore
|
373
|
-
does not measure time spent in methods such as Kernel.sleep method.
|
374
|
-
If you need to measure these values, then use wall time. Wall time
|
375
|
-
is measured using the gettimeofday kernel method.
|
376
|
-
|
377
|
-
On Windows, timings default to wall times. If you set the clock
|
378
|
-
mode to PROCESS_TIME, then timing are read using the clock method
|
379
|
-
provided by the C runtime library. Note though, these values are
|
380
|
-
wall times on Windows and not process times like on Linux.
|
381
|
-
Wall time is measured using the GetLocalTime API.
|
382
|
-
|
383
|
-
If you use wall time, the results will be affected by other
|
384
|
-
processes running on your computer, network delays, disk access,
|
385
|
-
etc. As result, for the best results, try to make sure your
|
386
|
-
computer is only performing your profiling run and is
|
387
|
-
otherwise quiescent.
|
388
|
-
|
389
|
-
On both platforms, cpu time is measured using the RDTSC assembly
|
390
|
-
function provided by the Pentium and PowerPC platforms. CPU time
|
391
|
-
is dependent on the cpu's frequency. On Linux, ruby-prof attempts
|
392
|
-
to read this value from "/proc/cpuinfo." On Windows, you must
|
393
|
-
manually specify the clock frequency. This can be done using the
|
394
|
-
RUBY_PROF_CPU_FREQUENCY environment variable:
|
395
|
-
|
396
|
-
export RUBY_PROF_CPU_FREQUENCY=<value>
|
397
|
-
|
398
|
-
You can also directly set the cpu frequency by calling:
|
399
|
-
|
400
|
-
RubyProf.cpu_frequency = <value>
|
401
|
-
|
402
|
-
|
403
|
-
== Multi-threaded Applications
|
404
|
-
|
405
|
-
Unfortunately, Ruby does not provide an internal api
|
406
|
-
for detecting thread context switches in 1.8. As a result, the
|
407
|
-
timings ruby-prof reports for each thread may be slightly
|
408
|
-
inaccurate. In particular, this will happen for newly
|
409
|
-
spawned threads that go to sleep immediately (their first call).
|
410
|
-
For instance, if you use Ruby's timeout library to wait for 2 seconds,
|
411
|
-
the 2 seconds will be assigned to the foreground thread
|
412
|
-
and not the newly created background thread. These errors
|
413
|
-
can largely be avoided if the background thread performs any
|
414
|
-
operation before going to sleep.
|
415
|
-
|
416
|
-
== Performance
|
417
|
-
|
418
|
-
Significant effort has been put into reducing ruby-prof's overhead
|
419
|
-
as much as possible. Our tests show that the overhead associated
|
420
|
-
with profiling code varies considerably with the code being
|
421
|
-
profiled. Most programs will run approximately twice as slow
|
422
|
-
while highly recursive programs (like the fibonacci series test)
|
423
|
-
will run three times slower.
|
424
|
-
|
425
|
-
== License
|
426
|
-
|
427
|
-
See LICENSE for license information.
|
428
|
-
|
429
|
-
== Development
|
430
|
-
|
431
|
-
Code is located at https://github.com/ruby-prof/ruby-prof
|
432
|
-
|
433
|
-
Google group/mailing list: http://groups.google.com/group/ruby-optimization or start a github issue.
|
1
|
+
= ruby-prof
|
2
|
+
|
3
|
+
{<img src="https://travis-ci.org/ruby-prof/ruby-prof.png?branch=master" alt="Build Status" />}[https://travis-ci.org/ruby-prof/ruby-prof]
|
4
|
+
|
5
|
+
For an overview of ruby-prof please see https://ruby-prof.github.io
|