ruby-prof 0.8.1-x86-mingw32 → 0.11.0.rc1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +89 -13
- data/LICENSE +4 -3
- data/{README → README.rdoc} +155 -162
- data/Rakefile +50 -123
- data/bin/ruby-prof +86 -47
- data/examples/empty.png +0 -0
- data/examples/graph.dot +106 -0
- data/examples/graph.png +0 -0
- data/examples/minus.png +0 -0
- data/examples/multi.flat.txt +23 -0
- data/examples/multi.graph.html +906 -0
- data/examples/multi.grind.dat +194 -0
- data/examples/multi.stack.html +573 -0
- data/examples/plus.png +0 -0
- data/examples/stack.html +573 -0
- data/ext/ruby_prof/extconf.rb +53 -0
- data/ext/ruby_prof/rp_call_info.c +369 -0
- data/ext/ruby_prof/rp_call_info.h +46 -0
- data/ext/ruby_prof/rp_measure.c +48 -0
- data/ext/ruby_prof/rp_measure.h +45 -0
- data/ext/ruby_prof/rp_measure_allocations.c +86 -0
- data/ext/ruby_prof/rp_measure_cpu_time.c +112 -0
- data/ext/ruby_prof/rp_measure_gc_runs.c +87 -0
- data/ext/ruby_prof/rp_measure_gc_time.c +73 -0
- data/ext/ruby_prof/rp_measure_memory.c +81 -0
- data/ext/ruby_prof/rp_measure_process_time.c +71 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +42 -0
- data/ext/ruby_prof/rp_method.c +363 -0
- data/ext/ruby_prof/rp_method.h +55 -0
- data/ext/ruby_prof/rp_stack.c +61 -0
- data/ext/ruby_prof/rp_stack.h +40 -0
- data/ext/ruby_prof/rp_thread.c +113 -0
- data/ext/ruby_prof/rp_thread.h +20 -0
- data/ext/ruby_prof/ruby_prof.c +332 -1377
- data/ext/ruby_prof/ruby_prof.h +54 -188
- data/ext/ruby_prof/version.h +6 -3
- data/lib/1.8/ruby_prof.so +0 -0
- data/lib/1.9/ruby_prof.exp +0 -0
- data/lib/1.9/ruby_prof.ilk +0 -0
- data/lib/1.9/ruby_prof.lib +0 -0
- data/lib/1.9/ruby_prof.pdb +0 -0
- data/lib/1.9/ruby_prof.so +0 -0
- data/lib/ruby-prof.rb +32 -18
- data/lib/ruby-prof/abstract_printer.rb +15 -5
- data/lib/ruby-prof/aggregate_call_info.rb +11 -3
- data/lib/ruby-prof/call_info.rb +68 -1
- data/lib/ruby-prof/call_stack_printer.rb +775 -0
- data/lib/ruby-prof/call_tree_printer.rb +17 -9
- data/lib/ruby-prof/compatibility.rb +134 -0
- data/lib/ruby-prof/dot_printer.rb +152 -0
- data/lib/ruby-prof/empty.png +0 -0
- data/lib/ruby-prof/flat_printer.rb +23 -24
- data/lib/ruby-prof/flat_printer_with_line_numbers.rb +17 -21
- data/lib/ruby-prof/graph_html_printer.rb +69 -39
- data/lib/ruby-prof/graph_printer.rb +35 -35
- data/lib/ruby-prof/method_info.rb +26 -4
- data/lib/ruby-prof/minus.png +0 -0
- data/lib/ruby-prof/multi_printer.rb +56 -0
- data/lib/ruby-prof/plus.png +0 -0
- data/lib/ruby-prof/profile.rb +72 -0
- data/lib/ruby-prof/rack.rb +31 -0
- data/lib/ruby-prof/symbol_to_proc.rb +3 -1
- data/lib/ruby-prof/task.rb +20 -19
- data/lib/ruby-prof/test.rb +5 -3
- data/lib/ruby_prof.exp +0 -0
- data/lib/ruby_prof.ilk +0 -0
- data/lib/ruby_prof.lib +0 -0
- data/lib/ruby_prof.pdb +0 -0
- data/lib/ruby_prof.so +0 -0
- data/lib/unprof.rb +2 -0
- data/test/aggregate_test.rb +29 -14
- data/test/basic_test.rb +3 -251
- data/test/bug_test.rb +6 -0
- data/test/duplicate_names_test.rb +4 -4
- data/test/dynamic_method_test.rb +61 -0
- data/test/enumerable_test.rb +4 -4
- data/test/exceptions_test.rb +6 -5
- data/test/exclude_threads_test.rb +47 -47
- data/test/exec_test.rb +5 -5
- data/test/line_number_test.rb +16 -16
- data/test/measure_allocations_test.rb +25 -0
- data/test/measure_cpu_time_test.rb +212 -0
- data/test/measure_gc_runs_test.rb +29 -0
- data/test/measure_gc_time_test.rb +29 -0
- data/test/measure_memory_test.rb +36 -0
- data/test/measure_process_time_test.rb +205 -0
- data/test/measure_wall_time_test.rb +209 -0
- data/test/method_elimination_test.rb +74 -0
- data/test/module_test.rb +12 -21
- data/test/multi_printer_test.rb +81 -0
- data/test/no_method_class_test.rb +5 -3
- data/test/prime.rb +7 -10
- data/test/prime_test.rb +3 -3
- data/test/printers_test.rb +180 -54
- data/test/recursive_test.rb +34 -72
- data/test/singleton_test.rb +5 -4
- data/test/stack_printer_test.rb +73 -0
- data/test/stack_test.rb +7 -7
- data/test/start_stop_test.rb +23 -6
- data/test/test_helper.rb +81 -0
- data/test/test_suite.rb +35 -21
- data/test/thread_test.rb +40 -39
- data/test/unique_call_path_test.rb +6 -6
- metadata +106 -51
- data/ext/ruby_prof/measure_allocations.h +0 -58
- data/ext/ruby_prof/measure_cpu_time.h +0 -152
- data/ext/ruby_prof/measure_gc_runs.h +0 -76
- data/ext/ruby_prof/measure_gc_time.h +0 -57
- data/ext/ruby_prof/measure_memory.h +0 -101
- data/ext/ruby_prof/measure_process_time.h +0 -52
- data/ext/ruby_prof/measure_wall_time.h +0 -53
- data/ext/ruby_prof/mingw/Rakefile +0 -23
- data/ext/ruby_prof/mingw/build.rake +0 -38
- data/rails/environment/profile.rb +0 -24
- data/rails/example/example_test.rb +0 -9
- data/rails/profile_test_helper.rb +0 -21
- data/test/current_failures_windows +0 -8
- data/test/measurement_test.rb +0 -121
- data/test/ruby-prof-bin +0 -20
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
2
3
|
|
3
|
-
require '
|
4
|
-
require 'ruby-prof'
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
5
|
|
6
6
|
class UniqueCallPath
|
7
7
|
def method_a(i)
|
@@ -112,7 +112,7 @@ class UniqueCallPathTest < Test::Unit::TestCase
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
assert !call_info_a.nil?
|
115
|
+
assert !call_info_a.nil?
|
116
116
|
|
117
117
|
children_of_a = Array.new
|
118
118
|
|
@@ -121,7 +121,7 @@ class UniqueCallPathTest < Test::Unit::TestCase
|
|
121
121
|
children_of_a.push(c)
|
122
122
|
end
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
if RUBY_VERSION < '1.9'
|
126
126
|
assert_equal(4, call_info_a.target.children.length)
|
127
127
|
else
|
@@ -139,7 +139,7 @@ class UniqueCallPathTest < Test::Unit::TestCase
|
|
139
139
|
assert_equal(1, children_of_a.length)
|
140
140
|
assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
end
|
144
144
|
|
145
145
|
def test_id2ref
|
@@ -222,4 +222,4 @@ class UniqueCallPathTest < Test::Unit::TestCase
|
|
222
222
|
assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
|
223
223
|
end
|
224
224
|
end
|
225
|
-
end
|
225
|
+
end
|
metadata
CHANGED
@@ -1,46 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-prof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15424167
|
5
|
+
prerelease: 7
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 11
|
9
|
+
- 0
|
10
|
+
- rc
|
11
|
+
- 1
|
12
|
+
version: 0.11.0.rc1
|
5
13
|
platform: x86-mingw32
|
6
14
|
authors:
|
7
|
-
- Shugo Maeda, Charlie Savage, Roger Pack
|
15
|
+
- Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes
|
8
16
|
autorequire:
|
9
17
|
bindir: bin
|
10
18
|
cert_chain: []
|
11
19
|
|
12
|
-
date:
|
13
|
-
default_executable:
|
20
|
+
date: 2012-03-24 00:00:00 Z
|
14
21
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: os
|
17
|
-
type: :development
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
25
22
|
- !ruby/object:Gem::Dependency
|
26
23
|
name: rake-compiler
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
30
27
|
requirements:
|
31
28
|
- - ">="
|
32
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
33
|
version: "0"
|
34
|
-
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
35
36
|
description: |
|
36
37
|
ruby-prof is a fast code profiler for Ruby. It is a C extension and
|
37
38
|
therefore is many times faster than the standard Ruby profiler. It
|
38
39
|
supports both flat and graph profiles. For each method, graph profiles
|
39
|
-
show how long the method ran, which methods called it and which
|
40
|
+
show how long the method ran, which methods called it and which
|
40
41
|
methods it called. RubyProf generate both text and html and can output
|
41
42
|
it to standard out or to a file.
|
42
43
|
|
43
|
-
email: shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com
|
44
|
+
email: shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de
|
44
45
|
executables:
|
45
46
|
- ruby-prof
|
46
47
|
extensions: []
|
@@ -49,70 +50,113 @@ extra_rdoc_files: []
|
|
49
50
|
|
50
51
|
files:
|
51
52
|
- Rakefile
|
52
|
-
- README
|
53
|
+
- README.rdoc
|
53
54
|
- LICENSE
|
54
55
|
- CHANGES
|
55
56
|
- bin/ruby-prof
|
57
|
+
- examples/empty.png
|
56
58
|
- examples/flat.txt
|
59
|
+
- examples/graph.dot
|
57
60
|
- examples/graph.html
|
61
|
+
- examples/graph.png
|
58
62
|
- examples/graph.txt
|
63
|
+
- examples/minus.png
|
64
|
+
- examples/multi.flat.txt
|
65
|
+
- examples/multi.graph.html
|
66
|
+
- examples/multi.grind.dat
|
67
|
+
- examples/multi.stack.html
|
68
|
+
- examples/plus.png
|
69
|
+
- examples/stack.html
|
70
|
+
- ext/ruby_prof/rp_call_info.c
|
71
|
+
- ext/ruby_prof/rp_measure.c
|
72
|
+
- ext/ruby_prof/rp_measure_allocations.c
|
73
|
+
- ext/ruby_prof/rp_measure_cpu_time.c
|
74
|
+
- ext/ruby_prof/rp_measure_gc_runs.c
|
75
|
+
- ext/ruby_prof/rp_measure_gc_time.c
|
76
|
+
- ext/ruby_prof/rp_measure_memory.c
|
77
|
+
- ext/ruby_prof/rp_measure_process_time.c
|
78
|
+
- ext/ruby_prof/rp_measure_wall_time.c
|
79
|
+
- ext/ruby_prof/rp_method.c
|
80
|
+
- ext/ruby_prof/rp_stack.c
|
81
|
+
- ext/ruby_prof/rp_thread.c
|
59
82
|
- ext/ruby_prof/ruby_prof.c
|
60
|
-
- ext/ruby_prof/
|
61
|
-
- ext/ruby_prof/
|
62
|
-
- ext/ruby_prof/
|
63
|
-
- ext/ruby_prof/
|
64
|
-
- ext/ruby_prof/
|
65
|
-
- ext/ruby_prof/measure_process_time.h
|
66
|
-
- ext/ruby_prof/measure_wall_time.h
|
83
|
+
- ext/ruby_prof/rp_call_info.h
|
84
|
+
- ext/ruby_prof/rp_measure.h
|
85
|
+
- ext/ruby_prof/rp_method.h
|
86
|
+
- ext/ruby_prof/rp_stack.h
|
87
|
+
- ext/ruby_prof/rp_thread.h
|
67
88
|
- ext/ruby_prof/ruby_prof.h
|
68
89
|
- ext/ruby_prof/version.h
|
69
|
-
-
|
70
|
-
-
|
90
|
+
- lib/1.8/ruby_prof.so
|
91
|
+
- lib/1.9/ruby_prof.exp
|
92
|
+
- lib/1.9/ruby_prof.ilk
|
93
|
+
- lib/1.9/ruby_prof.lib
|
94
|
+
- lib/1.9/ruby_prof.pdb
|
95
|
+
- lib/1.9/ruby_prof.so
|
71
96
|
- lib/ruby-prof/abstract_printer.rb
|
72
97
|
- lib/ruby-prof/aggregate_call_info.rb
|
73
98
|
- lib/ruby-prof/call_info.rb
|
99
|
+
- lib/ruby-prof/call_stack_printer.rb
|
74
100
|
- lib/ruby-prof/call_tree_printer.rb
|
101
|
+
- lib/ruby-prof/compatibility.rb
|
102
|
+
- lib/ruby-prof/dot_printer.rb
|
103
|
+
- lib/ruby-prof/empty.png
|
75
104
|
- lib/ruby-prof/flat_printer.rb
|
105
|
+
- lib/ruby-prof/flat_printer_with_line_numbers.rb
|
76
106
|
- lib/ruby-prof/graph_html_printer.rb
|
77
107
|
- lib/ruby-prof/graph_printer.rb
|
78
108
|
- lib/ruby-prof/method_info.rb
|
109
|
+
- lib/ruby-prof/minus.png
|
110
|
+
- lib/ruby-prof/multi_printer.rb
|
111
|
+
- lib/ruby-prof/plus.png
|
112
|
+
- lib/ruby-prof/profile.rb
|
113
|
+
- lib/ruby-prof/rack.rb
|
79
114
|
- lib/ruby-prof/symbol_to_proc.rb
|
80
115
|
- lib/ruby-prof/task.rb
|
81
116
|
- lib/ruby-prof/test.rb
|
82
|
-
- lib/ruby-prof/flat_printer_with_line_numbers.rb
|
83
117
|
- lib/ruby-prof.rb
|
84
|
-
- lib/
|
118
|
+
- lib/ruby_prof.exp
|
119
|
+
- lib/ruby_prof.ilk
|
120
|
+
- lib/ruby_prof.lib
|
121
|
+
- lib/ruby_prof.pdb
|
122
|
+
- lib/ruby_prof.so
|
85
123
|
- lib/unprof.rb
|
86
|
-
- rails/environment/profile.rb
|
87
|
-
- rails/example/example_test.rb
|
88
|
-
- rails/profile_test_helper.rb
|
89
124
|
- test/aggregate_test.rb
|
90
125
|
- test/basic_test.rb
|
126
|
+
- test/bug_test.rb
|
127
|
+
- test/do_nothing.rb
|
91
128
|
- test/duplicate_names_test.rb
|
129
|
+
- test/dynamic_method_test.rb
|
130
|
+
- test/enumerable_test.rb
|
92
131
|
- test/exceptions_test.rb
|
93
132
|
- test/exclude_threads_test.rb
|
133
|
+
- test/exec_test.rb
|
94
134
|
- test/line_number_test.rb
|
95
|
-
- test/
|
135
|
+
- test/measure_allocations_test.rb
|
136
|
+
- test/measure_cpu_time_test.rb
|
137
|
+
- test/measure_gc_runs_test.rb
|
138
|
+
- test/measure_gc_time_test.rb
|
139
|
+
- test/measure_memory_test.rb
|
140
|
+
- test/measure_process_time_test.rb
|
141
|
+
- test/measure_wall_time_test.rb
|
142
|
+
- test/method_elimination_test.rb
|
96
143
|
- test/module_test.rb
|
144
|
+
- test/multi_printer_test.rb
|
97
145
|
- test/no_method_class_test.rb
|
98
146
|
- test/prime.rb
|
99
147
|
- test/prime_test.rb
|
100
148
|
- test/printers_test.rb
|
101
149
|
- test/recursive_test.rb
|
102
150
|
- test/singleton_test.rb
|
151
|
+
- test/stack_printer_test.rb
|
103
152
|
- test/stack_test.rb
|
104
153
|
- test/start_stop_test.rb
|
154
|
+
- test/test_helper.rb
|
105
155
|
- test/test_suite.rb
|
106
156
|
- test/thread_test.rb
|
107
157
|
- test/unique_call_path_test.rb
|
108
|
-
-
|
109
|
-
|
110
|
-
- test/enumerable_test.rb
|
111
|
-
- test/exec_test.rb
|
112
|
-
- test/ruby-prof-bin
|
113
|
-
- lib/1.9/ruby_prof.so
|
114
|
-
has_rdoc: true
|
115
|
-
homepage: http://rubyforge.org/projects/ruby-prof/
|
158
|
+
- ext/ruby_prof/extconf.rb
|
159
|
+
homepage: https://github.com/rdp/ruby-prof
|
116
160
|
licenses: []
|
117
161
|
|
118
162
|
post_install_message:
|
@@ -121,23 +165,34 @@ rdoc_options: []
|
|
121
165
|
require_paths:
|
122
166
|
- lib
|
123
167
|
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
124
169
|
requirements:
|
125
170
|
- - ">="
|
126
171
|
- !ruby/object:Gem::Version
|
127
|
-
|
128
|
-
|
172
|
+
hash: 57
|
173
|
+
segments:
|
174
|
+
- 1
|
175
|
+
- 8
|
176
|
+
- 7
|
177
|
+
version: 1.8.7
|
129
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
130
180
|
requirements:
|
131
|
-
- - "
|
181
|
+
- - ">"
|
132
182
|
- !ruby/object:Gem::Version
|
133
|
-
|
134
|
-
|
183
|
+
hash: 25
|
184
|
+
segments:
|
185
|
+
- 1
|
186
|
+
- 3
|
187
|
+
- 1
|
188
|
+
version: 1.3.1
|
135
189
|
requirements: []
|
136
190
|
|
137
|
-
rubyforge_project:
|
138
|
-
rubygems_version: 1.
|
191
|
+
rubyforge_project:
|
192
|
+
rubygems_version: 1.8.10
|
139
193
|
signing_key:
|
140
194
|
specification_version: 3
|
141
195
|
summary: Fast Ruby profiler
|
142
196
|
test_files:
|
197
|
+
- test/test_helper.rb
|
143
198
|
- test/test_suite.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
/* :nodoc:
|
2
|
-
* Copyright (C) 2008 Shugo Maeda <shugo@ruby-lang.org>
|
3
|
-
* Charlie Savage <cfis@savagexi.com>
|
4
|
-
* All rights reserved.
|
5
|
-
*
|
6
|
-
* Redistribution and use in source and binary forms, with or without
|
7
|
-
* modification, are permitted provided that the following conditions
|
8
|
-
* are met:
|
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
|
25
|
-
* SUCH DAMAGE. */
|
26
|
-
|
27
|
-
#include <ruby.h>
|
28
|
-
|
29
|
-
#if defined(HAVE_RB_OS_ALLOCATED_OBJECTS)
|
30
|
-
#define MEASURE_ALLOCATIONS 3
|
31
|
-
|
32
|
-
static prof_measure_t
|
33
|
-
measure_allocations()
|
34
|
-
{
|
35
|
-
return rb_os_allocated_objects();
|
36
|
-
}
|
37
|
-
|
38
|
-
static double
|
39
|
-
convert_allocations(prof_measure_t c)
|
40
|
-
{
|
41
|
-
return c;
|
42
|
-
}
|
43
|
-
|
44
|
-
/* Document-method: prof_measure_allocations
|
45
|
-
call-seq:
|
46
|
-
measure_allocations -> int
|
47
|
-
|
48
|
-
Returns the total number of object allocations since Ruby started.*/
|
49
|
-
static VALUE
|
50
|
-
prof_measure_allocations(VALUE self)
|
51
|
-
{
|
52
|
-
#if defined(HAVE_LONG_LONG)
|
53
|
-
return ULL2NUM(rb_os_allocated_objects());
|
54
|
-
#else
|
55
|
-
return ULONG2NUM(rb_os_allocated_objects());
|
56
|
-
#endif
|
57
|
-
}
|
58
|
-
#endif
|
@@ -1,152 +0,0 @@
|
|
1
|
-
/* :nodoc:
|
2
|
-
* Copyright (C) 2008 Shugo Maeda <shugo@ruby-lang.org>
|
3
|
-
* Charlie Savage <cfis@savagexi.com>
|
4
|
-
* All rights reserved.
|
5
|
-
*
|
6
|
-
* Redistribution and use in source and binary forms, with or without
|
7
|
-
* modification, are permitted provided that the following conditions
|
8
|
-
* are met:
|
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
|
25
|
-
* SUCH DAMAGE. */
|
26
|
-
|
27
|
-
#include <ruby.h>
|
28
|
-
|
29
|
-
#if defined(_WIN32) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__ppc__)))
|
30
|
-
#define MEASURE_CPU_TIME 2
|
31
|
-
|
32
|
-
static unsigned LONG_LONG cpu_frequency;
|
33
|
-
|
34
|
-
#if defined(__GNUC__)
|
35
|
-
|
36
|
-
#include <stdint.h>
|
37
|
-
|
38
|
-
static prof_measure_t
|
39
|
-
measure_cpu_time()
|
40
|
-
{
|
41
|
-
#if defined(__i386__) || defined(__x86_64__)
|
42
|
-
uint32_t a, d;
|
43
|
-
__asm__ volatile("rdtsc" : "=a" (a), "=d" (d));
|
44
|
-
return ((uint64_t)d << 32) + a;
|
45
|
-
#elif defined(__powerpc__) || defined(__ppc__)
|
46
|
-
unsigned long long x, y;
|
47
|
-
|
48
|
-
__asm__ __volatile__ ("\n\
|
49
|
-
1: mftbu %1\n\
|
50
|
-
mftb %L0\n\
|
51
|
-
mftbu %0\n\
|
52
|
-
cmpw %0,%1\n\
|
53
|
-
bne- 1b"
|
54
|
-
: "=r" (x), "=r" (y));
|
55
|
-
return x;
|
56
|
-
#endif
|
57
|
-
}
|
58
|
-
|
59
|
-
#elif defined(_WIN32)
|
60
|
-
|
61
|
-
static prof_measure_t
|
62
|
-
measure_cpu_time()
|
63
|
-
{
|
64
|
-
prof_measure_t cycles = 0;
|
65
|
-
|
66
|
-
__asm
|
67
|
-
{
|
68
|
-
rdtsc
|
69
|
-
mov DWORD PTR cycles, eax
|
70
|
-
mov DWORD PTR [cycles + 4], edx
|
71
|
-
}
|
72
|
-
return cycles;
|
73
|
-
}
|
74
|
-
|
75
|
-
#endif
|
76
|
-
|
77
|
-
|
78
|
-
/* The _WIN32 check is needed for msys (and maybe cygwin?) */
|
79
|
-
#if defined(__GNUC__) && !defined(_WIN32)
|
80
|
-
|
81
|
-
unsigned long long get_cpu_frequency()
|
82
|
-
{
|
83
|
-
unsigned long long x, y;
|
84
|
-
|
85
|
-
struct timespec ts;
|
86
|
-
ts.tv_sec = 0;
|
87
|
-
ts.tv_nsec = 500000000;
|
88
|
-
x = measure_cpu_time();
|
89
|
-
nanosleep(&ts, NULL);
|
90
|
-
y = measure_cpu_time();
|
91
|
-
return (y - x) * 2;
|
92
|
-
}
|
93
|
-
|
94
|
-
#elif defined(_WIN32)
|
95
|
-
|
96
|
-
unsigned LONG_LONG get_cpu_frequency()
|
97
|
-
{
|
98
|
-
unsigned LONG_LONG x, y;
|
99
|
-
unsigned LONG_LONG frequency;
|
100
|
-
x = measure_cpu_time();
|
101
|
-
|
102
|
-
/* Use the windows sleep function, not Ruby's */
|
103
|
-
Sleep(500);
|
104
|
-
y = measure_cpu_time();
|
105
|
-
frequency = 2*(y-x);
|
106
|
-
return frequency;
|
107
|
-
}
|
108
|
-
#endif
|
109
|
-
|
110
|
-
static double
|
111
|
-
convert_cpu_time(prof_measure_t c)
|
112
|
-
{
|
113
|
-
return (double) c / cpu_frequency;
|
114
|
-
}
|
115
|
-
|
116
|
-
/* Document-method: prof_measure_cpu_time
|
117
|
-
call-seq:
|
118
|
-
measure_cpu_time -> float
|
119
|
-
|
120
|
-
Returns the cpu time.*/
|
121
|
-
static VALUE
|
122
|
-
prof_measure_cpu_time(VALUE self)
|
123
|
-
{
|
124
|
-
return rb_float_new(convert_cpu_time(measure_cpu_time()));
|
125
|
-
}
|
126
|
-
|
127
|
-
/* Document-method: prof_get_cpu_frequency
|
128
|
-
call-seq:
|
129
|
-
cpu_frequency -> int
|
130
|
-
|
131
|
-
Returns the cpu's frequency. This value is needed when
|
132
|
-
RubyProf::measure_mode is set to CPU_TIME. */
|
133
|
-
static VALUE
|
134
|
-
prof_get_cpu_frequency(VALUE self)
|
135
|
-
{
|
136
|
-
return ULL2NUM(cpu_frequency);
|
137
|
-
}
|
138
|
-
|
139
|
-
/* Document-method: prof_set_cpu_frequency
|
140
|
-
call-seq:
|
141
|
-
cpu_frequency=value -> void
|
142
|
-
|
143
|
-
Sets the cpu's frequency. This value is needed when
|
144
|
-
RubyProf::measure_mode is set to CPU_TIME. */
|
145
|
-
static VALUE
|
146
|
-
prof_set_cpu_frequency(VALUE self, VALUE val)
|
147
|
-
{
|
148
|
-
cpu_frequency = NUM2LL(val);
|
149
|
-
return val;
|
150
|
-
}
|
151
|
-
|
152
|
-
#endif
|