jeremy-ruby-prof 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGES +158 -0
  2. data/LICENSE +23 -0
  3. data/README +416 -0
  4. data/Rakefile +141 -0
  5. data/bin/ruby-prof +196 -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/extconf.rb +24 -0
  10. data/ext/measure_allocations.h +58 -0
  11. data/ext/measure_cpu_time.h +149 -0
  12. data/ext/measure_memory.h +104 -0
  13. data/ext/measure_process_time.h +52 -0
  14. data/ext/measure_wall_time.h +53 -0
  15. data/ext/ruby_prof.c +1680 -0
  16. data/lib/ruby-prof.rb +45 -0
  17. data/lib/ruby-prof/abstract_printer.rb +42 -0
  18. data/lib/ruby-prof/call_tree_printer.rb +76 -0
  19. data/lib/ruby-prof/flat_printer.rb +76 -0
  20. data/lib/ruby-prof/graph_html_printer.rb +255 -0
  21. data/lib/ruby-prof/graph_printer.rb +163 -0
  22. data/lib/ruby-prof/profile_test.rb +147 -0
  23. data/lib/ruby-prof/task.rb +147 -0
  24. data/lib/unprof.rb +8 -0
  25. data/test/basic_test.rb +190 -0
  26. data/test/duplicate_names_test.rb +33 -0
  27. data/test/exceptions_test.rb +19 -0
  28. data/test/line_number_test.rb +69 -0
  29. data/test/measure_mode_test.rb +91 -0
  30. data/test/measurement_test.rb +61 -0
  31. data/test/module_test.rb +57 -0
  32. data/test/no_method_class_test.rb +14 -0
  33. data/test/prime.rb +60 -0
  34. data/test/prime1.rb +17 -0
  35. data/test/prime2.rb +26 -0
  36. data/test/prime3.rb +17 -0
  37. data/test/prime_test.rb +24 -0
  38. data/test/printers_test.rb +74 -0
  39. data/test/profile_unit_test.rb +24 -0
  40. data/test/recursive_test.rb +144 -0
  41. data/test/singleton_test.rb +38 -0
  42. data/test/start_test.rb +24 -0
  43. data/test/test_helper.rb +55 -0
  44. data/test/test_suite.rb +20 -0
  45. data/test/thread_test.rb +135 -0
  46. data/test/timing_test.rb +133 -0
  47. metadata +112 -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,24 @@
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
+ have_func("rb_gc_malloc_allocations")
22
+ have_func("rb_gc_malloc_allocated_size")
23
+ have_func("rb_heap_total_mem")
24
+ create_makefile("ruby_prof")
@@ -0,0 +1,58 @@
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
44
+
45
+ /* Document-method: prof_measure_allocations
46
+ call-seq:
47
+ measure_allocations -> int
48
+
49
+ Returns the total number of object allocations since Ruby started.*/
50
+ static VALUE
51
+ prof_measure_allocations(VALUE self)
52
+ {
53
+ #if defined(HAVE_LONG_LONG)
54
+ return ULL2NUM(rb_os_allocated_objects());
55
+ #else
56
+ return ULONG2NUM(rb_os_allocated_objects());
57
+ #endif
58
+ }
@@ -0,0 +1,149 @@
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_measure_cpu_time
114
+ call-seq:
115
+ measure_cpu_time -> float
116
+
117
+ Returns the cpu time.*/
118
+ static VALUE
119
+ prof_measure_cpu_time(VALUE self)
120
+ {
121
+ return rb_float_new(convert_cpu_time(measure_cpu_time()));
122
+ }
123
+
124
+ /* Document-method: prof_get_cpu_frequency
125
+ call-seq:
126
+ cpu_frequency -> int
127
+
128
+ Returns the cpu's frequency. This value is needed when
129
+ RubyProf::measure_mode is set to CPU_TIME. */
130
+ static VALUE
131
+ prof_get_cpu_frequency(VALUE self)
132
+ {
133
+ return ULL2NUM(cpu_frequency);
134
+ }
135
+
136
+ /* Document-method: prof_set_cpu_frequency
137
+ call-seq:
138
+ cpu_frequency=value -> void
139
+
140
+ Sets the cpu's frequency. This value is needed when
141
+ RubyProf::measure_mode is set to CPU_TIME. */
142
+ static VALUE
143
+ prof_set_cpu_frequency(VALUE self, VALUE val)
144
+ {
145
+ cpu_frequency = NUM2ULL(val);
146
+ return val;
147
+ }
148
+
149
+ #endif
@@ -0,0 +1,104 @@
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
+ #define TOGGLE_GC_STATS 1
30
+
31
+ static prof_measure_t
32
+ measure_memory()
33
+ {
34
+ #if defined(HAVE_LONG_LONG)
35
+ return NUM2ULL(rb_gc_allocated_size());
36
+ #else
37
+ return NUM2ULONG(rb_gc_allocated_size());
38
+ #endif
39
+ }
40
+
41
+ static double
42
+ convert_memory(prof_measure_t c)
43
+ {
44
+ return (double) c / 1024;
45
+ }
46
+
47
+ /* Document-method: prof_measure_memory
48
+ call-seq:
49
+ measure_memory -> int
50
+
51
+ Returns total allocated memory in bytes.*/
52
+ static VALUE
53
+ prof_measure_memory(VALUE self)
54
+ {
55
+ return rb_gc_allocated_size();
56
+ }
57
+
58
+ #elif defined(HAVE_RB_GC_MALLOC_ALLOCATED_SIZE)
59
+ #define MEASURE_MEMORY 4
60
+
61
+ static prof_measure_t
62
+ measure_memory()
63
+ {
64
+ #if defined(HAVE_LONG_LONG)
65
+ return NUM2ULL(rb_gc_malloc_allocated_size());
66
+ #else
67
+ return NUM2ULONG(rb_gc_malloc_allocated_size());
68
+ #endif
69
+ }
70
+
71
+ static double
72
+ convert_memory(prof_measure_t c)
73
+ {
74
+ return (double) c / 1024;
75
+ }
76
+
77
+ static VALUE
78
+ prof_measure_memory(VALUE self)
79
+ {
80
+ return rb_gc_malloc_allocated_size();
81
+ }
82
+
83
+ #elif defined(HAVE_RB_HEAP_TOTAL_MEM)
84
+ #define MEASURE_MEMORY 4
85
+
86
+ static prof_measure_t
87
+ measure_memory()
88
+ {
89
+ return rb_heap_total_mem();
90
+ }
91
+
92
+ static double
93
+ convert_memory(prof_measure_t c)
94
+ {
95
+ return (double) c / 1024;
96
+ }
97
+
98
+ static VALUE
99
+ prof_measure_memory(VALUE self)
100
+ {
101
+ return ULONG2NUM(rb_heap_total_mem());
102
+ }
103
+
104
+ #endif