ruby-prof 0.6.0-x86-mswin32-60
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/CHANGES +116 -0
- data/LICENSE +23 -0
- data/README +307 -0
- data/Rakefile +141 -0
- data/bin/ruby-prof +192 -0
- data/examples/flat.txt +55 -0
- data/examples/graph.html +823 -0
- data/examples/graph.txt +170 -0
- data/ext/extconf.rb +21 -0
- data/ext/extconf.rb.rej +13 -0
- data/ext/measure_allocations.h +43 -0
- data/ext/measure_cpu_time.h +138 -0
- data/ext/measure_memory.h +42 -0
- data/ext/measure_process_time.h +41 -0
- data/ext/measure_wall_time.h +42 -0
- data/ext/ruby_prof.c +1628 -0
- data/lib/ruby-prof.rb +43 -0
- data/lib/ruby-prof/abstract_printer.rb +42 -0
- data/lib/ruby-prof/call_tree_printer.rb +76 -0
- data/lib/ruby-prof/call_tree_printer.rb.rej +27 -0
- data/lib/ruby-prof/flat_printer.rb +79 -0
- data/lib/ruby-prof/graph_html_printer.rb +255 -0
- data/lib/ruby-prof/graph_printer.rb +163 -0
- data/lib/ruby-prof/profile_test_case.rb +80 -0
- data/lib/ruby-prof/task.rb +147 -0
- data/lib/ruby_prof.so +0 -0
- data/lib/unprof.rb +8 -0
- data/rails_plugin/ruby-prof/init.rb +8 -0
- data/rails_plugin/ruby-prof/lib/profiling.rb +57 -0
- data/test/basic_test.rb +190 -0
- data/test/duplicate_names_test.rb +33 -0
- data/test/line_number_test.rb +69 -0
- data/test/measure_mode_test.rb +79 -0
- data/test/module_test.rb +57 -0
- data/test/no_method_class_test.rb +14 -0
- data/test/prime.rb +60 -0
- data/test/prime1.rb +17 -0
- data/test/prime2.rb +26 -0
- data/test/prime3.rb +17 -0
- data/test/prime_test.rb +24 -0
- data/test/printers_test.rb +74 -0
- data/test/profile_unit_test.rb +24 -0
- data/test/recursive_test.rb +144 -0
- data/test/singleton_test.rb +38 -0
- data/test/start_test.rb +24 -0
- data/test/test_helper.rb +55 -0
- data/test/test_suite.rb +19 -0
- data/test/thread_test.rb +135 -0
- data/test/timing_test.rb +133 -0
- metadata +116 -0
data/examples/graph.txt
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
= Graph Profiles
|
2
|
+
|
3
|
+
Graph profiles show how long each method runs, which methods call it
|
4
|
+
and which methods it calls.
|
5
|
+
|
6
|
+
As an example, here is the output from running printers_test.rb:
|
7
|
+
|
8
|
+
|
9
|
+
Thread ID: 21277412
|
10
|
+
%total %self total self children calls Name
|
11
|
+
--------------------------------------------------------------------------------
|
12
|
+
100.00% 0.00% 8.77 0.00 8.77 1 #toplevel
|
13
|
+
8.77 0.00 8.77 1/1 Object#run_primes
|
14
|
+
--------------------------------------------------------------------------------
|
15
|
+
8.77 0.00 8.77 1/1 #toplevel
|
16
|
+
100.00% 0.00% 8.77 0.00 8.77 1 Object#run_primes
|
17
|
+
0.02 0.00 0.02 1/1 Object#make_random_array
|
18
|
+
2.09 0.00 2.09 1/1 Object#find_largest
|
19
|
+
6.66 0.00 6.66 1/1 Object#find_primes
|
20
|
+
--------------------------------------------------------------------------------
|
21
|
+
6.63 4.06 2.56 500/501 Object#is_prime
|
22
|
+
2.09 0.00 2.09 1/501 Object#find_largest
|
23
|
+
99.48% 46.34% 8.72 4.06 4.66 501 Integer#upto
|
24
|
+
0.00 0.00 0.00 61/61 Array#[]
|
25
|
+
0.00 0.00 0.00 61/61 Fixnum#>
|
26
|
+
2.09 2.09 0.00 61/61 Kernel.sleep
|
27
|
+
1.24 1.24 0.00 250862/250862 Fixnum#==
|
28
|
+
1.33 1.33 0.00 250862/250862 Fixnum#%
|
29
|
+
--------------------------------------------------------------------------------
|
30
|
+
6.66 0.01 6.64 1/1 Object#find_primes
|
31
|
+
75.93% 0.17% 6.66 0.01 6.64 1 Array#select
|
32
|
+
6.64 0.01 6.63 500/500 Object#is_prime
|
33
|
+
--------------------------------------------------------------------------------
|
34
|
+
6.66 0.00 6.66 1/1 Object#run_primes
|
35
|
+
75.93% 0.00% 6.66 0.00 6.66 1 Object#find_primes
|
36
|
+
6.66 0.01 6.64 1/1 Array#select
|
37
|
+
--------------------------------------------------------------------------------
|
38
|
+
6.64 0.01 6.63 500/500 Array#select
|
39
|
+
75.76% 0.17% 6.64 0.01 6.63 500 Object#is_prime
|
40
|
+
0.00 0.00 0.00 500/501 Fixnum#-
|
41
|
+
6.63 4.06 2.56 500/501 Integer#upto
|
42
|
+
--------------------------------------------------------------------------------
|
43
|
+
2.09 0.00 2.09 1/1 Object#run_primes
|
44
|
+
23.89% 0.00% 2.09 0.00 2.09 1 Object#find_largest
|
45
|
+
0.00 0.00 0.00 1/501 Fixnum#-
|
46
|
+
2.09 0.00 2.09 1/501 Integer#upto
|
47
|
+
0.00 0.00 0.00 1/1 Array#first
|
48
|
+
0.00 0.00 0.00 1/1 Array#length
|
49
|
+
--------------------------------------------------------------------------------
|
50
|
+
2.09 2.09 0.00 61/61 Integer#upto
|
51
|
+
23.89% 23.89% 2.09 2.09 0.00 61 Kernel.sleep
|
52
|
+
--------------------------------------------------------------------------------
|
53
|
+
1.33 1.33 0.00 250862/250862 Integer#upto
|
54
|
+
15.12% 15.12% 1.33 1.33 0.00 250862 Fixnum#%
|
55
|
+
--------------------------------------------------------------------------------
|
56
|
+
1.24 1.24 0.00 250862/250862 Integer#upto
|
57
|
+
14.13% 14.13% 1.24 1.24 0.00 250862 Fixnum#==
|
58
|
+
--------------------------------------------------------------------------------
|
59
|
+
0.02 0.00 0.02 1/1 Object#run_primes
|
60
|
+
0.18% 0.00% 0.02 0.00 0.02 1 Object#make_random_array
|
61
|
+
0.02 0.02 0.00 1/1 Array#each_index
|
62
|
+
0.00 0.00 0.00 1/1 Class#new
|
63
|
+
--------------------------------------------------------------------------------
|
64
|
+
0.02 0.02 0.00 1/1 Object#make_random_array
|
65
|
+
0.18% 0.18% 0.02 0.02 0.00 1 Array#each_index
|
66
|
+
0.00 0.00 0.00 500/500 Kernel.rand
|
67
|
+
0.00 0.00 0.00 500/500 Array#[]=
|
68
|
+
--------------------------------------------------------------------------------
|
69
|
+
0.00 0.00 0.00 500/501 Object#is_prime
|
70
|
+
0.00 0.00 0.00 1/501 Object#find_largest
|
71
|
+
0.00% 0.00% 0.00 0.00 0.00 501 Fixnum#-
|
72
|
+
--------------------------------------------------------------------------------
|
73
|
+
0.00 0.00 0.00 1/1 Kernel.rand
|
74
|
+
0.00% 0.00% 0.00 0.00 0.00 1 Integer#to_int
|
75
|
+
--------------------------------------------------------------------------------
|
76
|
+
0.00 0.00 0.00 1/1 Object#find_largest
|
77
|
+
0.00% 0.00% 0.00 0.00 0.00 1 Array#first
|
78
|
+
--------------------------------------------------------------------------------
|
79
|
+
0.00 0.00 0.00 1/1 Class#new
|
80
|
+
0.00% 0.00% 0.00 0.00 0.00 1 Array#initialize
|
81
|
+
--------------------------------------------------------------------------------
|
82
|
+
0.00 0.00 0.00 1/1 Object#find_largest
|
83
|
+
0.00% 0.00% 0.00 0.00 0.00 1 Array#length
|
84
|
+
--------------------------------------------------------------------------------
|
85
|
+
0.00 0.00 0.00 1/1 Object#make_random_array
|
86
|
+
0.00% 0.00% 0.00 0.00 0.00 1 Class#new
|
87
|
+
0.00 0.00 0.00 1/1 Array#initialize
|
88
|
+
--------------------------------------------------------------------------------
|
89
|
+
0.00 0.00 0.00 61/61 Integer#upto
|
90
|
+
0.00% 0.00% 0.00 0.00 0.00 61 Fixnum#>
|
91
|
+
--------------------------------------------------------------------------------
|
92
|
+
0.00 0.00 0.00 61/61 Integer#upto
|
93
|
+
0.00% 0.00% 0.00 0.00 0.00 61 Array#[]
|
94
|
+
--------------------------------------------------------------------------------
|
95
|
+
0.00 0.00 0.00 500/500 Array#each_index
|
96
|
+
0.00% 0.00% 0.00 0.00 0.00 500 Array#[]=
|
97
|
+
--------------------------------------------------------------------------------
|
98
|
+
0.00 0.00 0.00 500/500 Array#each_index
|
99
|
+
0.00% 0.00% 0.00 0.00 0.00 500 Kernel.rand
|
100
|
+
0.00 0.00 0.00 1/1 Integer#to_int
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
== Overview
|
105
|
+
Dashed lines divide the report into entries, with one entry
|
106
|
+
per method. Entries are sorted by total time which is the
|
107
|
+
time spent in the method plus its children.
|
108
|
+
|
109
|
+
Each entry has a primary line demarked by values in the
|
110
|
+
%total and %self columns. The primary line represents
|
111
|
+
the method being profiled. Lines above it are the methods
|
112
|
+
that called this method (parents) while the lines below it
|
113
|
+
are the methods it called (children).
|
114
|
+
|
115
|
+
All values are in seconds. For the primary line, the columns represent:
|
116
|
+
|
117
|
+
%total - The percentage of time spent in this method and its children
|
118
|
+
%self - The percentage of time spent in this method
|
119
|
+
total - The time spent in this method and its children.
|
120
|
+
self - The time spent in this method.
|
121
|
+
children - The time spent in this method's children.
|
122
|
+
calls - The number of times this method was called.
|
123
|
+
name - The name of the method.
|
124
|
+
|
125
|
+
The interpretation of method names is:
|
126
|
+
* #toplevel - The root method that calls all other methods
|
127
|
+
* MyObject#test - An instance method "test" of the class "MyObject"
|
128
|
+
* <Object:MyObject>#test - The <> characters indicate a singleton method on a singleton class.
|
129
|
+
|
130
|
+
For example, we see that 99.48% of the time was spent in Integer#upto and its children.
|
131
|
+
Of that time, 4.06 seconds was spent in Integer#upto itself and 4.66 in its children.
|
132
|
+
Overall, Integer#upto was called 501 times.
|
133
|
+
|
134
|
+
== Parents
|
135
|
+
In each entry, the lines above the primary line are the methods that
|
136
|
+
called the current method. If the current method is a root method then
|
137
|
+
no parents are shown.
|
138
|
+
|
139
|
+
|
140
|
+
For parent lines, the columns represent:
|
141
|
+
|
142
|
+
total - The time spent in the current method and it children on behalf of the parent method.
|
143
|
+
self - The time spent in this method on behalf of the parent method.
|
144
|
+
children - The time spent in this method's children on behalf of the parent.
|
145
|
+
calls - The number of times the parent method called this child
|
146
|
+
|
147
|
+
Looking at Integer#upto again, we see that it was called 500 times from Object#is_prime
|
148
|
+
and 1 time from find_largest. Of the 8.72 total seconds spent in Integer#upto, 6.63
|
149
|
+
were done for Object#is_prime and 2.09 for Object#find_largest.
|
150
|
+
|
151
|
+
|
152
|
+
== Children
|
153
|
+
In each entry, the lines below the primary line are the methods that
|
154
|
+
the current method called. If the current method is a leaf method then
|
155
|
+
no children are shown.
|
156
|
+
|
157
|
+
For children lines, the columns represent:
|
158
|
+
|
159
|
+
total - The time spent in the child, and its children, on behalf of the current method
|
160
|
+
self - The time spent in the child on behalf of the current method.
|
161
|
+
children - The time spent in the child's children (ie, granchildren) in behalf of the current method
|
162
|
+
calls - The number of times the child method was called by the current method.
|
163
|
+
|
164
|
+
Taking our example of Integer#upto, we see that it called five other methods - Array#[],
|
165
|
+
Fixnum#>, Kernel.sleep, Fixnum#= and Fixnum#%. Looking at Kernel.sleep, we see that
|
166
|
+
its spent 2.09 seconds working for Integer#upto and its children spent 0 time working for
|
167
|
+
Integer#upto. To see the overall time Kernel.sleep took we would have to look up its entry
|
168
|
+
in the graph table.
|
169
|
+
|
170
|
+
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
if RUBY_VERSION >= "1.9"
|
4
|
+
if RUBY_RELEASE_DATE < "2005-03-17"
|
5
|
+
STDERR.print("Ruby version is too old\n")
|
6
|
+
exit(1)
|
7
|
+
end
|
8
|
+
elsif RUBY_VERSION >= "1.8"
|
9
|
+
if RUBY_RELEASE_DATE < "2005-03-22"
|
10
|
+
STDERR.print("Ruby version is too old\n")
|
11
|
+
exit(1)
|
12
|
+
end
|
13
|
+
else
|
14
|
+
STDERR.print("Ruby version is too old\n")
|
15
|
+
exit(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
have_header("sys/times.h")
|
19
|
+
have_func("rb_os_allocated_objects")
|
20
|
+
have_func("rb_gc_allocated_size")
|
21
|
+
create_makefile("ruby_prof")
|
data/ext/extconf.rb.rej
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
***************
|
2
|
+
*** 16,20 ****
|
3
|
+
end
|
4
|
+
|
5
|
+
have_header("sys/times.h")
|
6
|
+
- create_makefile("ruby_prof")
|
7
|
+
- have_func("rb_os_allocated_objects")--- 16,21 ----
|
8
|
+
end
|
9
|
+
|
10
|
+
have_header("sys/times.h")
|
11
|
+
+ have_func("rb_os_allocated_objects")
|
12
|
+
+ have_func("rb_gc_allocated_size")
|
13
|
+
+ create_makefile("ruby_prof")
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/* :nodoc:
|
2
|
+
* Copyright (C) 2007 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
|
+
|
28
|
+
#if defined(HAVE_RB_OS_ALLOCATED_OBJECTS)
|
29
|
+
#define MEASURE_ALLOCATIONS 3
|
30
|
+
|
31
|
+
static prof_measure_t
|
32
|
+
measure_allocations()
|
33
|
+
{
|
34
|
+
return rb_os_allocated_objects();
|
35
|
+
}
|
36
|
+
|
37
|
+
static double
|
38
|
+
convert_allocations(prof_measure_t c)
|
39
|
+
{
|
40
|
+
return c;
|
41
|
+
}
|
42
|
+
|
43
|
+
#endif
|
@@ -0,0 +1,138 @@
|
|
1
|
+
/* :nodoc:
|
2
|
+
* Copyright (C) 2007 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
|
+
|
28
|
+
#if defined(_WIN32) || (defined(__GNUC__) && (defined(__i386__) || defined(__powerpc__) || defined(__ppc__)))
|
29
|
+
#define MEASURE_CPU_TIME 2
|
30
|
+
|
31
|
+
static unsigned long long cpu_frequency;
|
32
|
+
|
33
|
+
#if defined(__GNUC__)
|
34
|
+
|
35
|
+
static prof_measure_t
|
36
|
+
measure_cpu_time()
|
37
|
+
{
|
38
|
+
#if defined(__i386__)
|
39
|
+
unsigned long long x;
|
40
|
+
__asm__ __volatile__ ("rdtsc" : "=A" (x));
|
41
|
+
return x;
|
42
|
+
#elif defined(__powerpc__) || defined(__ppc__)
|
43
|
+
unsigned long long x, y;
|
44
|
+
|
45
|
+
__asm__ __volatile__ ("\n\
|
46
|
+
1: mftbu %1\n\
|
47
|
+
mftb %L0\n\
|
48
|
+
mftbu %0\n\
|
49
|
+
cmpw %0,%1\n\
|
50
|
+
bne- 1b"
|
51
|
+
: "=r" (x), "=r" (y));
|
52
|
+
return x;
|
53
|
+
#endif
|
54
|
+
}
|
55
|
+
|
56
|
+
#elif defined(_WIN32)
|
57
|
+
|
58
|
+
static prof_measure_t
|
59
|
+
measure_cpu_time()
|
60
|
+
{
|
61
|
+
prof_measure_t cycles = 0;
|
62
|
+
|
63
|
+
__asm
|
64
|
+
{
|
65
|
+
rdtsc
|
66
|
+
mov DWORD PTR cycles, eax
|
67
|
+
mov DWORD PTR [cycles + 4], edx
|
68
|
+
}
|
69
|
+
return cycles;
|
70
|
+
}
|
71
|
+
|
72
|
+
#endif
|
73
|
+
|
74
|
+
|
75
|
+
/* The _WIN32 check is needed for msys (and maybe cygwin?) */
|
76
|
+
#if defined(__GNUC__) && !defined(_WIN32)
|
77
|
+
|
78
|
+
unsigned long long get_cpu_frequency()
|
79
|
+
{
|
80
|
+
unsigned long long x, y;
|
81
|
+
|
82
|
+
struct timespec ts;
|
83
|
+
ts.tv_sec = 0;
|
84
|
+
ts.tv_nsec = 500000000;
|
85
|
+
x = measure_cpu_time();
|
86
|
+
nanosleep(&ts, NULL);
|
87
|
+
y = measure_cpu_time();
|
88
|
+
return (y - x) * 2;
|
89
|
+
}
|
90
|
+
|
91
|
+
#elif defined(_WIN32)
|
92
|
+
|
93
|
+
unsigned long long get_cpu_frequency()
|
94
|
+
{
|
95
|
+
unsigned long long x, y;
|
96
|
+
unsigned long long frequency;
|
97
|
+
x = measure_cpu_time();
|
98
|
+
|
99
|
+
/* Use the windows sleep function, not Ruby's */
|
100
|
+
Sleep(500);
|
101
|
+
y = measure_cpu_time();
|
102
|
+
frequency = 2*(y-x);
|
103
|
+
return frequency;
|
104
|
+
}
|
105
|
+
#endif
|
106
|
+
|
107
|
+
static double
|
108
|
+
convert_cpu_time(prof_measure_t c)
|
109
|
+
{
|
110
|
+
return (double) c / cpu_frequency;
|
111
|
+
}
|
112
|
+
|
113
|
+
/* Document-method: prof_get_cpu_frequency
|
114
|
+
call-seq:
|
115
|
+
cpu_frequency -> int
|
116
|
+
|
117
|
+
Returns the cpu's frequency. This value is needed when
|
118
|
+
RubyProf::measure_mode is set to CPU_TIME. */
|
119
|
+
static VALUE
|
120
|
+
prof_get_cpu_frequency(VALUE self)
|
121
|
+
{
|
122
|
+
return LONG2NUM(cpu_frequency);
|
123
|
+
}
|
124
|
+
|
125
|
+
/* Document-method: prof_set_cpu_frequency
|
126
|
+
call-seq:
|
127
|
+
cpu_frequency=value -> void
|
128
|
+
|
129
|
+
Sets the cpu's frequency. This value is needed when
|
130
|
+
RubyProf::measure_mode is set to CPU_TIME. */
|
131
|
+
static VALUE
|
132
|
+
prof_set_cpu_frequency(VALUE self, VALUE val)
|
133
|
+
{
|
134
|
+
cpu_frequency = NUM2LONG(val);
|
135
|
+
return val;
|
136
|
+
}
|
137
|
+
|
138
|
+
#endif
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/* :nodoc:
|
2
|
+
* Copyright (C) 2008 Alexander Dymo <adymo@pluron.com>
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions
|
7
|
+
* are met:
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
15
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
17
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
18
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
20
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
21
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
22
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
23
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
24
|
+
* SUCH DAMAGE. */
|
25
|
+
|
26
|
+
|
27
|
+
#if defined(HAVE_RB_GC_ALLOCATED_SIZE)
|
28
|
+
#define MEASURE_MEMORY 4
|
29
|
+
|
30
|
+
static prof_measure_t
|
31
|
+
measure_memory()
|
32
|
+
{
|
33
|
+
return rb_gc_allocated_size();
|
34
|
+
}
|
35
|
+
|
36
|
+
static double
|
37
|
+
convert_memory(prof_measure_t c)
|
38
|
+
{
|
39
|
+
return c / 1024;
|
40
|
+
}
|
41
|
+
|
42
|
+
#endif
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/* :nodoc:
|
2
|
+
* Copyright (C) 2007 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 <time.h>
|
28
|
+
|
29
|
+
#define MEASURE_PROCESS_TIME 0
|
30
|
+
|
31
|
+
static prof_measure_t
|
32
|
+
measure_process_time()
|
33
|
+
{
|
34
|
+
return clock();
|
35
|
+
}
|
36
|
+
|
37
|
+
static double
|
38
|
+
convert_process_time(prof_measure_t c)
|
39
|
+
{
|
40
|
+
return (double) c / CLOCKS_PER_SEC;
|
41
|
+
}
|