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.
Files changed (45) hide show
  1. data/README +220 -220
  2. data/Rakefile +3 -3
  3. data/doc/created.rid +1 -1
  4. data/doc/files/LICENSE.html +0 -142
  5. data/doc/files/README.html +2 -2
  6. data/doc/files/examples/flat_txt.html +8 -16
  7. data/doc/files/examples/graph_txt.html +10 -18
  8. data/doc/files/ext/ruby_prof_c.html +1 -1
  9. data/doc/files/lib/ruby-prof/flat_printer_rb.html +1 -1
  10. data/doc/files/lib/ruby-prof/graph_html_printer_rb.html +1 -1
  11. data/doc/files/lib/ruby-prof/graph_printer_rb.html +1 -1
  12. data/examples/flat.txt +55 -57
  13. data/examples/graph.html +827 -827
  14. data/examples/graph.txt +170 -171
  15. data/ext/ruby_prof.c +35 -20
  16. data/lib/ruby-prof/flat_printer.rb +8 -9
  17. data/lib/ruby-prof/graph_html_printer.rb +3 -2
  18. data/lib/ruby-prof/graph_printer.rb +4 -5
  19. data/lib/ruby_prof.so +0 -0
  20. data/test/basic_test.rb +148 -141
  21. data/test/clock_mode_test.rb +72 -72
  22. data/test/duplicate_names_test.rb +37 -0
  23. data/test/module_test.rb +45 -45
  24. data/test/prime.rb +58 -58
  25. data/test/prime_test.rb +23 -23
  26. data/test/printers_test.rb +27 -27
  27. data/test/recursive_test.rb +55 -55
  28. data/test/test_helper.rb +45 -45
  29. data/test/test_suite.rb +10 -9
  30. data/test/thread_test.rb +32 -32
  31. data/test/timing_test.rb +90 -90
  32. metadata +3 -16
  33. data/doc/classes/RubyProf.html +0 -563
  34. data/doc/classes/RubyProf/CallInfo.html +0 -274
  35. data/doc/classes/RubyProf/FlatPrinter.html +0 -207
  36. data/doc/classes/RubyProf/GraphHtmlPrinter.html +0 -538
  37. data/doc/classes/RubyProf/GraphPrinter.html +0 -240
  38. data/doc/classes/RubyProf/MethodInfo.html +0 -556
  39. data/doc/classes/RubyProf/ProfileTask.html +0 -395
  40. data/doc/classes/RubyProf/Result.html +0 -234
  41. data/doc/fr_class_index.html +0 -34
  42. data/doc/fr_file_index.html +0 -39
  43. data/doc/fr_method_index.html +0 -67
  44. data/doc/index.html +0 -24
  45. data/test/test.rb +0 -3
