ruby-prof 0.4.0-mswin32 → 0.4.1-mswin32
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.
- data/README +220 -220
- data/Rakefile +3 -3
- data/doc/created.rid +1 -1
- data/doc/files/LICENSE.html +0 -142
- data/doc/files/README.html +2 -2
- data/doc/files/examples/flat_txt.html +8 -16
- data/doc/files/examples/graph_txt.html +10 -18
- data/doc/files/ext/ruby_prof_c.html +1 -1
- data/doc/files/lib/ruby-prof/flat_printer_rb.html +1 -1
- data/doc/files/lib/ruby-prof/graph_html_printer_rb.html +1 -1
- data/doc/files/lib/ruby-prof/graph_printer_rb.html +1 -1
- data/examples/flat.txt +55 -57
- data/examples/graph.html +827 -827
- data/examples/graph.txt +170 -171
- data/ext/ruby_prof.c +35 -20
- data/lib/ruby-prof/flat_printer.rb +8 -9
- data/lib/ruby-prof/graph_html_printer.rb +3 -2
- data/lib/ruby-prof/graph_printer.rb +4 -5
- data/lib/ruby_prof.so +0 -0
- data/test/basic_test.rb +148 -141
- data/test/clock_mode_test.rb +72 -72
- data/test/duplicate_names_test.rb +37 -0
- data/test/module_test.rb +45 -45
- data/test/prime.rb +58 -58
- data/test/prime_test.rb +23 -23
- data/test/printers_test.rb +27 -27
- data/test/recursive_test.rb +55 -55
- data/test/test_helper.rb +45 -45
- data/test/test_suite.rb +10 -9
- data/test/thread_test.rb +32 -32
- data/test/timing_test.rb +90 -90
- metadata +3 -16
- data/doc/classes/RubyProf.html +0 -563
- data/doc/classes/RubyProf/CallInfo.html +0 -274
- data/doc/classes/RubyProf/FlatPrinter.html +0 -207
- data/doc/classes/RubyProf/GraphHtmlPrinter.html +0 -538
- data/doc/classes/RubyProf/GraphPrinter.html +0 -240
- data/doc/classes/RubyProf/MethodInfo.html +0 -556
- data/doc/classes/RubyProf/ProfileTask.html +0 -395
- data/doc/classes/RubyProf/Result.html +0 -234
- data/doc/fr_class_index.html +0 -34
- data/doc/fr_file_index.html +0 -39
- data/doc/fr_method_index.html +0 -67
- data/doc/index.html +0 -24
- data/test/test.rb +0 -3
data/README
CHANGED
@@ -1,220 +1,220 @@
|
|
1
|
-
= ruby-prof
|
2
|
-
|
3
|
-
== Overview
|
4
|
-
|
5
|
-
ruby-prof is a fast code profiler for Ruby. Its features include:
|
6
|
-
|
7
|
-
* Speed - it is a C extension and therefore many times faster than the standard Ruby profiler.
|
8
|
-
* Flat Profiles - similar to the reports generated by the standard Ruby profiler
|
9
|
-
* Graph profiles - similar to GProf, these show how long a method runs, which methods call it and which methods it calls.
|
10
|
-
* Threads - supports profiling multiple threads simultaneously
|
11
|
-
* Recursive calls - supports profiling recursive method calls
|
12
|
-
* Reports - can generate both text and cross-referenced html reports
|
13
|
-
* Output - can output to standard out or to a file
|
14
|
-
|
15
|
-
|
16
|
-
== Requirements
|
17
|
-
|
18
|
-
ruby-prof requires Ruby 1.8.2 or higher.
|
19
|
-
|
20
|
-
If you are running Linux or Unix you'll need a C compiler so the extension
|
21
|
-
can be compiled when it is installed.
|
22
|
-
|
23
|
-
If you are running Windows, then install the Windows specific RubyGem which
|
24
|
-
includes an already built extension.
|
25
|
-
|
26
|
-
|
27
|
-
== Install
|
28
|
-
|
29
|
-
ruby-prof is provided as a RubyGem. To install:
|
30
|
-
|
31
|
-
<tt>gem install ruby-prof</tt>
|
32
|
-
|
33
|
-
If you are running Windows, make sure to install the Win32 RubyGem which
|
34
|
-
includes a pre-built binary.
|
35
|
-
|
36
|
-
== Usage
|
37
|
-
|
38
|
-
There are three ways of running ruby-prof.
|
39
|
-
|
40
|
-
=== ruby-prof executable
|
41
|
-
|
42
|
-
The first is to use ruby-prof to run the Ruby program
|
43
|
-
you want to profile. For more information refer to
|
44
|
-
the ruby-prof documentation[link:files/bin/ruby-prof.html].
|
45
|
-
|
46
|
-
=== ruby-prof API
|
47
|
-
|
48
|
-
The second way is to use the ruby-prof API to profile
|
49
|
-
particular segments of code.
|
50
|
-
|
51
|
-
require 'ruby-prof'
|
52
|
-
|
53
|
-
# Profile the code
|
54
|
-
RubyProf.start
|
55
|
-
...
|
56
|
-
[code to profile]
|
57
|
-
...
|
58
|
-
result = RubyProf.
|
59
|
-
|
60
|
-
# Print a flat profile to text
|
61
|
-
printer = RubyProf::TextPrinter.new(result)
|
62
|
-
printer.print(STDOUT, 0)
|
63
|
-
|
64
|
-
Alternatively, you can use a block to tell ruby-prof what
|
65
|
-
to profile:
|
66
|
-
|
67
|
-
require 'ruby-prof'
|
68
|
-
|
69
|
-
# Profile the code
|
70
|
-
result = RubyProf.profile do
|
71
|
-
...
|
72
|
-
[code to profile]
|
73
|
-
...
|
74
|
-
end
|
75
|
-
|
76
|
-
# Print a graph profile to text
|
77
|
-
printer = RubyProf::GraphPrinter.new(result)
|
78
|
-
printer.print(STDOUT, 0)
|
79
|
-
|
80
|
-
|
81
|
-
=== require unprof
|
82
|
-
|
83
|
-
The third way of using ruby-prof is by requiring unprof.rb:
|
84
|
-
|
85
|
-
require 'unprof'
|
86
|
-
|
87
|
-
This will start profiling immediately and will output the results
|
88
|
-
using a flat profile report.
|
89
|
-
|
90
|
-
This method is provided for backwards compatibility. Using
|
91
|
-
{ruby-prof}[link:files/bin/ruby-prof.html] provides more flexibility.
|
92
|
-
|
93
|
-
|
94
|
-
== Reports
|
95
|
-
|
96
|
-
ruby-prof can generate flat profile and graph profile reports.
|
97
|
-
|
98
|
-
Flat profiles show the overall time spent in each method. They
|
99
|
-
are a good of quickly identifying which methods take the most time.
|
100
|
-
An example of a flat profile and an explanation can be found in
|
101
|
-
{examples/flat.txt}[link:files/examples/flat_txt.html].
|
102
|
-
|
103
|
-
Graph profiles also show the overall time spent in each method.
|
104
|
-
In addition, they also show which methods call the current
|
105
|
-
method and which methods its calls. Thus they are good for
|
106
|
-
understanding how methods gets called and provide insight into
|
107
|
-
the flow of your program. Graph profiles can be generated
|
108
|
-
in text and html. Since the html is cross-referenced it is
|
109
|
-
easier to work with. An example text graph profile
|
110
|
-
is located at {examples/graph.txt}[link:files/examples/graph_txt.html] while
|
111
|
-
an example html graph file is located at
|
112
|
-
{examples/graph.html}[link:files/examples/graph_html.html].
|
113
|
-
|
114
|
-
Reports are created by printers. The current printers include:
|
115
|
-
* RubyProf::FlatPrinter - Creates a flat report in text format
|
116
|
-
* RubyProf::GraphPrinter - Creates a call graph report in text format
|
117
|
-
* RubyProf::GraphHtmlPrinter - Creates a call graph report in HTML (separate files per thread)
|
118
|
-
|
119
|
-
To use a printer:
|
120
|
-
|
121
|
-
result = RubyProf.end
|
122
|
-
printer = RubyProf::GraphPrinter.new(result)
|
123
|
-
printer.print(STDOUT, 0)
|
124
|
-
|
125
|
-
The first parameter is any writable IO object such as STDOUT or a file.
|
126
|
-
The second parameter, which has a default value of 0, specifies
|
127
|
-
the minimum percentage a method must take to be printed. For more
|
128
|
-
information please see the documentation for the different printers.
|
129
|
-
|
130
|
-
|
131
|
-
== Timing Data
|
132
|
-
|
133
|
-
Depending on the mode and platform, ruby-prof can measure time in
|
134
|
-
three ways - process time, wall time and cpu time.
|
135
|
-
|
136
|
-
Process time measures the time used by a process between any two moments.
|
137
|
-
It is unaffected by other processes concurrently running
|
138
|
-
on the system. Note that Windows does not support measuring process
|
139
|
-
times - therefore, all measurements on Windows use wall time.
|
140
|
-
|
141
|
-
Wall time measures the real-world time elapsed between any two moments.
|
142
|
-
If there are other processes concurrently running on the system
|
143
|
-
that use significant CPU or disk time during a profiling run
|
144
|
-
then the reported results will be too large.
|
145
|
-
|
146
|
-
CPU time uses the CPU clock counter to measure time. The returned
|
147
|
-
values are dependent on the correctly setting the CPU's frequency.
|
148
|
-
This mode is only supported on Pentium or PowerPC platforms.
|
149
|
-
|
150
|
-
To set the clock_mode:
|
151
|
-
|
152
|
-
RubyProf.clock_mode = RubyProf::PROCESS_TIME
|
153
|
-
RubyProf.clock_mode = RubyProf::WALL_TIME
|
154
|
-
RubyProf.clock_mode = RubyProf::CPU_TIME
|
155
|
-
|
156
|
-
This default value is PROCESS_TIME.
|
157
|
-
|
158
|
-
You may also specify the clock_mode by using the RUBY_PROF_CLOCK_MODE
|
159
|
-
environment variable:
|
160
|
-
|
161
|
-
export RUBY_PROF_CLOCK_MODE=process
|
162
|
-
export RUBY_PROF_CLOCK_MODE=wall
|
163
|
-
export RUBY_PROF_CLOCK_MODE=cpu
|
164
|
-
|
165
|
-
Note that these values have changed since ruby-prof-0.3.0.
|
166
|
-
|
167
|
-
On Linux, process time is measured using the clock method provided
|
168
|
-
by the C runtime library. Note that the clock method does not
|
169
|
-
report time spent in the kernel or child processes and therefore
|
170
|
-
does not measure time spent in methods such as Kernel.sleep method.
|
171
|
-
If you need to measure these values, then use wall time. Wall time
|
172
|
-
is measured using the gettimeofday kernel method.
|
173
|
-
|
174
|
-
On Windows, timings are always wall times. If you set the clock
|
175
|
-
mode to PROCESS_TIME, then timing are read using the clock method
|
176
|
-
provided by the C runtime library. Note though, these values are
|
177
|
-
wall times on Windows and not process times like on Linux.
|
178
|
-
Wall time is measured using the GetLocalTime API.
|
179
|
-
|
180
|
-
On both platforms, cpu time is measured using the RDTSC assembly
|
181
|
-
function provided by the Pentium and PowerPC platforms. CPU time
|
182
|
-
is dependent on the cpu's frequency. On Linux, ruby-prof attempts
|
183
|
-
to read this value from "/proc/cpuinfo." On Windows, you must
|
184
|
-
specify the clock frequency. This can be done using the
|
185
|
-
RUBY_PROF_CPU_FREQUENCY environment variable:
|
186
|
-
|
187
|
-
export RUBY_PROF_CPU_FREQUENCY=<value>
|
188
|
-
|
189
|
-
You can also directly set the cpu frequency by calling:
|
190
|
-
|
191
|
-
RubyProf.cpu_frequency = <value>
|
192
|
-
|
193
|
-
|
194
|
-
== Recursive Calls
|
195
|
-
|
196
|
-
Recursive calls occur when method A calls method A and cycles
|
197
|
-
occur when method A calls method B calls method C calls method A.
|
198
|
-
ruby-prof can detect recursive calls any cycle calls, but does not
|
199
|
-
currently report these in its output.
|
200
|
-
|
201
|
-
However, the self time values for recursive calls should always
|
202
|
-
be accurate. It is also believed that the total times are
|
203
|
-
accurate, but these should be carefully analyzed to verify their veracity.
|
204
|
-
|
205
|
-
== Performance
|
206
|
-
|
207
|
-
Significant effort has been put into reducing ruby-prof's overhead
|
208
|
-
as much as possible. Our tests show that the overhead associated
|
209
|
-
with profiling code varies considerably with the code being
|
210
|
-
profiled. On the low end overhead is around 10% while on the
|
211
|
-
high end its can around 80%.
|
212
|
-
|
213
|
-
== Windows Binary
|
214
|
-
|
215
|
-
The Windows binary is built with the latest version of MinGW.
|
216
|
-
|
217
|
-
|
218
|
-
== License
|
219
|
-
|
220
|
-
See LICENSE for license information.
|
1
|
+
= ruby-prof
|
2
|
+
|
3
|
+
== Overview
|
4
|
+
|
5
|
+
ruby-prof is a fast code profiler for Ruby. Its features include:
|
6
|
+
|
7
|
+
* Speed - it is a C extension and therefore many times faster than the standard Ruby profiler.
|
8
|
+
* Flat Profiles - similar to the reports generated by the standard Ruby profiler
|
9
|
+
* Graph profiles - similar to GProf, these show how long a method runs, which methods call it and which methods it calls.
|
10
|
+
* Threads - supports profiling multiple threads simultaneously
|
11
|
+
* Recursive calls - supports profiling recursive method calls
|
12
|
+
* Reports - can generate both text and cross-referenced html reports
|
13
|
+
* Output - can output to standard out or to a file
|
14
|
+
|
15
|
+
|
16
|
+
== Requirements
|
17
|
+
|
18
|
+
ruby-prof requires Ruby 1.8.2 or higher.
|
19
|
+
|
20
|
+
If you are running Linux or Unix you'll need a C compiler so the extension
|
21
|
+
can be compiled when it is installed.
|
22
|
+
|
23
|
+
If you are running Windows, then install the Windows specific RubyGem which
|
24
|
+
includes an already built extension.
|
25
|
+
|
26
|
+
|
27
|
+
== Install
|
28
|
+
|
29
|
+
ruby-prof is provided as a RubyGem. To install:
|
30
|
+
|
31
|
+
<tt>gem install ruby-prof</tt>
|
32
|
+
|
33
|
+
If you are running Windows, make sure to install the Win32 RubyGem which
|
34
|
+
includes a pre-built binary.
|
35
|
+
|
36
|
+
== Usage
|
37
|
+
|
38
|
+
There are three ways of running ruby-prof.
|
39
|
+
|
40
|
+
=== ruby-prof executable
|
41
|
+
|
42
|
+
The first is to use ruby-prof to run the Ruby program
|
43
|
+
you want to profile. For more information refer to
|
44
|
+
the ruby-prof documentation[link:files/bin/ruby-prof.html].
|
45
|
+
|
46
|
+
=== ruby-prof API
|
47
|
+
|
48
|
+
The second way is to use the ruby-prof API to profile
|
49
|
+
particular segments of code.
|
50
|
+
|
51
|
+
require 'ruby-prof'
|
52
|
+
|
53
|
+
# Profile the code
|
54
|
+
RubyProf.start
|
55
|
+
...
|
56
|
+
[code to profile]
|
57
|
+
...
|
58
|
+
result = RubyProf.stop
|
59
|
+
|
60
|
+
# Print a flat profile to text
|
61
|
+
printer = RubyProf::TextPrinter.new(result)
|
62
|
+
printer.print(STDOUT, 0)
|
63
|
+
|
64
|
+
Alternatively, you can use a block to tell ruby-prof what
|
65
|
+
to profile:
|
66
|
+
|
67
|
+
require 'ruby-prof'
|
68
|
+
|
69
|
+
# Profile the code
|
70
|
+
result = RubyProf.profile do
|
71
|
+
...
|
72
|
+
[code to profile]
|
73
|
+
...
|
74
|
+
end
|
75
|
+
|
76
|
+
# Print a graph profile to text
|
77
|
+
printer = RubyProf::GraphPrinter.new(result)
|
78
|
+
printer.print(STDOUT, 0)
|
79
|
+
|
80
|
+
|
81
|
+
=== require unprof
|
82
|
+
|
83
|
+
The third way of using ruby-prof is by requiring unprof.rb:
|
84
|
+
|
85
|
+
require 'unprof'
|
86
|
+
|
87
|
+
This will start profiling immediately and will output the results
|
88
|
+
using a flat profile report.
|
89
|
+
|
90
|
+
This method is provided for backwards compatibility. Using
|
91
|
+
{ruby-prof}[link:files/bin/ruby-prof.html] provides more flexibility.
|
92
|
+
|
93
|
+
|
94
|
+
== Reports
|
95
|
+
|
96
|
+
ruby-prof can generate flat profile and graph profile reports.
|
97
|
+
|
98
|
+
Flat profiles show the overall time spent in each method. They
|
99
|
+
are a good of quickly identifying which methods take the most time.
|
100
|
+
An example of a flat profile and an explanation can be found in
|
101
|
+
{examples/flat.txt}[link:files/examples/flat_txt.html].
|
102
|
+
|
103
|
+
Graph profiles also show the overall time spent in each method.
|
104
|
+
In addition, they also show which methods call the current
|
105
|
+
method and which methods its calls. Thus they are good for
|
106
|
+
understanding how methods gets called and provide insight into
|
107
|
+
the flow of your program. Graph profiles can be generated
|
108
|
+
in text and html. Since the html is cross-referenced it is
|
109
|
+
easier to work with. An example text graph profile
|
110
|
+
is located at {examples/graph.txt}[link:files/examples/graph_txt.html] while
|
111
|
+
an example html graph file is located at
|
112
|
+
{examples/graph.html}[link:files/examples/graph_html.html].
|
113
|
+
|
114
|
+
Reports are created by printers. The current printers include:
|
115
|
+
* RubyProf::FlatPrinter - Creates a flat report in text format
|
116
|
+
* RubyProf::GraphPrinter - Creates a call graph report in text format
|
117
|
+
* RubyProf::GraphHtmlPrinter - Creates a call graph report in HTML (separate files per thread)
|
118
|
+
|
119
|
+
To use a printer:
|
120
|
+
|
121
|
+
result = RubyProf.end
|
122
|
+
printer = RubyProf::GraphPrinter.new(result)
|
123
|
+
printer.print(STDOUT, 0)
|
124
|
+
|
125
|
+
The first parameter is any writable IO object such as STDOUT or a file.
|
126
|
+
The second parameter, which has a default value of 0, specifies
|
127
|
+
the minimum percentage a method must take to be printed. For more
|
128
|
+
information please see the documentation for the different printers.
|
129
|
+
|
130
|
+
|
131
|
+
== Timing Data
|
132
|
+
|
133
|
+
Depending on the mode and platform, ruby-prof can measure time in
|
134
|
+
three ways - process time, wall time and cpu time.
|
135
|
+
|
136
|
+
Process time measures the time used by a process between any two moments.
|
137
|
+
It is unaffected by other processes concurrently running
|
138
|
+
on the system. Note that Windows does not support measuring process
|
139
|
+
times - therefore, all measurements on Windows use wall time.
|
140
|
+
|
141
|
+
Wall time measures the real-world time elapsed between any two moments.
|
142
|
+
If there are other processes concurrently running on the system
|
143
|
+
that use significant CPU or disk time during a profiling run
|
144
|
+
then the reported results will be too large.
|
145
|
+
|
146
|
+
CPU time uses the CPU clock counter to measure time. The returned
|
147
|
+
values are dependent on the correctly setting the CPU's frequency.
|
148
|
+
This mode is only supported on Pentium or PowerPC platforms.
|
149
|
+
|
150
|
+
To set the clock_mode:
|
151
|
+
|
152
|
+
RubyProf.clock_mode = RubyProf::PROCESS_TIME
|
153
|
+
RubyProf.clock_mode = RubyProf::WALL_TIME
|
154
|
+
RubyProf.clock_mode = RubyProf::CPU_TIME
|
155
|
+
|
156
|
+
This default value is PROCESS_TIME.
|
157
|
+
|
158
|
+
You may also specify the clock_mode by using the RUBY_PROF_CLOCK_MODE
|
159
|
+
environment variable:
|
160
|
+
|
161
|
+
export RUBY_PROF_CLOCK_MODE=process
|
162
|
+
export RUBY_PROF_CLOCK_MODE=wall
|
163
|
+
export RUBY_PROF_CLOCK_MODE=cpu
|
164
|
+
|
165
|
+
Note that these values have changed since ruby-prof-0.3.0.
|
166
|
+
|
167
|
+
On Linux, process time is measured using the clock method provided
|
168
|
+
by the C runtime library. Note that the clock method does not
|
169
|
+
report time spent in the kernel or child processes and therefore
|
170
|
+
does not measure time spent in methods such as Kernel.sleep method.
|
171
|
+
If you need to measure these values, then use wall time. Wall time
|
172
|
+
is measured using the gettimeofday kernel method.
|
173
|
+
|
174
|
+
On Windows, timings are always wall times. If you set the clock
|
175
|
+
mode to PROCESS_TIME, then timing are read using the clock method
|
176
|
+
provided by the C runtime library. Note though, these values are
|
177
|
+
wall times on Windows and not process times like on Linux.
|
178
|
+
Wall time is measured using the GetLocalTime API.
|
179
|
+
|
180
|
+
On both platforms, cpu time is measured using the RDTSC assembly
|
181
|
+
function provided by the Pentium and PowerPC platforms. CPU time
|
182
|
+
is dependent on the cpu's frequency. On Linux, ruby-prof attempts
|
183
|
+
to read this value from "/proc/cpuinfo." On Windows, you must
|
184
|
+
specify the clock frequency. This can be done using the
|
185
|
+
RUBY_PROF_CPU_FREQUENCY environment variable:
|
186
|
+
|
187
|
+
export RUBY_PROF_CPU_FREQUENCY=<value>
|
188
|
+
|
189
|
+
You can also directly set the cpu frequency by calling:
|
190
|
+
|
191
|
+
RubyProf.cpu_frequency = <value>
|
192
|
+
|
193
|
+
|
194
|
+
== Recursive Calls
|
195
|
+
|
196
|
+
Recursive calls occur when method A calls method A and cycles
|
197
|
+
occur when method A calls method B calls method C calls method A.
|
198
|
+
ruby-prof can detect recursive calls any cycle calls, but does not
|
199
|
+
currently report these in its output.
|
200
|
+
|
201
|
+
However, the self time values for recursive calls should always
|
202
|
+
be accurate. It is also believed that the total times are
|
203
|
+
accurate, but these should be carefully analyzed to verify their veracity.
|
204
|
+
|
205
|
+
== Performance
|
206
|
+
|
207
|
+
Significant effort has been put into reducing ruby-prof's overhead
|
208
|
+
as much as possible. Our tests show that the overhead associated
|
209
|
+
with profiling code varies considerably with the code being
|
210
|
+
profiled. On the low end overhead is around 10% while on the
|
211
|
+
high end its can around 80%.
|
212
|
+
|
213
|
+
== Windows Binary
|
214
|
+
|
215
|
+
The Windows binary is built with the latest version of MinGW.
|
216
|
+
|
217
|
+
|
218
|
+
== License
|
219
|
+
|
220
|
+
See LICENSE for license information.
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake/rdoctask'
|
|
5
5
|
SO_NAME = "ruby_prof.so"
|
6
6
|
|
7
7
|
# ------- Default Package ----------
|
8
|
-
RUBY_PROF_VERSION = "0.4.
|
8
|
+
RUBY_PROF_VERSION = "0.4.1"
|
9
9
|
|
10
10
|
FILES = FileList[
|
11
11
|
'Rakefile',
|
@@ -73,8 +73,8 @@ end
|
|
73
73
|
|
74
74
|
# Rake task to build the default package
|
75
75
|
Rake::GemPackageTask.new(default_spec) do |pkg|
|
76
|
-
|
77
|
-
pkg.need_tar =
|
76
|
+
pkg.need_tar = true
|
77
|
+
pkg.need_tar = true
|
78
78
|
end
|
79
79
|
|
80
80
|
|