ruby-prof 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGES +17 -0
  2. data/LICENSE +23 -0
  3. data/README +220 -0
  4. data/Rakefile +141 -0
  5. data/bin/ruby-prof +154 -0
  6. data/doc/classes/RubyProf.html +563 -0
  7. data/doc/classes/RubyProf/CallInfo.html +274 -0
  8. data/doc/classes/RubyProf/FlatPrinter.html +207 -0
  9. data/doc/classes/RubyProf/GraphHtmlPrinter.html +538 -0
  10. data/doc/classes/RubyProf/GraphPrinter.html +240 -0
  11. data/doc/classes/RubyProf/MethodInfo.html +556 -0
  12. data/doc/classes/RubyProf/ProfileTask.html +395 -0
  13. data/doc/classes/RubyProf/Result.html +234 -0
  14. data/doc/created.rid +1 -0
  15. data/doc/files/LICENSE.html +142 -0
  16. data/doc/files/README.html +376 -0
  17. data/doc/files/bin/ruby-prof.html +143 -0
  18. data/doc/files/examples/flat_txt.html +187 -0
  19. data/doc/files/examples/graph_html.html +948 -0
  20. data/doc/files/examples/graph_txt.html +305 -0
  21. data/doc/files/ext/ruby_prof_c.html +101 -0
  22. data/doc/files/lib/ruby-prof/flat_printer_rb.html +101 -0
  23. data/doc/files/lib/ruby-prof/graph_html_printer_rb.html +108 -0
  24. data/doc/files/lib/ruby-prof/graph_printer_rb.html +101 -0
  25. data/doc/files/lib/ruby-prof/profiletask_rb.html +109 -0
  26. data/doc/files/lib/ruby-prof_rb.html +111 -0
  27. data/doc/files/lib/unprof_rb.html +108 -0
  28. data/doc/fr_class_index.html +34 -0
  29. data/doc/fr_file_index.html +39 -0
  30. data/doc/fr_method_index.html +67 -0
  31. data/doc/index.html +24 -0
  32. data/doc/rdoc-style.css +208 -0
  33. data/examples/flat.txt +57 -0
  34. data/examples/graph.html +827 -0
  35. data/examples/graph.txt +171 -0
  36. data/ext/extconf.rb +19 -0
  37. data/ext/ruby_prof.c +1433 -0
  38. data/lib/ruby-prof.rb +38 -0
  39. data/lib/ruby-prof/flat_printer.rb +76 -0
  40. data/lib/ruby-prof/graph_html_printer.rb +227 -0
  41. data/lib/ruby-prof/graph_printer.rb +142 -0
  42. data/lib/ruby-prof/profiletask.rb +150 -0
  43. data/lib/unprof.rb +8 -0
  44. data/test/basic_test.rb +141 -0
  45. data/test/clock_mode_test.rb +73 -0
  46. data/test/module_test.rb +45 -0
  47. data/test/prime.rb +58 -0
  48. data/test/prime_test.rb +24 -0
  49. data/test/printers_test.rb +28 -0
  50. data/test/recursive_test.rb +55 -0
  51. data/test/test.rb +3 -0
  52. data/test/test_helper.rb +45 -0
  53. data/test/test_suite.rb +9 -0
  54. data/test/thread_test.rb +32 -0
  55. data/test/timing_test.rb +90 -0
  56. metadata +121 -0
