ruby-prof-danielhoey 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +221 -0
- data/LICENSE +23 -0
- data/README +432 -0
- data/Rakefile +158 -0
- data/bin/ruby-prof +224 -0
- data/examples/flat.txt +55 -0
- data/examples/graph.html +823 -0
- data/examples/graph.txt +170 -0
- data/ext/ruby_prof/call_tree.c +392 -0
- data/ext/ruby_prof/call_tree.h +32 -0
- data/ext/ruby_prof/extconf.rb +40 -0
- data/ext/ruby_prof/list.c +66 -0
- data/ext/ruby_prof/list.h +10 -0
- data/ext/ruby_prof/measure_allocations.h +58 -0
- data/ext/ruby_prof/measure_cpu_time.h +152 -0
- data/ext/ruby_prof/measure_gc_runs.h +76 -0
- data/ext/ruby_prof/measure_gc_time.h +57 -0
- data/ext/ruby_prof/measure_memory.h +101 -0
- data/ext/ruby_prof/measure_process_time.h +52 -0
- data/ext/ruby_prof/measure_wall_time.h +53 -0
- data/ext/ruby_prof/measurement.h +13 -0
- data/ext/ruby_prof/mingw/Rakefile +23 -0
- data/ext/ruby_prof/mingw/build.rake +38 -0
- data/ext/ruby_prof/ruby_prof.c +1943 -0
- data/ext/ruby_prof/ruby_prof.h +183 -0
- data/ext/ruby_prof/version.h +4 -0
- data/lib/ruby-prof.rb +59 -0
- data/lib/ruby-prof/abstract_printer.rb +41 -0
- data/lib/ruby-prof/aggregate_call_info.rb +62 -0
- data/lib/ruby-prof/call_info.rb +47 -0
- data/lib/ruby-prof/call_tree/abstract_printer.rb +24 -0
- data/lib/ruby-prof/call_tree/html_printer.rb +89 -0
- data/lib/ruby-prof/call_tree/html_printer_output.html.erb +99 -0
- data/lib/ruby-prof/call_tree/text_printer.rb +28 -0
- data/lib/ruby-prof/call_tree_printer.rb +84 -0
- data/lib/ruby-prof/flat_printer.rb +78 -0
- data/lib/ruby-prof/flat_printer_with_line_numbers.rb +72 -0
- data/lib/ruby-prof/graph_html_printer.rb +256 -0
- data/lib/ruby-prof/graph_printer.rb +157 -0
- data/lib/ruby-prof/method_info.rb +111 -0
- data/lib/ruby-prof/symbol_to_proc.rb +8 -0
- data/lib/ruby-prof/task.rb +146 -0
- data/lib/ruby-prof/test.rb +148 -0
- data/lib/unprof.rb +8 -0
- data/rails/environment/profile.rb +24 -0
- data/rails/example/example_test.rb +9 -0
- data/rails/profile_test_helper.rb +21 -0
- data/test/aggregate_test.rb +121 -0
- data/test/basic_test.rb +290 -0
- data/test/current_failures_windows +8 -0
- data/test/do_nothing.rb +0 -0
- data/test/duplicate_names_test.rb +32 -0
- data/test/enumerable_test.rb +16 -0
- data/test/exceptions_test.rb +15 -0
- data/test/exclude_threads_test.rb +54 -0
- data/test/exec_test.rb +14 -0
- data/test/line_number_test.rb +73 -0
- data/test/measurement_test.rb +121 -0
- data/test/module_test.rb +54 -0
- data/test/no_method_class_test.rb +14 -0
- data/test/prime.rb +58 -0
- data/test/prime_test.rb +13 -0
- data/test/printers_test.rb +130 -0
- data/test/recursive_test.rb +275 -0
- data/test/ruby-prof-bin +20 -0
- data/test/singleton_test.rb +37 -0
- data/test/stack_test.rb +138 -0
- data/test/start_stop_test.rb +95 -0
- data/test/test_suite.rb +23 -0
- data/test/thread_test.rb +173 -0
- data/test/unique_call_path_test.rb +225 -0
- metadata +163 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef CALL_TREE
|
2
|
+
#define CALL_TREE
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
#include <st.h>
|
6
|
+
#include "measurement.h"
|
7
|
+
|
8
|
+
void init_call_tree();
|
9
|
+
VALUE call_tree_create_root();
|
10
|
+
VALUE call_tree_create_thread(VALUE parent, char* thread_id, char* file, prof_measure_t time);
|
11
|
+
|
12
|
+
VALUE call_tree_initialize(VALUE self, VALUE parent, VALUE klass_text, VALUE method, char* file);
|
13
|
+
VALUE call_tree_initialize_copy(VALUE copy, VALUE original);
|
14
|
+
VALUE call_tree_children(VALUE self);
|
15
|
+
VALUE call_tree_fetch(VALUE self, VALUE index);
|
16
|
+
VALUE call_tree_add(VALUE self, ID klass, ID mid, char* file);
|
17
|
+
VALUE call_tree_size(VALUE self);
|
18
|
+
VALUE call_tree_find_child(VALUE self, ID klass, ID mid, char* file);
|
19
|
+
VALUE call_tree_method_start(VALUE self, VALUE klass_text, ID mid, char* file, prof_measure_t time);
|
20
|
+
VALUE call_tree_method_stop(VALUE self, prof_measure_t time);
|
21
|
+
void call_tree_method_pause(VALUE self, prof_measure_t time);
|
22
|
+
void call_tree_method_resume(VALUE self, prof_measure_t time);
|
23
|
+
VALUE call_tree_to_s(VALUE self);
|
24
|
+
|
25
|
+
VALUE call_tree_parent(VALUE self);
|
26
|
+
VALUE call_tree_method(VALUE self);
|
27
|
+
VALUE call_tree_klass(VALUE self);
|
28
|
+
VALUE call_tree_time(VALUE self);
|
29
|
+
VALUE call_tree_file(VALUE self);
|
30
|
+
VALUE call_tree_call_count(VALUE self);
|
31
|
+
|
32
|
+
#endif
|
@@ -0,0 +1,40 @@
|
|
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
|
+
|
20
|
+
# Stefan Kaes / Alexander Dymo GC patch
|
21
|
+
have_func("rb_os_allocated_objects")
|
22
|
+
have_func("rb_gc_allocated_size")
|
23
|
+
have_func("rb_gc_collections")
|
24
|
+
have_func("rb_gc_time")
|
25
|
+
|
26
|
+
# Lloyd Hilaiel's heap info patch
|
27
|
+
have_func("rb_heap_total_mem")
|
28
|
+
have_func("rb_gc_heap_info")
|
29
|
+
|
30
|
+
# Ruby 1.9 unexposed methods
|
31
|
+
have_func("rb_gc_malloc_allocations")
|
32
|
+
have_func("rb_gc_malloc_allocated_size")
|
33
|
+
|
34
|
+
def add_define(name)
|
35
|
+
$defs.push("-D#{name}")
|
36
|
+
end
|
37
|
+
|
38
|
+
add_define 'DEBUG' if $DEBUG
|
39
|
+
|
40
|
+
create_makefile("ruby_prof")
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#ifdef HAVE_MALLOC_H
|
2
|
+
#include <malloc.h>
|
3
|
+
#endif
|
4
|
+
#include <assert.h>
|
5
|
+
#include <ruby.h>
|
6
|
+
#include "list.h"
|
7
|
+
|
8
|
+
typedef struct list_t{
|
9
|
+
int allocated_size;
|
10
|
+
int assigned_size;
|
11
|
+
list_data_t* data;
|
12
|
+
} list_t;
|
13
|
+
|
14
|
+
|
15
|
+
list new_list(int size)
|
16
|
+
{
|
17
|
+
list new_list = (list) ALLOC(list_t);
|
18
|
+
list_data_t* data = (list_data_t*) ALLOC_N(list_data_t, size);
|
19
|
+
|
20
|
+
new_list->allocated_size = size;
|
21
|
+
new_list->assigned_size = 0;
|
22
|
+
new_list->data = data;
|
23
|
+
|
24
|
+
return new_list;
|
25
|
+
}
|
26
|
+
|
27
|
+
void delete_list(list l)
|
28
|
+
{
|
29
|
+
xfree(l->data);
|
30
|
+
}
|
31
|
+
|
32
|
+
void list_add(list l, list_data_t item)
|
33
|
+
{
|
34
|
+
if (l->assigned_size >= l->allocated_size)
|
35
|
+
{
|
36
|
+
int new_allocated_size = l->allocated_size*2;
|
37
|
+
list_data_t* new_data = (list_data_t*) ALLOC_N(list_data_t, new_allocated_size);
|
38
|
+
int i;
|
39
|
+
for (i=0; i<l->allocated_size; i++)
|
40
|
+
{
|
41
|
+
new_data[i] = l->data[i];
|
42
|
+
}
|
43
|
+
xfree(l->data);
|
44
|
+
l->data = new_data;
|
45
|
+
l->allocated_size = new_allocated_size;
|
46
|
+
}
|
47
|
+
|
48
|
+
l->data[l->assigned_size] = item;
|
49
|
+
l->assigned_size++;
|
50
|
+
}
|
51
|
+
|
52
|
+
list_data_t list_get(list l, int index)
|
53
|
+
{
|
54
|
+
assert(index < l->allocated_size);
|
55
|
+
return l->data[index];
|
56
|
+
}
|
57
|
+
|
58
|
+
int list_size(list l)
|
59
|
+
{
|
60
|
+
return l->assigned_size;
|
61
|
+
}
|
62
|
+
|
63
|
+
list_data_t* list_data(list l)
|
64
|
+
{
|
65
|
+
return l->data;
|
66
|
+
}
|
@@ -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
|
@@ -0,0 +1,57 @@
|
|
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_TIME)
|
28
|
+
#define MEASURE_GC_TIME 6
|
29
|
+
|
30
|
+
static prof_measure_t
|
31
|
+
measure_gc_time()
|
32
|
+
{
|
33
|
+
#if HAVE_LONG_LONG
|
34
|
+
return NUM2LL(rb_gc_time());
|
35
|
+
#else
|
36
|
+
return NUM2LONG(rb_gc_time());
|
37
|
+
#endif
|
38
|
+
}
|
39
|
+
|
40
|
+
static double
|
41
|
+
convert_gc_time(prof_measure_t c)
|
42
|
+
{
|
43
|
+
return (double) c / 1000000;
|
44
|
+
}
|
45
|
+
|
46
|
+
/* Document-method: prof_measure_gc_time
|
47
|
+
call-seq:
|
48
|
+
gc_time -> Integer
|
49
|
+
|
50
|
+
Returns the time spent doing garbage collections in microseconds.*/
|
51
|
+
static VALUE
|
52
|
+
prof_measure_gc_time(VALUE self)
|
53
|
+
{
|
54
|
+
return rb_gc_time();
|
55
|
+
}
|
56
|
+
|
57
|
+
#endif
|