ruby-prof 1.7.1 → 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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +8 -0
  3. data/ext/ruby_prof/extconf.rb +23 -22
  4. data/ext/ruby_prof/rp_call_trees.c +296 -296
  5. data/ext/ruby_prof/rp_call_trees.h +28 -28
  6. data/ext/ruby_prof/rp_measure_allocations.c +47 -47
  7. data/ext/ruby_prof/rp_measure_process_time.c +64 -66
  8. data/ext/ruby_prof/rp_measure_wall_time.c +52 -64
  9. data/ext/ruby_prof/rp_method.c +551 -551
  10. data/ext/ruby_prof/rp_stack.c +212 -212
  11. data/ext/ruby_prof/ruby_prof.c +50 -50
  12. data/ext/ruby_prof/ruby_prof.h +3 -2
  13. data/ext/ruby_prof/vc/ruby_prof.vcxproj +3 -3
  14. data/lib/ruby-prof/compatibility.rb +113 -113
  15. data/lib/ruby-prof/exclude_common_methods.rb +204 -204
  16. data/lib/ruby-prof/printers/abstract_printer.rb +156 -138
  17. data/lib/ruby-prof/version.rb +3 -3
  18. data/ruby-prof.gemspec +66 -65
  19. data/test/dynamic_method_test.rb +9 -21
  20. data/test/enumerable_test.rb +23 -21
  21. data/test/exclude_methods_test.rb +363 -257
  22. data/test/fiber_test.rb +195 -195
  23. data/test/gc_test.rb +104 -102
  24. data/test/line_number_test.rb +426 -289
  25. data/test/measure_allocations_test.rb +1172 -1081
  26. data/test/measure_memory_test.rb +1193 -1456
  27. data/test/measure_process_time_test.rb +3330 -2477
  28. data/test/measure_wall_time_test.rb +634 -568
  29. data/test/merge_test.rb +146 -146
  30. data/test/method_info_test.rb +100 -95
  31. data/test/printers_test.rb +178 -135
  32. data/test/recursive_test.rb +796 -622
  33. data/test/start_stop_test.rb +4 -4
  34. data/test/test_helper.rb +20 -20
  35. data/test/thread_test.rb +229 -231
  36. data/test/unique_call_path_test.rb +9 -22
  37. data/test/yarv_test.rb +1 -5
  38. metadata +19 -9
  39. data/test/crash2.rb +0 -144
@@ -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(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
- }
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
+ }
@@ -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(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
- }
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
+ }
@@ -4,11 +4,12 @@
4
4
  #ifndef __RUBY_PROF_H__
5
5
  #define __RUBY_PROF_H__
6
6
 
7
- #include <ruby.h>
8
- #include <ruby/debug.h>
9
7
  #include <stdio.h>
10
8
  #include <stdbool.h>
11
9
 
10
+ #include <ruby.h>
11
+ #include <ruby/debug.h>
12
+
12
13
  #ifndef rb_st_lookup
13
14
  #define rb_st_foreach st_foreach
14
15
  #define rb_st_free_table st_free_table
@@ -104,14 +104,14 @@
104
104
  </ItemDefinitionGroup>
105
105
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
106
106
  <ClCompile>
107
- <AdditionalIncludeDirectories>C:\msys64\usr\local\ruby-3.3.0-vc\include\ruby-3.3.0\x64-mswin64_140;C:\msys64\usr\local\ruby-3.3.0-vc\include\ruby-3.3.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
107
+ <AdditionalIncludeDirectories>C:\msys64\usr\local\ruby-3.4.3-mswin\include\ruby-3.4.0\x64-mswin64_140;C:\msys64\usr\local\ruby-3.4.3-mswin\include\ruby-3.4.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
108
108
  <Optimization>Disabled</Optimization>
109
109
  <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
110
110
  <WarningLevel>Level3</WarningLevel>
111
111
  </ClCompile>
112
112
  <Link>
113
- <AdditionalLibraryDirectories>C:\msys64\usr\local\ruby-3.3.0-vc\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
114
- <AdditionalDependencies>x64-vcruntime140-ruby330.lib;%(AdditionalDependencies)</AdditionalDependencies>
113
+ <AdditionalLibraryDirectories>C:\msys64\usr\local\ruby-3.4.3-mswin\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
114
+ <AdditionalDependencies>x64-vcruntime140-ruby340.lib;%(AdditionalDependencies)</AdditionalDependencies>
115
115
  <ModuleDefinitionFile>ruby_prof.def</ModuleDefinitionFile>
116
116
  <SubSystem>Console</SubSystem>
117
117
  </Link>