ruby-prof 1.6.3 → 1.7.2
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.
- checksums.yaml +4 -4
- data/CHANGES +19 -0
- data/ext/ruby_prof/extconf.rb +23 -22
- data/ext/ruby_prof/rp_allocation.c +342 -342
- data/ext/ruby_prof/rp_call_tree.c +1 -1
- data/ext/ruby_prof/rp_call_tree.h +1 -1
- data/ext/ruby_prof/rp_call_trees.c +296 -296
- data/ext/ruby_prof/rp_call_trees.h +28 -28
- data/ext/ruby_prof/rp_measure_allocations.c +47 -47
- data/ext/ruby_prof/rp_measure_memory.c +46 -46
- data/ext/ruby_prof/rp_measure_process_time.c +64 -66
- data/ext/ruby_prof/rp_measure_wall_time.c +52 -64
- data/ext/ruby_prof/rp_measurement.c +364 -364
- data/ext/ruby_prof/rp_method.c +551 -550
- data/ext/ruby_prof/rp_method.h +5 -2
- data/ext/ruby_prof/rp_profile.c +2 -2
- data/ext/ruby_prof/rp_profile.h +36 -36
- data/ext/ruby_prof/rp_stack.c +212 -212
- data/ext/ruby_prof/rp_thread.c +1 -1
- data/ext/ruby_prof/ruby_prof.c +50 -50
- data/ext/ruby_prof/ruby_prof.h +35 -34
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +5 -7
- data/lib/ruby-prof/compatibility.rb +113 -113
- data/lib/ruby-prof/exclude_common_methods.rb +204 -198
- data/lib/ruby-prof/method_info.rb +87 -85
- data/lib/ruby-prof/printers/abstract_printer.rb +156 -138
- data/lib/ruby-prof/version.rb +3 -3
- data/ruby-prof.gemspec +66 -64
- data/test/dynamic_method_test.rb +9 -21
- data/test/enumerable_test.rb +23 -21
- data/test/exclude_methods_test.rb +363 -146
- data/test/fiber_test.rb +195 -195
- data/test/gc_test.rb +104 -102
- data/test/line_number_test.rb +426 -134
- data/test/measure_allocations_test.rb +1172 -660
- data/test/measure_memory_test.rb +1193 -1024
- data/test/measure_process_time_test.rb +3330 -1610
- data/test/measure_wall_time_test.rb +634 -420
- data/test/merge_test.rb +146 -146
- data/test/method_info_test.rb +100 -95
- data/test/printers_test.rb +178 -135
- data/test/recursive_test.rb +796 -425
- data/test/start_stop_test.rb +4 -4
- data/test/test_helper.rb +20 -20
- data/test/thread_test.rb +229 -235
- data/test/unique_call_path_test.rb +9 -22
- data/test/yarv_test.rb +1 -5
- metadata +33 -8
data/ext/ruby_prof/rp_method.h
CHANGED
|
@@ -18,11 +18,14 @@ enum {
|
|
|
18
18
|
kOtherSingleton = 0x10 // Singleton of unknown object
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
// Don't want to include ruby_prof.h to avoid a circular reference
|
|
22
|
+
struct prof_profile_t;
|
|
23
|
+
|
|
21
24
|
// Profiling information for each method.
|
|
22
25
|
// Excluded methods have no call_trees, source_klass, or source_file.
|
|
23
26
|
typedef struct prof_method_t
|
|
24
27
|
{
|
|
25
|
-
|
|
28
|
+
struct prof_profile_t* profile; // Profile this method is associated with - needed for mark phase
|
|
26
29
|
struct prof_call_trees_t* call_trees; // Call infos that call this method
|
|
27
30
|
st_table* allocations_table; // Tracks object allocations
|
|
28
31
|
|
|
@@ -51,7 +54,7 @@ prof_method_t* method_table_lookup(st_table* table, st_data_t key);
|
|
|
51
54
|
size_t method_table_insert(st_table* table, st_data_t key, prof_method_t* val);
|
|
52
55
|
void method_table_free(st_table* table);
|
|
53
56
|
void prof_method_table_merge(st_table* self, st_table* other);
|
|
54
|
-
prof_method_t* prof_method_create(
|
|
57
|
+
prof_method_t* prof_method_create(struct prof_profile_t* profile, VALUE klass, VALUE msym, VALUE source_file, int source_line);
|
|
55
58
|
prof_method_t* prof_get_method(VALUE self);
|
|
56
59
|
|
|
57
60
|
VALUE prof_method_wrap(prof_method_t* result);
|
data/ext/ruby_prof/rp_profile.c
CHANGED
|
@@ -105,7 +105,7 @@ static int excludes_method(st_data_t key, prof_profile_t* profile)
|
|
|
105
105
|
|
|
106
106
|
static prof_method_t* create_method(prof_profile_t* profile, st_data_t key, VALUE klass, VALUE msym, VALUE source_file, int source_line)
|
|
107
107
|
{
|
|
108
|
-
prof_method_t* result = prof_method_create(profile
|
|
108
|
+
prof_method_t* result = prof_method_create(profile, klass, msym, source_file, source_line);
|
|
109
109
|
method_table_insert(profile->last_thread_data->method_table, result->key, result);
|
|
110
110
|
|
|
111
111
|
return result;
|
|
@@ -863,7 +863,7 @@ static VALUE prof_exclude_method(VALUE self, VALUE klass, VALUE msym)
|
|
|
863
863
|
|
|
864
864
|
if (!method)
|
|
865
865
|
{
|
|
866
|
-
method = prof_method_create(
|
|
866
|
+
method = prof_method_create(profile, klass, msym, Qnil, 0);
|
|
867
867
|
method_table_insert(profile->exclude_methods_tbl, method->key, method);
|
|
868
868
|
}
|
|
869
869
|
|
data/ext/ruby_prof/rp_profile.h
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/* Copyright (C) 2005-2019 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
|
|
2
|
-
Please see the LICENSE file for copyright and distribution information */
|
|
3
|
-
|
|
4
|
-
#ifndef __RP_PROFILE_H__
|
|
5
|
-
#define __RP_PROFILE_H__
|
|
6
|
-
|
|
7
|
-
#include "ruby_prof.h"
|
|
8
|
-
#include "rp_measurement.h"
|
|
9
|
-
#include "rp_thread.h"
|
|
10
|
-
|
|
11
|
-
extern VALUE cProfile;
|
|
12
|
-
|
|
13
|
-
typedef struct prof_profile_t
|
|
14
|
-
{
|
|
15
|
-
VALUE object;
|
|
16
|
-
VALUE running;
|
|
17
|
-
VALUE paused;
|
|
18
|
-
|
|
19
|
-
prof_measurer_t* measurer;
|
|
20
|
-
|
|
21
|
-
VALUE tracepoints;
|
|
22
|
-
|
|
23
|
-
st_table* threads_tbl;
|
|
24
|
-
st_table* exclude_threads_tbl;
|
|
25
|
-
st_table* include_threads_tbl;
|
|
26
|
-
st_table* exclude_methods_tbl;
|
|
27
|
-
thread_data_t* last_thread_data;
|
|
28
|
-
double measurement_at_pause_resume;
|
|
29
|
-
bool allow_exceptions;
|
|
30
|
-
} prof_profile_t;
|
|
31
|
-
|
|
32
|
-
void rp_init_profile(void);
|
|
33
|
-
prof_profile_t* prof_get_profile(VALUE self);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
#endif //__RP_PROFILE_H__
|
|
1
|
+
/* Copyright (C) 2005-2019 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
|
|
2
|
+
Please see the LICENSE file for copyright and distribution information */
|
|
3
|
+
|
|
4
|
+
#ifndef __RP_PROFILE_H__
|
|
5
|
+
#define __RP_PROFILE_H__
|
|
6
|
+
|
|
7
|
+
#include "ruby_prof.h"
|
|
8
|
+
#include "rp_measurement.h"
|
|
9
|
+
#include "rp_thread.h"
|
|
10
|
+
|
|
11
|
+
extern VALUE cProfile;
|
|
12
|
+
|
|
13
|
+
typedef struct prof_profile_t
|
|
14
|
+
{
|
|
15
|
+
VALUE object;
|
|
16
|
+
VALUE running;
|
|
17
|
+
VALUE paused;
|
|
18
|
+
|
|
19
|
+
prof_measurer_t* measurer;
|
|
20
|
+
|
|
21
|
+
VALUE tracepoints;
|
|
22
|
+
|
|
23
|
+
st_table* threads_tbl;
|
|
24
|
+
st_table* exclude_threads_tbl;
|
|
25
|
+
st_table* include_threads_tbl;
|
|
26
|
+
st_table* exclude_methods_tbl;
|
|
27
|
+
thread_data_t* last_thread_data;
|
|
28
|
+
double measurement_at_pause_resume;
|
|
29
|
+
bool allow_exceptions;
|
|
30
|
+
} prof_profile_t;
|
|
31
|
+
|
|
32
|
+
void rp_init_profile(void);
|
|
33
|
+
prof_profile_t* prof_get_profile(VALUE self);
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
#endif //__RP_PROFILE_H__
|
data/ext/ruby_prof/rp_stack.c
CHANGED
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
/* Copyright (C) 2005-2019 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
|
|
2
|
-
Please see the LICENSE file for copyright and distribution information */
|
|
3
|
-
|
|
4
|
-
#include "rp_stack.h"
|
|
5
|
-
|
|
6
|
-
#define INITIAL_STACK_SIZE 16
|
|
7
|
-
|
|
8
|
-
// Creates a stack of prof_frame_t to keep track of timings for active methods.
|
|
9
|
-
prof_stack_t* prof_stack_create()
|
|
10
|
-
{
|
|
11
|
-
prof_stack_t* stack = ALLOC(prof_stack_t);
|
|
12
|
-
stack->start = ZALLOC_N(prof_frame_t, INITIAL_STACK_SIZE);
|
|
13
|
-
stack->ptr = stack->start;
|
|
14
|
-
stack->end = stack->start + INITIAL_STACK_SIZE;
|
|
15
|
-
|
|
16
|
-
return stack;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
void prof_stack_free(prof_stack_t* stack)
|
|
20
|
-
{
|
|
21
|
-
xfree(stack->start);
|
|
22
|
-
xfree(stack);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
prof_frame_t* prof_stack_parent(prof_stack_t* stack)
|
|
26
|
-
{
|
|
27
|
-
if (stack->ptr == stack->start || stack->ptr - 1 == stack->start)
|
|
28
|
-
return NULL;
|
|
29
|
-
else
|
|
30
|
-
return stack->ptr - 2;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
prof_frame_t* prof_stack_last(prof_stack_t* stack)
|
|
34
|
-
{
|
|
35
|
-
if (stack->ptr == stack->start)
|
|
36
|
-
return NULL;
|
|
37
|
-
else
|
|
38
|
-
return stack->ptr - 1;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
void prof_stack_verify_size(prof_stack_t* stack)
|
|
42
|
-
{
|
|
43
|
-
// Is there space on the stack? If not, double its size.
|
|
44
|
-
if (stack->ptr == stack->end)
|
|
45
|
-
{
|
|
46
|
-
size_t len = stack->ptr - stack->start;
|
|
47
|
-
size_t new_capacity = (stack->end - stack->start) * 2;
|
|
48
|
-
REALLOC_N(stack->start, prof_frame_t, new_capacity);
|
|
49
|
-
|
|
50
|
-
/* Memory just got moved, reset pointers */
|
|
51
|
-
stack->ptr = stack->start + len;
|
|
52
|
-
stack->end = stack->start + new_capacity;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
prof_frame_t* prof_stack_push(prof_stack_t* stack)
|
|
57
|
-
{
|
|
58
|
-
prof_stack_verify_size(stack);
|
|
59
|
-
|
|
60
|
-
prof_frame_t* result = stack->ptr;
|
|
61
|
-
stack->ptr++;
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
prof_frame_t* prof_stack_pop(prof_stack_t* stack)
|
|
66
|
-
{
|
|
67
|
-
prof_frame_t* result = prof_stack_last(stack);
|
|
68
|
-
if (result)
|
|
69
|
-
stack->ptr--;
|
|
70
|
-
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// ---------------- Frame Methods ----------------------------
|
|
75
|
-
void prof_frame_pause(prof_frame_t* frame, double current_measurement)
|
|
76
|
-
{
|
|
77
|
-
if (frame && prof_frame_is_unpaused(frame))
|
|
78
|
-
frame->pause_time = current_measurement;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
void prof_frame_unpause(prof_frame_t* frame, double current_measurement)
|
|
82
|
-
{
|
|
83
|
-
if (prof_frame_is_paused(frame))
|
|
84
|
-
{
|
|
85
|
-
frame->dead_time += (current_measurement - frame->pause_time);
|
|
86
|
-
frame->pause_time = -1;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
prof_frame_t* prof_frame_current(prof_stack_t* stack)
|
|
91
|
-
{
|
|
92
|
-
return prof_stack_last(stack);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
prof_frame_t* prof_frame_push(prof_stack_t* stack, prof_call_tree_t* call_tree, double measurement, bool paused)
|
|
96
|
-
{
|
|
97
|
-
prof_frame_t* result = prof_stack_push(stack);
|
|
98
|
-
prof_frame_t* parent_frame = prof_stack_parent(stack);
|
|
99
|
-
|
|
100
|
-
result->call_tree = call_tree;
|
|
101
|
-
|
|
102
|
-
result->start_time = measurement;
|
|
103
|
-
result->pause_time = -1; // init as not paused.
|
|
104
|
-
result->switch_time = 0;
|
|
105
|
-
result->wait_time = 0;
|
|
106
|
-
result->child_time = 0;
|
|
107
|
-
result->dead_time = 0;
|
|
108
|
-
result->source_file = Qnil;
|
|
109
|
-
result->source_line = 0;
|
|
110
|
-
|
|
111
|
-
call_tree->measurement->called++;
|
|
112
|
-
call_tree->visits++;
|
|
113
|
-
|
|
114
|
-
if (call_tree->method->visits > 0)
|
|
115
|
-
{
|
|
116
|
-
call_tree->method->recursive = true;
|
|
117
|
-
}
|
|
118
|
-
call_tree->method->measurement->called++;
|
|
119
|
-
call_tree->method->visits++;
|
|
120
|
-
|
|
121
|
-
// Unpause the parent frame, if it exists.
|
|
122
|
-
// If currently paused then:
|
|
123
|
-
// 1) The child frame will begin paused.
|
|
124
|
-
// 2) The parent will inherit the child's dead time.
|
|
125
|
-
if (parent_frame)
|
|
126
|
-
prof_frame_unpause(parent_frame, measurement);
|
|
127
|
-
|
|
128
|
-
if (paused)
|
|
129
|
-
{
|
|
130
|
-
prof_frame_pause(result, measurement);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Return the result
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
prof_frame_t* prof_frame_unshift(prof_stack_t* stack, prof_call_tree_t* parent_call_tree, prof_call_tree_t* call_tree, double measurement)
|
|
138
|
-
{
|
|
139
|
-
if (prof_stack_last(stack))
|
|
140
|
-
rb_raise(rb_eRuntimeError, "Stack unshift can only be called with an empty stack");
|
|
141
|
-
|
|
142
|
-
parent_call_tree->measurement->total_time = call_tree->measurement->total_time;
|
|
143
|
-
parent_call_tree->measurement->self_time = 0;
|
|
144
|
-
parent_call_tree->measurement->wait_time = call_tree->measurement->wait_time;
|
|
145
|
-
|
|
146
|
-
parent_call_tree->method->measurement->total_time += call_tree->measurement->total_time;
|
|
147
|
-
parent_call_tree->method->measurement->wait_time += call_tree->measurement->wait_time;
|
|
148
|
-
|
|
149
|
-
return prof_frame_push(stack, parent_call_tree, measurement, false);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
prof_frame_t* prof_frame_pop(prof_stack_t* stack, double measurement)
|
|
153
|
-
{
|
|
154
|
-
prof_frame_t* frame = prof_stack_pop(stack);
|
|
155
|
-
|
|
156
|
-
if (!frame)
|
|
157
|
-
return NULL;
|
|
158
|
-
|
|
159
|
-
/* Calculate the total time this method took */
|
|
160
|
-
prof_frame_unpause(frame, measurement);
|
|
161
|
-
|
|
162
|
-
double total_time = measurement - frame->start_time - frame->dead_time;
|
|
163
|
-
double self_time = total_time - frame->child_time - frame->wait_time;
|
|
164
|
-
|
|
165
|
-
/* Update information about the current method */
|
|
166
|
-
prof_call_tree_t* call_tree = frame->call_tree;
|
|
167
|
-
|
|
168
|
-
// Update method measurement
|
|
169
|
-
call_tree->method->measurement->self_time += self_time;
|
|
170
|
-
call_tree->method->measurement->wait_time += frame->wait_time;
|
|
171
|
-
if (call_tree->method->visits == 1)
|
|
172
|
-
call_tree->method->measurement->total_time += total_time;
|
|
173
|
-
|
|
174
|
-
call_tree->method->visits--;
|
|
175
|
-
|
|
176
|
-
// Update method measurement
|
|
177
|
-
call_tree->measurement->self_time += self_time;
|
|
178
|
-
call_tree->measurement->wait_time += frame->wait_time;
|
|
179
|
-
if (call_tree->visits == 1)
|
|
180
|
-
call_tree->measurement->total_time += total_time;
|
|
181
|
-
|
|
182
|
-
call_tree->visits--;
|
|
183
|
-
|
|
184
|
-
prof_frame_t* parent_frame = prof_stack_last(stack);
|
|
185
|
-
if (parent_frame)
|
|
186
|
-
{
|
|
187
|
-
parent_frame->child_time += total_time;
|
|
188
|
-
parent_frame->dead_time += frame->dead_time;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
frame->source_file = Qnil;
|
|
192
|
-
|
|
193
|
-
return frame;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
prof_method_t* prof_find_method(prof_stack_t* stack, VALUE source_file, int source_line)
|
|
197
|
-
{
|
|
198
|
-
prof_frame_t* frame = prof_stack_last(stack);
|
|
199
|
-
while (frame >= stack->start)
|
|
200
|
-
{
|
|
201
|
-
if (!frame->call_tree)
|
|
202
|
-
return NULL;
|
|
203
|
-
|
|
204
|
-
if (rb_str_equal(source_file, frame->call_tree->method->source_file) &&
|
|
205
|
-
source_line >= frame->call_tree->method->source_line)
|
|
206
|
-
{
|
|
207
|
-
return frame->call_tree->method;
|
|
208
|
-
}
|
|
209
|
-
frame--;
|
|
210
|
-
}
|
|
211
|
-
return NULL;
|
|
212
|
-
}
|
|
1
|
+
/* Copyright (C) 2005-2019 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
|
|
2
|
+
Please see the LICENSE file for copyright and distribution information */
|
|
3
|
+
|
|
4
|
+
#include "rp_stack.h"
|
|
5
|
+
|
|
6
|
+
#define INITIAL_STACK_SIZE 16
|
|
7
|
+
|
|
8
|
+
// Creates a stack of prof_frame_t to keep track of timings for active methods.
|
|
9
|
+
prof_stack_t* prof_stack_create(void)
|
|
10
|
+
{
|
|
11
|
+
prof_stack_t* stack = ALLOC(prof_stack_t);
|
|
12
|
+
stack->start = ZALLOC_N(prof_frame_t, INITIAL_STACK_SIZE);
|
|
13
|
+
stack->ptr = stack->start;
|
|
14
|
+
stack->end = stack->start + INITIAL_STACK_SIZE;
|
|
15
|
+
|
|
16
|
+
return stack;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
void prof_stack_free(prof_stack_t* stack)
|
|
20
|
+
{
|
|
21
|
+
xfree(stack->start);
|
|
22
|
+
xfree(stack);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
prof_frame_t* prof_stack_parent(prof_stack_t* stack)
|
|
26
|
+
{
|
|
27
|
+
if (stack->ptr == stack->start || stack->ptr - 1 == stack->start)
|
|
28
|
+
return NULL;
|
|
29
|
+
else
|
|
30
|
+
return stack->ptr - 2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
prof_frame_t* prof_stack_last(prof_stack_t* stack)
|
|
34
|
+
{
|
|
35
|
+
if (stack->ptr == stack->start)
|
|
36
|
+
return NULL;
|
|
37
|
+
else
|
|
38
|
+
return stack->ptr - 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
void prof_stack_verify_size(prof_stack_t* stack)
|
|
42
|
+
{
|
|
43
|
+
// Is there space on the stack? If not, double its size.
|
|
44
|
+
if (stack->ptr == stack->end)
|
|
45
|
+
{
|
|
46
|
+
size_t len = stack->ptr - stack->start;
|
|
47
|
+
size_t new_capacity = (stack->end - stack->start) * 2;
|
|
48
|
+
REALLOC_N(stack->start, prof_frame_t, new_capacity);
|
|
49
|
+
|
|
50
|
+
/* Memory just got moved, reset pointers */
|
|
51
|
+
stack->ptr = stack->start + len;
|
|
52
|
+
stack->end = stack->start + new_capacity;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
prof_frame_t* prof_stack_push(prof_stack_t* stack)
|
|
57
|
+
{
|
|
58
|
+
prof_stack_verify_size(stack);
|
|
59
|
+
|
|
60
|
+
prof_frame_t* result = stack->ptr;
|
|
61
|
+
stack->ptr++;
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
prof_frame_t* prof_stack_pop(prof_stack_t* stack)
|
|
66
|
+
{
|
|
67
|
+
prof_frame_t* result = prof_stack_last(stack);
|
|
68
|
+
if (result)
|
|
69
|
+
stack->ptr--;
|
|
70
|
+
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ---------------- Frame Methods ----------------------------
|
|
75
|
+
void prof_frame_pause(prof_frame_t* frame, double current_measurement)
|
|
76
|
+
{
|
|
77
|
+
if (frame && prof_frame_is_unpaused(frame))
|
|
78
|
+
frame->pause_time = current_measurement;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
void prof_frame_unpause(prof_frame_t* frame, double current_measurement)
|
|
82
|
+
{
|
|
83
|
+
if (prof_frame_is_paused(frame))
|
|
84
|
+
{
|
|
85
|
+
frame->dead_time += (current_measurement - frame->pause_time);
|
|
86
|
+
frame->pause_time = -1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
prof_frame_t* prof_frame_current(prof_stack_t* stack)
|
|
91
|
+
{
|
|
92
|
+
return prof_stack_last(stack);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
prof_frame_t* prof_frame_push(prof_stack_t* stack, prof_call_tree_t* call_tree, double measurement, bool paused)
|
|
96
|
+
{
|
|
97
|
+
prof_frame_t* result = prof_stack_push(stack);
|
|
98
|
+
prof_frame_t* parent_frame = prof_stack_parent(stack);
|
|
99
|
+
|
|
100
|
+
result->call_tree = call_tree;
|
|
101
|
+
|
|
102
|
+
result->start_time = measurement;
|
|
103
|
+
result->pause_time = -1; // init as not paused.
|
|
104
|
+
result->switch_time = 0;
|
|
105
|
+
result->wait_time = 0;
|
|
106
|
+
result->child_time = 0;
|
|
107
|
+
result->dead_time = 0;
|
|
108
|
+
result->source_file = Qnil;
|
|
109
|
+
result->source_line = 0;
|
|
110
|
+
|
|
111
|
+
call_tree->measurement->called++;
|
|
112
|
+
call_tree->visits++;
|
|
113
|
+
|
|
114
|
+
if (call_tree->method->visits > 0)
|
|
115
|
+
{
|
|
116
|
+
call_tree->method->recursive = true;
|
|
117
|
+
}
|
|
118
|
+
call_tree->method->measurement->called++;
|
|
119
|
+
call_tree->method->visits++;
|
|
120
|
+
|
|
121
|
+
// Unpause the parent frame, if it exists.
|
|
122
|
+
// If currently paused then:
|
|
123
|
+
// 1) The child frame will begin paused.
|
|
124
|
+
// 2) The parent will inherit the child's dead time.
|
|
125
|
+
if (parent_frame)
|
|
126
|
+
prof_frame_unpause(parent_frame, measurement);
|
|
127
|
+
|
|
128
|
+
if (paused)
|
|
129
|
+
{
|
|
130
|
+
prof_frame_pause(result, measurement);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Return the result
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
prof_frame_t* prof_frame_unshift(prof_stack_t* stack, prof_call_tree_t* parent_call_tree, prof_call_tree_t* call_tree, double measurement)
|
|
138
|
+
{
|
|
139
|
+
if (prof_stack_last(stack))
|
|
140
|
+
rb_raise(rb_eRuntimeError, "Stack unshift can only be called with an empty stack");
|
|
141
|
+
|
|
142
|
+
parent_call_tree->measurement->total_time = call_tree->measurement->total_time;
|
|
143
|
+
parent_call_tree->measurement->self_time = 0;
|
|
144
|
+
parent_call_tree->measurement->wait_time = call_tree->measurement->wait_time;
|
|
145
|
+
|
|
146
|
+
parent_call_tree->method->measurement->total_time += call_tree->measurement->total_time;
|
|
147
|
+
parent_call_tree->method->measurement->wait_time += call_tree->measurement->wait_time;
|
|
148
|
+
|
|
149
|
+
return prof_frame_push(stack, parent_call_tree, measurement, false);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
prof_frame_t* prof_frame_pop(prof_stack_t* stack, double measurement)
|
|
153
|
+
{
|
|
154
|
+
prof_frame_t* frame = prof_stack_pop(stack);
|
|
155
|
+
|
|
156
|
+
if (!frame)
|
|
157
|
+
return NULL;
|
|
158
|
+
|
|
159
|
+
/* Calculate the total time this method took */
|
|
160
|
+
prof_frame_unpause(frame, measurement);
|
|
161
|
+
|
|
162
|
+
double total_time = measurement - frame->start_time - frame->dead_time;
|
|
163
|
+
double self_time = total_time - frame->child_time - frame->wait_time;
|
|
164
|
+
|
|
165
|
+
/* Update information about the current method */
|
|
166
|
+
prof_call_tree_t* call_tree = frame->call_tree;
|
|
167
|
+
|
|
168
|
+
// Update method measurement
|
|
169
|
+
call_tree->method->measurement->self_time += self_time;
|
|
170
|
+
call_tree->method->measurement->wait_time += frame->wait_time;
|
|
171
|
+
if (call_tree->method->visits == 1)
|
|
172
|
+
call_tree->method->measurement->total_time += total_time;
|
|
173
|
+
|
|
174
|
+
call_tree->method->visits--;
|
|
175
|
+
|
|
176
|
+
// Update method measurement
|
|
177
|
+
call_tree->measurement->self_time += self_time;
|
|
178
|
+
call_tree->measurement->wait_time += frame->wait_time;
|
|
179
|
+
if (call_tree->visits == 1)
|
|
180
|
+
call_tree->measurement->total_time += total_time;
|
|
181
|
+
|
|
182
|
+
call_tree->visits--;
|
|
183
|
+
|
|
184
|
+
prof_frame_t* parent_frame = prof_stack_last(stack);
|
|
185
|
+
if (parent_frame)
|
|
186
|
+
{
|
|
187
|
+
parent_frame->child_time += total_time;
|
|
188
|
+
parent_frame->dead_time += frame->dead_time;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
frame->source_file = Qnil;
|
|
192
|
+
|
|
193
|
+
return frame;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
prof_method_t* prof_find_method(prof_stack_t* stack, VALUE source_file, int source_line)
|
|
197
|
+
{
|
|
198
|
+
prof_frame_t* frame = prof_stack_last(stack);
|
|
199
|
+
while (frame >= stack->start)
|
|
200
|
+
{
|
|
201
|
+
if (!frame->call_tree)
|
|
202
|
+
return NULL;
|
|
203
|
+
|
|
204
|
+
if (rb_str_equal(source_file, frame->call_tree->method->source_file) &&
|
|
205
|
+
source_line >= frame->call_tree->method->source_line)
|
|
206
|
+
{
|
|
207
|
+
return frame->call_tree->method;
|
|
208
|
+
}
|
|
209
|
+
frame--;
|
|
210
|
+
}
|
|
211
|
+
return NULL;
|
|
212
|
+
}
|
data/ext/ruby_prof/rp_thread.c
CHANGED
|
@@ -172,7 +172,7 @@ thread_data_t* prof_get_thread(VALUE self)
|
|
|
172
172
|
// ====== Thread Table ======
|
|
173
173
|
// The thread table is hash keyed on ruby fiber_id that stores instances of thread_data_t.
|
|
174
174
|
|
|
175
|
-
st_table* threads_table_create()
|
|
175
|
+
st_table* threads_table_create(void)
|
|
176
176
|
{
|
|
177
177
|
return rb_st_init_numtable();
|
|
178
178
|
}
|
data/ext/ruby_prof/ruby_prof.c
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/* Copyright (C) 2005-2019 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
|
|
2
|
-
Please see the LICENSE file for copyright and distribution information */
|
|
3
|
-
|
|
4
|
-
/* ruby-prof tracks the time spent executing every method in ruby programming.
|
|
5
|
-
The main players are:
|
|
6
|
-
|
|
7
|
-
profile_t - This represents 1 profile.
|
|
8
|
-
thread_data_t - Stores data about a single thread.
|
|
9
|
-
prof_stack_t - The method call stack in a particular thread
|
|
10
|
-
prof_method_t - Profiling information about each method
|
|
11
|
-
prof_call_tree_t - Keeps track a method's callers and callees.
|
|
12
|
-
|
|
13
|
-
The final result is an instance of a profile object which has a hash table of
|
|
14
|
-
thread_data_t, keyed on the thread id. Each thread in turn has a hash table
|
|
15
|
-
of prof_method_t, keyed on the method id. A hash table is used for quick
|
|
16
|
-
look up when doing a profile. However, it is exposed to Ruby as an array.
|
|
17
|
-
|
|
18
|
-
Each prof_method_t has two hash tables, parent and children, of prof_call_tree_t.
|
|
19
|
-
These objects keep track of a method's callers (who called the method) and its
|
|
20
|
-
callees (who the method called). These are keyed the method id, but once again,
|
|
21
|
-
are exposed to Ruby as arrays. Each prof_call_into_t maintains a pointer to the
|
|
22
|
-
caller or callee method, thereby making it easy to navigate through the call
|
|
23
|
-
hierarchy in ruby - which is very helpful for creating call graphs.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
#include "ruby_prof.h"
|
|
27
|
-
|
|
28
|
-
#include "rp_allocation.h"
|
|
29
|
-
#include "rp_measurement.h"
|
|
30
|
-
#include "rp_method.h"
|
|
31
|
-
#include "rp_call_tree.h"
|
|
32
|
-
#include "rp_call_trees.h"
|
|
33
|
-
#include "rp_profile.h"
|
|
34
|
-
#include "rp_stack.h"
|
|
35
|
-
#include "rp_thread.h"
|
|
36
|
-
|
|
37
|
-
VALUE mProf;
|
|
38
|
-
|
|
39
|
-
void Init_ruby_prof()
|
|
40
|
-
{
|
|
41
|
-
mProf = rb_define_module("RubyProf");
|
|
42
|
-
|
|
43
|
-
rp_init_allocation();
|
|
44
|
-
rp_init_call_tree();
|
|
45
|
-
rp_init_call_trees();
|
|
46
|
-
rp_init_measure();
|
|
47
|
-
rp_init_method_info();
|
|
48
|
-
rp_init_profile();
|
|
49
|
-
rp_init_thread();
|
|
50
|
-
}
|
|
1
|
+
/* Copyright (C) 2005-2019 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
|
|
2
|
+
Please see the LICENSE file for copyright and distribution information */
|
|
3
|
+
|
|
4
|
+
/* ruby-prof tracks the time spent executing every method in ruby programming.
|
|
5
|
+
The main players are:
|
|
6
|
+
|
|
7
|
+
profile_t - This represents 1 profile.
|
|
8
|
+
thread_data_t - Stores data about a single thread.
|
|
9
|
+
prof_stack_t - The method call stack in a particular thread
|
|
10
|
+
prof_method_t - Profiling information about each method
|
|
11
|
+
prof_call_tree_t - Keeps track a method's callers and callees.
|
|
12
|
+
|
|
13
|
+
The final result is an instance of a profile object which has a hash table of
|
|
14
|
+
thread_data_t, keyed on the thread id. Each thread in turn has a hash table
|
|
15
|
+
of prof_method_t, keyed on the method id. A hash table is used for quick
|
|
16
|
+
look up when doing a profile. However, it is exposed to Ruby as an array.
|
|
17
|
+
|
|
18
|
+
Each prof_method_t has two hash tables, parent and children, of prof_call_tree_t.
|
|
19
|
+
These objects keep track of a method's callers (who called the method) and its
|
|
20
|
+
callees (who the method called). These are keyed the method id, but once again,
|
|
21
|
+
are exposed to Ruby as arrays. Each prof_call_into_t maintains a pointer to the
|
|
22
|
+
caller or callee method, thereby making it easy to navigate through the call
|
|
23
|
+
hierarchy in ruby - which is very helpful for creating call graphs.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include "ruby_prof.h"
|
|
27
|
+
|
|
28
|
+
#include "rp_allocation.h"
|
|
29
|
+
#include "rp_measurement.h"
|
|
30
|
+
#include "rp_method.h"
|
|
31
|
+
#include "rp_call_tree.h"
|
|
32
|
+
#include "rp_call_trees.h"
|
|
33
|
+
#include "rp_profile.h"
|
|
34
|
+
#include "rp_stack.h"
|
|
35
|
+
#include "rp_thread.h"
|
|
36
|
+
|
|
37
|
+
VALUE mProf;
|
|
38
|
+
|
|
39
|
+
void Init_ruby_prof(void)
|
|
40
|
+
{
|
|
41
|
+
mProf = rb_define_module("RubyProf");
|
|
42
|
+
|
|
43
|
+
rp_init_allocation();
|
|
44
|
+
rp_init_call_tree();
|
|
45
|
+
rp_init_call_trees();
|
|
46
|
+
rp_init_measure();
|
|
47
|
+
rp_init_method_info();
|
|
48
|
+
rp_init_profile();
|
|
49
|
+
rp_init_thread();
|
|
50
|
+
}
|