ruby-prof 0.8.1-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/CHANGES +221 -0
  2. data/LICENSE +23 -0
  3. data/README +432 -0
  4. data/Rakefile +159 -0
  5. data/bin/ruby-prof +224 -0
  6. data/examples/flat.txt +55 -0
  7. data/examples/graph.html +823 -0
  8. data/examples/graph.txt +170 -0
  9. data/ext/ruby_prof/measure_allocations.h +58 -0
  10. data/ext/ruby_prof/measure_cpu_time.h +152 -0
  11. data/ext/ruby_prof/measure_gc_runs.h +76 -0
  12. data/ext/ruby_prof/measure_gc_time.h +57 -0
  13. data/ext/ruby_prof/measure_memory.h +101 -0
  14. data/ext/ruby_prof/measure_process_time.h +52 -0
  15. data/ext/ruby_prof/measure_wall_time.h +53 -0
  16. data/ext/ruby_prof/mingw/Rakefile +23 -0
  17. data/ext/ruby_prof/mingw/build.rake +38 -0
  18. data/ext/ruby_prof/ruby_prof.c +1747 -0
  19. data/ext/ruby_prof/ruby_prof.h +188 -0
  20. data/ext/ruby_prof/version.h +4 -0
  21. data/lib/1.8/ruby_prof.so +0 -0
  22. data/lib/1.9/ruby_prof.so +0 -0
  23. data/lib/ruby-prof.rb +56 -0
  24. data/lib/ruby-prof/abstract_printer.rb +41 -0
  25. data/lib/ruby-prof/aggregate_call_info.rb +62 -0
  26. data/lib/ruby-prof/call_info.rb +47 -0
  27. data/lib/ruby-prof/call_tree_printer.rb +84 -0
  28. data/lib/ruby-prof/flat_printer.rb +78 -0
  29. data/lib/ruby-prof/flat_printer_with_line_numbers.rb +72 -0
  30. data/lib/ruby-prof/graph_html_printer.rb +256 -0
  31. data/lib/ruby-prof/graph_printer.rb +157 -0
  32. data/lib/ruby-prof/method_info.rb +111 -0
  33. data/lib/ruby-prof/symbol_to_proc.rb +8 -0
  34. data/lib/ruby-prof/task.rb +146 -0
  35. data/lib/ruby-prof/test.rb +148 -0
  36. data/lib/unprof.rb +8 -0
  37. data/rails/environment/profile.rb +24 -0
  38. data/rails/example/example_test.rb +9 -0
  39. data/rails/profile_test_helper.rb +21 -0
  40. data/test/aggregate_test.rb +121 -0
  41. data/test/basic_test.rb +290 -0
  42. data/test/current_failures_windows +8 -0
  43. data/test/do_nothing.rb +0 -0
  44. data/test/duplicate_names_test.rb +32 -0
  45. data/test/enumerable_test.rb +16 -0
  46. data/test/exceptions_test.rb +15 -0
  47. data/test/exclude_threads_test.rb +54 -0
  48. data/test/exec_test.rb +14 -0
  49. data/test/line_number_test.rb +73 -0
  50. data/test/measurement_test.rb +121 -0
  51. data/test/module_test.rb +54 -0
  52. data/test/no_method_class_test.rb +13 -0
  53. data/test/prime.rb +58 -0
  54. data/test/prime_test.rb +13 -0
  55. data/test/printers_test.rb +130 -0
  56. data/test/recursive_test.rb +275 -0
  57. data/test/ruby-prof-bin +20 -0
  58. data/test/singleton_test.rb +37 -0
  59. data/test/stack_test.rb +138 -0
  60. data/test/start_stop_test.rb +95 -0
  61. data/test/test_suite.rb +23 -0
  62. data/test/thread_test.rb +173 -0
  63. data/test/unique_call_path_test.rb +225 -0
  64. metadata +143 -0
@@ -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
+
@@ -0,0 +1,58 @@
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
@@ -0,0 +1,152 @@
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
@@ -0,0 +1,76 @@
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
+ #if defined(HAVE_RB_GC_COLLECTIONS)
28
+ #define MEASURE_GC_RUNS 5
29
+
30
+ static prof_measure_t
31
+ measure_gc_runs()
32
+ {
33
+ return NUM2INT(rb_gc_collections());
34
+ }
35
+
36
+ static double
37
+ convert_gc_runs(prof_measure_t c)
38
+ {
39
+ return c;
40
+ }
41
+
42
+ /* Document-method: prof_measure_gc_runs
43
+ call-seq:
44
+ gc_runs -> Integer
45
+
46
+ Returns the total number of garbage collections.*/
47
+ static VALUE
48
+ prof_measure_gc_runs(VALUE self)
49
+ {
50
+ return rb_gc_collections();
51
+ }
52
+
53
+ #elif defined(HAVE_RB_GC_HEAP_INFO)
54
+ #define MEASURE_GC_RUNS 5
55
+
56
+ static prof_measure_t
57
+ measure_gc_runs()
58
+ {
59
+ VALUE h = rb_gc_heap_info();
60
+ return NUM2UINT(rb_hash_aref(h, rb_str_new2("num_gc_passes")));
61
+ }
62
+
63
+ static double
64
+ convert_gc_runs(prof_measure_t c)
65
+ {
66
+ return c;
67
+ }
68
+
69
+ static VALUE
70
+ prof_measure_gc_runs(VALUE self)
71
+ {
72
+ VALUE h = rb_gc_heap_info();
73
+ return rb_hash_aref(h, rb_str_new2("num_gc_passes"));
74
+ }
75
+
76
+ #endif