@@ -1,45 +1,45 @@
1
- def print_results(result)
2
- printer = RubyProf::FlatPrinter.new(result)
3
- printer.print(STDOUT)
4
-
5
- STDOUT << "\n" * 2
6
-
7
- printer = RubyProf::GraphPrinter.new(result)
8
- printer.print(STDOUT)
9
- end
10
-
11
- def check_parent_times(method)
12
- return if method.parents.length == 0
13
-
14
- parents_self_time = method.parents.values.inject(0) do |sum, call_info|
15
- sum + call_info.self_time
16
- end
17
- assert_in_delta(method.self_time, parents_self_time, 0.01, method.name)
18
-
19
- parents_children_time = method.parents.values.inject(0) do |sum, call_info|
20
- sum + call_info.children_time
21
- end
22
- assert_in_delta(method.children_time, parents_children_time, 0.01, method.name)
23
- end
24
-
25
- def check_parent_calls(method)
26
- return if method.parents.length == 0
27
-
28
- parent_calls = method.parents.values.inject(0) do |sum, call_info|
29
- sum + call_info.called
30
- end
31
- assert_equal(method.called, parent_calls, method.name)
32
- end
33
-
34
- def check_child_times(method)
35
- return if method.children.length == 0
36
-
37
- children_total_time = method.children.values.inject(0) do |sum, call_info|
38
- sum + call_info.total_time
39
- end
40
-
41
- assert_in_delta(method.children_time, children_total_time, 0.01, method.name)
42
- end
43
-
44
-
45
-
1
+ def print_results(result)
2
+ printer = RubyProf::FlatPrinter.new(result)
3
+ printer.print(STDOUT)
4
+
5
+ STDOUT << "\n" * 2
6
+
7
+ printer = RubyProf::GraphPrinter.new(result)
8
+ printer.print(STDOUT)
9
+ end
10
+
11
+ def check_parent_times(method)
12
+ return if method.parents.length == 0
13
+
14
+ parents_self_time = method.parents.values.inject(0) do |sum, call_info|
15
+ sum + call_info.self_time
16
+ end
17
+ assert_in_delta(method.self_time, parents_self_time, 0.01, method.name)
18
+
19
+ parents_children_time = method.parents.values.inject(0) do |sum, call_info|
20
+ sum + call_info.children_time
21
+ end
22
+ assert_in_delta(method.children_time, parents_children_time, 0.01, method.name)
23
+ end
24
+
25
+ def check_parent_calls(method)
26
+ return if method.parents.length == 0
27
+
28
+ parent_calls = method.parents.values.inject(0) do |sum, call_info|
29
+ sum + call_info.called
30
+ end
31
+ assert_equal(method.called, parent_calls, method.name)
32
+ end
33
+
34
+ def check_child_times(method)
35
+ return if method.children.length == 0
36
+
37
+ children_total_time = method.children.values.inject(0) do |sum, call_info|
38
+ sum + call_info.total_time
39
+ end
40
+
41
+ assert_in_delta(method.children_time, children_total_time, 0.01, method.name)
42
+ end
43
+
44
+
45
+
@@ -1,9 +1,10 @@
1
- # file ts_dbaccess.rb
2
- require 'test/unit'
3
- require 'basic_test'
4
- require 'module_test'
5
- require 'timing_test'
6
- require 'prime_test'
7
- require 'printers_test'
8
- require 'recursive_test'
9
- require 'thread_test'
1
+ # file ts_dbaccess.rb
2
+ require 'test/unit'
3
+ require 'basic_test'
4
+ require 'module_test'
5
+ require 'duplicate_names_test'
6
+ require 'timing_test'
7
+ require 'prime_test'
8
+ require 'printers_test'
9
+ require 'recursive_test'
10
+ require 'thread_test'
@@ -1,32 +1,32 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'ruby-prof'
5
- require 'timeout'
6
- require 'test_helper'
7
-
8
- # -- Tests ----
9
- class ThreadTest < Test::Unit::TestCase
10
- def test_thread
11
- RubyProf.start
12
-
13
- begin
14
- status = Timeout::timeout(2) do
15
- while true
16
- next
17
- end
18
- end
19
- rescue Timeout::Error
20
- end
21
-
22
- result = RubyProf.stop
23
-
24
- result.threads.values.each do |methods|
25
- methods.values.each do |method|
26
- check_parent_times(method)
27
- check_parent_calls(method)
28
- check_child_times(method)
29
- end
30
- end
31
- end
32
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'timeout'
6
+ require 'test_helper'
7
+
8
+ # -- Tests ----
9
+ class ThreadTest < Test::Unit::TestCase
10
+ def test_thread
11
+ RubyProf.start
12
+
13
+ begin
14
+ status = Timeout::timeout(2) do
15
+ while true
16
+ next
17
+ end
18
+ end
19
+ rescue Timeout::Error
20
+ end
21
+
22
+ result = RubyProf.stop
23
+
24
+ result.threads.values.each do |methods|
25
+ methods.values.each do |method|
26
+ check_parent_times(method)
27
+ check_parent_calls(method)
28
+ check_child_times(method)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,90 +1,90 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'ruby-prof'
5
- require 'test_helper'
6
-
7
- def method1
8
- sleep(1)
9
- end
10
-
11
- def method2
12
- sleep(2)
13
- method1
14
- end
15
-
16
- def method3
17
- sleep(3)
18
- method2
19
- method1
20
- end
21
-
22
- # Need to use wall time for this test due to the sleep calls
23
- RubyProf::clock_mode = RubyProf::WALL_TIME
24
-
25
- class TimingTest < Test::Unit::TestCase
26
-
27
- def test_basic
28
- result = RubyProf.profile do
29
- method1
30
- end
31
-
32
- assert_equal(1, result.threads.length)
33
-
34
- methods = result.threads.values.first
35
- assert_equal(3, methods.length)
36
-
37
- method = methods['#toplevel']
38
- assert_not_nil(method)
39
- assert_in_delta(1, method.total_time, 0.02)
40
- assert_in_delta(0, method.self_time, 0.02)
41
- assert_in_delta(1, method.called, 0.02)
42
- assert_equal(0, method.parents.length)
43
- assert_equal(1, method.children.length)
44
-
45
- method = methods['Object#method1']
46
- assert_not_nil(method)
47
- assert_in_delta(1, method.total_time, 0.02)
48
- assert_in_delta(0, method.self_time, 0.02)
49
- assert_equal(1, method.called)
50
- assert_equal(1, method.parents.length)
51
- assert_equal(1, method.children.length)
52
-
53
- sleep = methods['Kernel#sleep']
54
- assert_not_nil(sleep)
55
- assert_in_delta(1, sleep.total_time, 0.02)
56
- assert_in_delta(1, sleep.self_time, 0.02)
57
- assert_in_delta(0, sleep.children_time, 0.02)
58
- assert_equal(1, sleep.called)
59
- assert_equal(1, sleep.parents.length)
60
- assert_equal(0, sleep.children.length)
61
- end
62
-
63
- def test_timings
64
- result = RubyProf.profile do
65
- method3
66
- end
67
-
68
- assert_equal(1, result.threads.length)
69
- methods = result.threads.values.first
70
- assert_equal(5, methods.length)
71
-
72
- method = methods['#toplevel']
73
- assert_not_nil(method)
74
- assert_in_delta(7, method.total_time, 0.02)
75
- assert_in_delta(0, method.self_time, 0.02)
76
- assert_in_delta(7, method.children_time, 0.02)
77
- assert_equal(1, method.called)
78
- assert_equal(0, method.parents.length)
79
- assert_equal(1, method.children.length)
80
-
81
- method = methods['Object#method3']
82
- assert_not_nil(method)
83
- assert_in_delta(7, method.total_time, 0.02)
84
- assert_in_delta(0, method.self_time, 0.02)
85
- assert_in_delta(7, method.children_time, 0.02)
86
- assert_equal(1, method.called)
87
- assert_equal(1, method.parents.length)
88
- assert_equal(3, method.children.length)
89
- end
90
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'test_helper'
6
+
7
+ def method1
8
+ sleep(1)
9
+ end
10
+
11
+ def method2
12
+ sleep(2)
13
+ method1
14
+ end
15
+
16
+ def method3
17
+ sleep(3)
18
+ method2
19
+ method1
20
+ end
21
+
22
+ # Need to use wall time for this test due to the sleep calls
23
+ RubyProf::clock_mode = RubyProf::WALL_TIME
24
+
25
+ class TimingTest < Test::Unit::TestCase
26
+
27
+ def test_basic
28
+ result = RubyProf.profile do
29
+ method1
30
+ end
31
+
32
+ assert_equal(1, result.threads.length)
33
+
34
+ methods = result.threads.values.first
35
+ assert_equal(3, methods.length)
36
+
37
+ method = methods['#toplevel']
38
+ assert_not_nil(method)
39
+ assert_in_delta(1, method.total_time, 0.02)
40
+ assert_in_delta(0, method.self_time, 0.02)
41
+ assert_in_delta(1, method.called, 0.02)
42
+ assert_equal(0, method.parents.length)
43
+ assert_equal(1, method.children.length)
44
+
45
+ method = methods['Object#method1']
46
+ assert_not_nil(method)
47
+ assert_in_delta(1, method.total_time, 0.02)
48
+ assert_in_delta(0, method.self_time, 0.02)
49
+ assert_equal(1, method.called)
50
+ assert_equal(1, method.parents.length)
51
+ assert_equal(1, method.children.length)
52
+
53
+ sleep = methods['Kernel#sleep']
54
+ assert_not_nil(sleep)
55
+ assert_in_delta(1, sleep.total_time, 0.02)
56
+ assert_in_delta(1, sleep.self_time, 0.02)
57
+ assert_in_delta(0, sleep.children_time, 0.02)
58
+ assert_equal(1, sleep.called)
59
+ assert_equal(1, sleep.parents.length)
60
+ assert_equal(0, sleep.children.length)
61
+ end
62
+
63
+ def test_timings
64
+ result = RubyProf.profile do
65
+ method3
66
+ end
67
+
68
+ assert_equal(1, result.threads.length)
69
+ methods = result.threads.values.first
70
+ assert_equal(5, methods.length)
71
+
72
+ method = methods['#toplevel']
73
+ assert_not_nil(method)
74
+ assert_in_delta(7, method.total_time, 0.02)
75
+ assert_in_delta(0, method.self_time, 0.02)
76
+ assert_in_delta(7, method.children_time, 0.02)
77
+ assert_equal(1, method.called)
78
+ assert_equal(0, method.parents.length)
79
+ assert_equal(1, method.children.length)
80
+
81
+ method = methods['Object#method3']
82
+ assert_not_nil(method)
83
+ assert_in_delta(7, method.total_time, 0.02)
84
+ assert_in_delta(0, method.self_time, 0.02)
85
+ assert_in_delta(7, method.children_time, 0.02)
86
+ assert_equal(1, method.called)
87
+ assert_equal(1, method.parents.length)
88
+ assert_equal(3, method.children.length)
89
+ end
90
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ruby-prof
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.0
7
- date: 2006-06-21 01:45:45 -06:00
6
+ version: 0.4.1
7
+ date: 2006-06-22 15:36:48 -06:00
8
8
  summary: Fast Ruby profiler