@@ -0,0 +1,563 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: RubyProf</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">RubyProf</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/ruby-prof_rb.html">
59
+ lib/ruby-prof.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/ruby-prof/flat_printer_rb.html">
63
+ lib/ruby-prof/flat_printer.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/ruby-prof/graph_html_printer_rb.html">
67
+ lib/ruby-prof/graph_html_printer.rb
68
+ </a>
69
+ <br />
70
+ <a href="../files/lib/ruby-prof/graph_printer_rb.html">
71
+ lib/ruby-prof/graph_printer.rb
72
+ </a>
73
+ <br />
74
+ <a href="../files/lib/ruby-prof/profiletask_rb.html">
75
+ lib/ruby-prof/profiletask.rb
76
+ </a>
77
+ <br />
78
+ <a href="../files/ext/ruby_prof_c.html">
79
+ ext/ruby_prof.c
80
+ </a>
81
+ <br />
82
+ </td>
83
+ </tr>
84
+
85
+ </table>
86
+ </div>
87
+ <!-- banner header -->
88
+
89
+ <div id="bodyContent">
90
+
91
+
92
+
93
+ <div id="contextContent">
94
+
95
+
96
+
97
+ </div>
98
+
99
+ <div id="method-list">
100
+ <h3 class="section-bar">Methods</h3>
101
+
102
+ <div class="name-list">
103
+ <a href="#M000005">clock_mode</a>&nbsp;&nbsp;
104
+ <a href="#M000006">clock_mode=</a>&nbsp;&nbsp;
105
+ <a href="#M000007">cpu_frequency</a>&nbsp;&nbsp;
106
+ <a href="#M000008">cpu_frequency=</a>&nbsp;&nbsp;
107
+ <a href="#M000001">figure_clock_mode</a>&nbsp;&nbsp;
108
+ <a href="#M000004">profile</a>&nbsp;&nbsp;
109
+ <a href="#M000002">start</a>&nbsp;&nbsp;
110
+ <a href="#M000003">stop</a>&nbsp;&nbsp;
111
+ </div>
112
+ </div>
113
+
114
+ </div>
115
+
116
+
117
+ <!-- if includes -->
118
+
119
+ <div id="section">
120
+
121
+ <div id="class-list">
122
+ <h3 class="section-bar">Classes and Modules</h3>
123
+
124
+ Class <a href="RubyProf/CallInfo.html" class="link">RubyProf::CallInfo</a><br />
125
+ Class <a href="RubyProf/FlatPrinter.html" class="link">RubyProf::FlatPrinter</a><br />
126
+ Class <a href="RubyProf/GraphHtmlPrinter.html" class="link">RubyProf::GraphHtmlPrinter</a><br />
127
+ Class <a href="RubyProf/GraphPrinter.html" class="link">RubyProf::GraphPrinter</a><br />
128
+ Class <a href="RubyProf/MethodInfo.html" class="link">RubyProf::MethodInfo</a><br />
129
+ Class <a href="RubyProf/ProfileTask.html" class="link">RubyProf::ProfileTask</a><br />
130
+ Class <a href="RubyProf/Result.html" class="link">RubyProf::Result</a><br />
131
+
132
+ </div>
133
+
134
+ <div id="constants-list">
135
+ <h3 class="section-bar">Constants</h3>
136
+
137
+ <div class="name-list">
138
+ <table summary="Constants">
139
+ <tr class="top-aligned-row context-row">
140
+ <td class="context-item-name">VERSION</td>
141
+ <td>=</td>
142
+ <td class="context-item-value">rb_str_new2(PROF_VERSION)</td>
143
+ </tr>
144
+ <tr class="top-aligned-row context-row">
145
+ <td class="context-item-name">PROCESS_TIME</td>
146
+ <td>=</td>
147
+ <td class="context-item-value">INT2NUM(CLOCK_MODE_PROCESS)</td>
148
+ </tr>
149
+ <tr class="top-aligned-row context-row">
150
+ <td class="context-item-name">WALL_TIME</td>
151
+ <td>=</td>
152
+ <td class="context-item-value">INT2NUM(CLOCK_MODE_WALL)</td>
153
+ </tr>
154
+ <tr class="top-aligned-row context-row">
155
+ <td class="context-item-name">CPU_TIME</td>
156
+ <td>=</td>
157
+ <td class="context-item-value">INT2NUM(CLOCK_MODE_CPU)</td>
158
+ </tr>
159
+ </table>
160
+ </div>
161
+ </div>
162
+
163
+
164
+
165
+
166
+
167
+
168
+ <!-- if method_list -->
169
+ <div id="methods">
170
+ <h3 class="section-bar">Public Class methods</h3>
171
+
172
+ <div id="method-M000005" class="method-detail">
173
+ <a name="M000005"></a>
174
+
175
+ <div class="method-heading">
176
+ <a href="#M000005" class="method-signature">
177
+ <span class="method-name"><br />
178
+ clock_mode &rarr; clock_mode<br />
179
+ </span>
180
+ </a>
181
+ </div>
182
+
183
+ <div class="method-description">
184
+ <p>
185
+ Returns the current clock mode. Valid values include:
186
+ </p>
187
+ <pre>
188
+ RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock function in the C Runtime library.
189
+ RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
190
+ RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms.
191
+ </pre>
192
+ <p><a class="source-toggle" href="#"
193
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
194
+ <div class="method-source-code" id="M000005-source">
195
+ <pre>
196
+ /* call-seq:
197
+ clock_mode -&gt; clock_mode
198
+
199
+ Returns the current clock mode. Valid values include:
200
+ *RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock function in the C Runtime library.
201
+ *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
202
+ *RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms. */
203
+ static VALUE
204
+ prof_get_clock_mode(VALUE self)
205
+ {
206
+ return INT2NUM(clock_mode);
207
+ }
208
+ </pre>
209
+ </div>
210
+ </div>
211
+ </div>
212
+
213
+ <div id="method-M000006" class="method-detail">
214
+ <a name="M000006"></a>
215
+
216
+ <div class="method-heading">
217
+ <a href="#M000006" class="method-signature">
218
+ <span class="method-name"><br />
219
+ clock_mode=value &rarr; void<br />
220
+ </span>
221
+ </a>
222
+ </div>
223
+
224
+ <div class="method-description">
225
+ <p>
226
+ Specifies the method ruby-prof uses to measure time. Valid values include:
227
+ </p>
228
+ <pre>
229
+ RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock function in the C Runtime library.
230
+ RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
231
+ RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms.
232
+ </pre>
233
+ <p><a class="source-toggle" href="#"
234
+ onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
235
+ <div class="method-source-code" id="M000006-source">
236
+ <pre>
237
+ /* call-seq:
238
+ clock_mode=value -&gt; void
239
+
240
+ Specifies the method ruby-prof uses to measure time. Valid values include:
241
+ *RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock function in the C Runtime library.
242
+ *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
243
+ *RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms. */
244
+ static VALUE
245
+ prof_set_clock_mode(VALUE self, VALUE val)
246
+ {
247
+ int mode = NUM2INT(val);
248
+
249
+ if (threads_tbl)
250
+ {
251
+ rb_raise(rb_eRuntimeError, &quot;can't set clock_mode while profiling&quot;);
252
+ }
253
+
254
+ switch (mode) {
255
+ case CLOCK_MODE_PROCESS:
256
+ get_clock = clock_get_clock;
257
+ clock2sec = clock_clock2sec;
258
+ break;
259
+ case CLOCK_MODE_WALL:
260
+ get_clock = gettimeofday_get_clock;
261
+ clock2sec = gettimeofday_clock2sec;
262
+ break;
263
+ #ifdef CLOCK_MODE_CPU
264
+ case CLOCK_MODE_CPU:
265
+ if (cpu_frequency == 0)
266
+ cpu_frequency = get_cpu_frequency();
267
+ get_clock = cpu_get_clock;
268
+ clock2sec = cpu_clock2sec;
269
+ break;
270
+ #endif
271
+ default:
272
+ rb_raise(rb_eArgError, &quot;invalid mode: %d&quot;, mode);
273
+ break;
274
+ }
275
+ clock_mode = mode;
276
+ return val;
277
+ }
278
+ </pre>
279
+ </div>
280
+ </div>
281
+ </div>
282
+
283
+ <div id="method-M000007" class="method-detail">
284
+ <a name="M000007"></a>
285
+
286
+ <div class="method-heading">
287
+ <a href="#M000007" class="method-signature">
288
+ <span class="method-name"><br />
289
+ cpu_frequency &rarr; int<br />
290
+ </span>
291
+ </a>
292
+ </div>
293
+
294
+ <div class="method-description">
295
+ <p>
296
+ Returns the cpu&#8217;s frequency. This value is needed when using the cpu
297
+ RubyProf::clock_mode.
298
+ </p>
299
+ <p><a class="source-toggle" href="#"
300
+ onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
301
+ <div class="method-source-code" id="M000007-source">
302
+ <pre>
303
+ /* call-seq:
304
+ cpu_frequency -&gt; int
305
+
306
+ Returns the cpu's frequency. This value is needed when using the
307
+ cpu RubyProf::clock_mode. */
308
+ static VALUE
309
+ prof_get_cpu_frequency(VALUE self)
310
+ {
311
+ return rb_float_new(cpu_frequency);
312
+ }
313
+ </pre>
314
+ </div>
315
+ </div>
316
+ </div>
317
+
318
+ <div id="method-M000008" class="method-detail">
319
+ <a name="M000008"></a>
320
+
321
+ <div class="method-heading">
322
+ <a href="#M000008" class="method-signature">
323
+ <span class="method-name"><br />
324
+ cpu_frequency=value &rarr; void<br />
325
+ </span>
326
+ </a>
327
+ </div>
328
+
329
+ <div class="method-description">
330
+ <p>
331
+ Sets the cpu&#8217;s frequency. This value is needed when using the cpu
332
+ RubyProf::clock_mode.
333
+ </p>
334
+ <p><a class="source-toggle" href="#"
335
+ onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
336
+ <div class="method-source-code" id="M000008-source">
337
+ <pre>
338
+ /* call-seq:
339
+ cpu_frequency=value -&gt; void
340
+
341
+ Sets the cpu's frequency. This value is needed when using the
342
+ cpu RubyProf::clock_mode. */
343
+ static VALUE
344
+ prof_set_cpu_freqeuncy(VALUE self, VALUE val)
345
+ {
346
+ cpu_frequency = NUM2DBL(val);
347
+ return val;
348
+ }
349
+ </pre>
350
+ </div>
351
+ </div>
352
+ </div>
353
+
354
+ <div id="method-M000001" class="method-detail">
355
+ <a name="M000001"></a>
356
+
357
+ <div class="method-heading">
358
+ <a href="#M000001" class="method-signature">
359
+ <span class="method-name">figure_clock_mode</span><span class="method-args">()</span>
360
+ </a>
361
+ </div>
362
+
363
+ <div class="method-description">
364
+ <p>
365
+ See if the user specified the clock mode via the RUBY_PROF_CLOCK_MODE
366
+ environment variable
367
+ </p>
368
+ <p><a class="source-toggle" href="#"
369
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
370
+ <div class="method-source-code" id="M000001-source">
371
+ <pre>
372
+ <span class="ruby-comment cmt"># File lib/ruby-prof.rb, line 10</span>
373
+ 10: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">figure_clock_mode</span>
374
+ 11: <span class="ruby-keyword kw">case</span> <span class="ruby-constant">ENV</span>[<span class="ruby-value str">&quot;RUBY_PROF_CLOCK_MODE&quot;</span>]
375
+ 12: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;wall&quot;</span> <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;wall_time&quot;</span>
376
+ 13: <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">clock_mode</span> = <span class="ruby-constant">RubyProf</span><span class="ruby-operator">::</span><span class="ruby-constant">WALL_TIME</span>
377
+ 14: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;cpu&quot;</span> <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;cpu_time&quot;</span>
378
+ 15: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">ENV</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value str">&quot;RUBY_PROF_CPU_FREQUENCY&quot;</span>)
379
+ 16: <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">cpu_frequency</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">&quot;RUBY_PROF_CPU_FREQUENCY&quot;</span>].<span class="ruby-identifier">to_f</span>
380
+ 17: <span class="ruby-keyword kw">else</span>
381
+ 18: <span class="ruby-keyword kw">begin</span>
382
+ 19: <span class="ruby-identifier">open</span>(<span class="ruby-value str">&quot;/proc/cpuinfo&quot;</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
383
+ 20: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
384
+ 21: <span class="ruby-identifier">s</span> = <span class="ruby-identifier">line</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-regexp re">/cpu MHz\s*:\s*(.*)/</span>, <span class="ruby-value">1</span>)
385
+ 22: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>
386
+ 23: <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">cpu_frequency</span> = <span class="ruby-identifier">s</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">*</span> <span class="ruby-value">1000000</span>
387
+ 24: <span class="ruby-keyword kw">break</span>
388
+ 25: <span class="ruby-keyword kw">end</span>
389
+ 26: <span class="ruby-keyword kw">end</span>
390
+ 27: <span class="ruby-keyword kw">end</span>
391
+ 28: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ENOENT</span>
392
+ 29: <span class="ruby-keyword kw">end</span>
393
+ 30: <span class="ruby-keyword kw">end</span>
394
+ 31: <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">clock_mode</span> = <span class="ruby-constant">RubyProf</span><span class="ruby-operator">::</span><span class="ruby-constant">CPU_TIME</span>
395
+ 32: <span class="ruby-keyword kw">else</span>
396
+ 33: <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">clock_mode</span> = <span class="ruby-constant">RubyProf</span><span class="ruby-operator">::</span><span class="ruby-constant">PROCESS_TIME</span>
397
+ 34: <span class="ruby-keyword kw">end</span>
398
+ 35: <span class="ruby-keyword kw">end</span>
399
+ </pre>
400
+ </div>
401
+ </div>
402
+ </div>
403
+
404
+ <h3 class="section-bar">Public Instance methods</h3>
405
+
406
+ <div id="method-M000004" class="method-detail">
407
+ <a name="M000004"></a>
408
+
409
+ <div class="method-heading">
410
+ <a href="#M000004" class="method-signature">
411
+ <span class="method-name"><br />
412
+ profile {block} &rarr; RubyProf::Result<br />
413
+ </span>
414
+ </a>
415
+ </div>
416
+
417
+ <div class="method-description">
418
+ <p>
419
+ Profiles the specified block and returns a <a
420
+ href="RubyProf/Result.html">RubyProf::Result</a> object.
421
+ </p>
422
+ <p><a class="source-toggle" href="#"
423
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
424
+ <div class="method-source-code" id="M000004-source">
425
+ <pre>
426
+ /* call-seq:
427
+ profile {block} -&gt; RubyProf::Result
428
+
429
+ Profiles the specified block and returns a RubyProf::Result object. */
430
+ static VALUE
431
+ prof_profile(VALUE self)
432
+ {
433
+ if (!rb_block_given_p())
434
+ {
435
+ rb_raise(rb_eArgError, &quot;A block must be provided to the profile method.&quot;);
436
+ }
437
+
438
+ prof_start(self);
439
+ rb_yield(Qnil);
440
+ return prof_stop(self);
441
+ }
442
+ </pre>
443
+ </div>
444
+ </div>
445
+ </div>
446
+
447
+ <div id="method-M000002" class="method-detail">
448
+ <a name="M000002"></a>
449
+
450
+ <div class="method-heading">
451
+ <a href="#M000002" class="method-signature">
452
+ <span class="method-name"><br />
453
+ start &rarr; void<br />
454
+ </span>
455
+ </a>
456
+ </div>
457
+
458
+ <div class="method-description">
459
+ <p>
460
+ Starts recording profile data.
461
+ </p>
462
+ <p><a class="source-toggle" href="#"
463
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
464
+ <div class="method-source-code" id="M000002-source">
465
+ <pre>
466
+ /* call-seq:
467
+ start -&gt; void
468
+
469
+ Starts recording profile data.*/
470
+ static VALUE
471
+ prof_start(VALUE self)
472
+ {
473
+ toplevel_id = rb_intern(&quot;toplevel&quot;);
474
+ toplevel_key = method_key(Qnil, toplevel_id);
475
+
476
+ if (threads_tbl != NULL)
477
+ {
478
+ rb_raise(rb_eRuntimeError, &quot;RubyProf.start was already called&quot;);
479
+ }
480
+
481
+ /* Setup globals */
482
+ class_tbl = rb_hash_new();
483
+ threads_tbl = threads_table_create();
484
+
485
+ rb_add_event_hook(prof_event_hook,
486
+ RUBY_EVENT_CALL | RUBY_EVENT_RETURN |
487
+ RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN);
488
+
489
+ return Qnil;
490
+ }
491
+ </pre>
492
+ </div>
493
+ </div>
494
+ </div>
495
+
496
+ <div id="method-M000003" class="method-detail">
497
+ <a name="M000003"></a>
498
+
499
+ <div class="method-heading">
500
+ <a href="#M000003" class="method-signature">
501
+ <span class="method-name"><br />
502
+ stop &rarr; RubyProf::Result<br />
503
+ </span>
504
+ </a>
505
+ </div>
506
+
507
+ <div class="method-description">
508
+ <p>
509
+ Stops collecting profile data and returns a <a
510
+ href="RubyProf/Result.html">RubyProf::Result</a> object.
511
+ </p>
512
+ <p><a class="source-toggle" href="#"
513
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
514
+ <div class="method-source-code" id="M000003-source">
515
+ <pre>
516
+ /* call-seq:
517
+ stop -&gt; RubyProf::Result
518
+
519
+ Stops collecting profile data and returns a RubyProf::Result object. */
520
+ static VALUE
521
+ prof_stop(VALUE self)
522
+ {
523
+ VALUE result = Qnil;
524
+
525
+ if (threads_tbl == NULL)
526
+ {
527
+ rb_raise(rb_eRuntimeError, &quot;RubyProf.start is not called yet&quot;);
528
+ }
529
+
530
+ /* Now unregister from event */
531
+ rb_remove_event_hook(prof_event_hook);
532
+
533
+ /* Create the result */
534
+ result = prof_result_new();
535
+
536
+ /* Free threads table */
537
+ free_threads(threads_tbl);
538
+ threads_table_free(threads_tbl);
539
+ threads_tbl = NULL;
540
+
541
+ /* Free reference to class_tbl */
542
+ class_tbl = Qnil;
543
+
544
+ return result;
545
+ }
546
+ </pre>
547
+ </div>
548
+ </div>
549
+ </div>
550
+
551
+
552
+ </div>
553
+
554
+
555
+ </div>
556
+
557
+
558
+ <div id="validator-badges">
559
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
560
+ </div>
561
+
562
+ </body>
563
+ </html>