9
9
  require_paths:
10
10
  - lib
@@ -49,20 +49,7 @@ files:
49
49
  - doc/classes
50
50
  - doc/created.rid
51
51
  - doc/files
52
- - doc/fr_class_index.html
53
- - doc/fr_file_index.html
54
- - doc/fr_method_index.html
55
- - doc/index.html
56
52
  - doc/rdoc-style.css
57
- - doc/classes/RubyProf
58
- - doc/classes/RubyProf.html
59
- - doc/classes/RubyProf/CallInfo.html
60
- - doc/classes/RubyProf/FlatPrinter.html
61
- - doc/classes/RubyProf/GraphHtmlPrinter.html
62
- - doc/classes/RubyProf/GraphPrinter.html
63
- - doc/classes/RubyProf/MethodInfo.html
64
- - doc/classes/RubyProf/ProfileTask.html
65
- - doc/classes/RubyProf/Result.html
66
53
  - doc/files/bin
67
54
  - doc/files/examples
68
55
  - doc/files/ext
@@ -83,12 +70,12 @@ files:
83
70
  - doc/files/lib/ruby-prof/profiletask_rb.html
84
71
  - test/basic_test.rb
85
72
  - test/clock_mode_test.rb
73
+ - test/duplicate_names_test.rb
86
74
  - test/module_test.rb
87
75
  - test/prime.rb
88
76
  - test/prime_test.rb
89
77
  - test/printers_test.rb
90
78
  - test/recursive_test.rb
91
- - test/test.rb
92
79
  - test/test_helper.rb
93
80
  - test/test_suite.rb
94
81
  - test/thread_test.rb
@@ -1,563 +0,0 @@
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>