ruby-prof 1.8.0-x64-mswin64-140

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 (108) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +665 -0
  3. data/LICENSE +25 -0
  4. data/README.md +5 -0
  5. data/Rakefile +98 -0
  6. data/bin/ruby-prof +341 -0
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +23 -0
  9. data/ext/ruby_prof/rp_allocation.c +327 -0
  10. data/ext/ruby_prof/rp_allocation.h +32 -0
  11. data/ext/ruby_prof/rp_call_tree.c +502 -0
  12. data/ext/ruby_prof/rp_call_tree.h +47 -0
  13. data/ext/ruby_prof/rp_call_trees.c +296 -0
  14. data/ext/ruby_prof/rp_call_trees.h +28 -0
  15. data/ext/ruby_prof/rp_measure_allocations.c +47 -0
  16. data/ext/ruby_prof/rp_measure_memory.c +46 -0
  17. data/ext/ruby_prof/rp_measure_process_time.c +64 -0
  18. data/ext/ruby_prof/rp_measure_wall_time.c +52 -0
  19. data/ext/ruby_prof/rp_measurement.c +359 -0
  20. data/ext/ruby_prof/rp_measurement.h +52 -0
  21. data/ext/ruby_prof/rp_method.c +551 -0
  22. data/ext/ruby_prof/rp_method.h +66 -0
  23. data/ext/ruby_prof/rp_profile.c +933 -0
  24. data/ext/ruby_prof/rp_profile.h +36 -0
  25. data/ext/ruby_prof/rp_stack.c +212 -0
  26. data/ext/ruby_prof/rp_stack.h +53 -0
  27. data/ext/ruby_prof/rp_thread.c +433 -0
  28. data/ext/ruby_prof/rp_thread.h +39 -0
  29. data/ext/ruby_prof/ruby_prof.c +50 -0
  30. data/ext/ruby_prof/ruby_prof.h +35 -0
  31. data/ext/ruby_prof/vc/ruby_prof.sln +39 -0
  32. data/ext/ruby_prof/vc/ruby_prof.vcxproj +158 -0
  33. data/lib/ruby-prof/assets/call_stack_printer.html.erb +711 -0
  34. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  35. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  36. data/lib/ruby-prof/call_tree.rb +57 -0
  37. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  38. data/lib/ruby-prof/compatibility.rb +113 -0
  39. data/lib/ruby-prof/exclude_common_methods.rb +204 -0
  40. data/lib/ruby-prof/measurement.rb +17 -0
  41. data/lib/ruby-prof/method_info.rb +87 -0
  42. data/lib/ruby-prof/printers/abstract_printer.rb +156 -0
  43. data/lib/ruby-prof/printers/call_info_printer.rb +53 -0
  44. data/lib/ruby-prof/printers/call_stack_printer.rb +180 -0
  45. data/lib/ruby-prof/printers/call_tree_printer.rb +145 -0
  46. data/lib/ruby-prof/printers/dot_printer.rb +132 -0
  47. data/lib/ruby-prof/printers/flat_printer.rb +53 -0
  48. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -0
  49. data/lib/ruby-prof/printers/graph_printer.rb +113 -0
  50. data/lib/ruby-prof/printers/multi_printer.rb +127 -0
  51. data/lib/ruby-prof/profile.rb +70 -0
  52. data/lib/ruby-prof/rack.rb +105 -0
  53. data/lib/ruby-prof/task.rb +147 -0
  54. data/lib/ruby-prof/thread.rb +20 -0
  55. data/lib/ruby-prof/version.rb +3 -0
  56. data/lib/ruby-prof.rb +52 -0
  57. data/lib/unprof.rb +10 -0
  58. data/ruby-prof.gemspec +67 -0
  59. data/test/abstract_printer_test.rb +27 -0
  60. data/test/alias_test.rb +117 -0
  61. data/test/call_tree_builder.rb +126 -0
  62. data/test/call_tree_test.rb +94 -0
  63. data/test/call_tree_visitor_test.rb +27 -0
  64. data/test/call_trees_test.rb +66 -0
  65. data/test/compatibility_test.rb +49 -0
  66. data/test/duplicate_names_test.rb +32 -0
  67. data/test/dynamic_method_test.rb +50 -0
  68. data/test/enumerable_test.rb +23 -0
  69. data/test/exceptions_test.rb +24 -0
  70. data/test/exclude_methods_test.rb +363 -0
  71. data/test/exclude_threads_test.rb +48 -0
  72. data/test/fiber_test.rb +195 -0
  73. data/test/gc_test.rb +104 -0
  74. data/test/inverse_call_tree_test.rb +174 -0
  75. data/test/line_number_test.rb +426 -0
  76. data/test/marshal_test.rb +145 -0
  77. data/test/measure_allocations.rb +26 -0
  78. data/test/measure_allocations_test.rb +1172 -0
  79. data/test/measure_process_time_test.rb +3330 -0
  80. data/test/measure_times.rb +56 -0
  81. data/test/measure_wall_time_test.rb +635 -0
  82. data/test/measurement_test.rb +82 -0
  83. data/test/merge_test.rb +146 -0
  84. data/test/method_info_test.rb +100 -0
  85. data/test/multi_printer_test.rb +66 -0
  86. data/test/no_method_class_test.rb +15 -0
  87. data/test/pause_resume_test.rb +171 -0
  88. data/test/prime.rb +54 -0
  89. data/test/prime_script.rb +6 -0
  90. data/test/printer_call_stack_test.rb +27 -0
  91. data/test/printer_call_tree_test.rb +30 -0
  92. data/test/printer_flat_test.rb +99 -0
  93. data/test/printer_graph_html_test.rb +59 -0
  94. data/test/printer_graph_test.rb +40 -0
  95. data/test/printers_test.rb +178 -0
  96. data/test/printing_recursive_graph_test.rb +81 -0
  97. data/test/profile_test.rb +101 -0
  98. data/test/rack_test.rb +93 -0
  99. data/test/recursive_test.rb +796 -0
  100. data/test/scheduler.rb +363 -0
  101. data/test/singleton_test.rb +38 -0
  102. data/test/stack_printer_test.rb +61 -0
  103. data/test/start_stop_test.rb +106 -0
  104. data/test/test_helper.rb +21 -0
  105. data/test/thread_test.rb +229 -0
  106. data/test/unique_call_path_test.rb +123 -0
  107. data/test/yarv_test.rb +56 -0
  108. metadata +228 -0
@@ -0,0 +1,359 @@
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_measurement.h"
5
+
6
+ VALUE mMeasure;
7
+ VALUE cRpMeasurement;
8
+
9
+ prof_measurer_t* prof_measurer_allocations(bool track_allocations);
10
+ prof_measurer_t* prof_measurer_process_time(bool track_allocations);
11
+ prof_measurer_t* prof_measurer_wall_time(bool track_allocations);
12
+
13
+ void rp_init_measure_allocations(void);
14
+ void rp_init_measure_process_time(void);
15
+ void rp_init_measure_wall_time(void);
16
+
17
+ prof_measurer_t* prof_measurer_create(prof_measure_mode_t measure, bool track_allocations)
18
+ {
19
+ switch (measure)
20
+ {
21
+ case MEASURE_WALL_TIME:
22
+ return prof_measurer_wall_time(track_allocations);
23
+ case MEASURE_PROCESS_TIME:
24
+ return prof_measurer_process_time(track_allocations);
25
+ case MEASURE_ALLOCATIONS:
26
+ return prof_measurer_allocations(track_allocations);
27
+ default:
28
+ rb_raise(rb_eArgError, "Unknown measure mode: %d", measure);
29
+ }
30
+ };
31
+
32
+ double prof_measure(prof_measurer_t* measurer, rb_trace_arg_t* trace_arg)
33
+ {
34
+ double measurement = measurer->measure(trace_arg);
35
+ return measurement * measurer->multiplier;
36
+ }
37
+
38
+ /* ======= prof_measurement_t ========*/
39
+ prof_measurement_t* prof_measurement_create(void)
40
+ {
41
+ prof_measurement_t* result = ALLOC(prof_measurement_t);
42
+ result->owner = OWNER_C;
43
+ result->total_time = 0;
44
+ result->self_time = 0;
45
+ result->wait_time = 0;
46
+ result->called = 0;
47
+ result->object = Qnil;
48
+ return result;
49
+ }
50
+
51
+ /* call-seq:
52
+ new(total_time, self_time, wait_time, called) -> Measurement
53
+
54
+ Creates a new measuremen instance. */
55
+ static VALUE prof_measurement_initialize(VALUE self, VALUE total_time, VALUE self_time, VALUE wait_time, VALUE called)
56
+ {
57
+ prof_measurement_t* result = prof_get_measurement(self);
58
+
59
+ result->total_time = NUM2DBL(total_time);
60
+ result->self_time = NUM2DBL(self_time);
61
+ result->wait_time = NUM2DBL(wait_time);
62
+ result->called = NUM2INT(called);
63
+ result->object = self;
64
+ return self;
65
+ }
66
+
67
+ prof_measurement_t* prof_measurement_copy(prof_measurement_t* other)
68
+ {
69
+ prof_measurement_t* result = prof_measurement_create();
70
+ result->called = other->called;
71
+ result->total_time = other->total_time;
72
+ result->self_time = other->self_time;
73
+ result->wait_time = other->wait_time;
74
+
75
+ return result;
76
+ }
77
+
78
+ static VALUE prof_measurement_initialize_copy(VALUE self, VALUE other)
79
+ {
80
+ // This object was created by Ruby either via Measurment#clone or Measurement#dup
81
+ // and thus prof_measurement_allocate was called so the object is owned by Ruby
82
+
83
+ if (self == other)
84
+ return self;
85
+
86
+ prof_measurement_t* self_ptr = prof_get_measurement(self);
87
+ prof_measurement_t* other_ptr = prof_get_measurement(other);
88
+
89
+ self_ptr->called = other_ptr->called;
90
+ self_ptr->total_time = other_ptr->total_time;
91
+ self_ptr->self_time = other_ptr->self_time;
92
+ self_ptr->wait_time = other_ptr->wait_time;
93
+
94
+ return self;
95
+ }
96
+
97
+ void prof_measurement_mark(void* data)
98
+ {
99
+ if (!data) return;
100
+
101
+ prof_measurement_t* measurement = (prof_measurement_t*)data;
102
+
103
+ if (measurement->object != Qnil)
104
+ rb_gc_mark_movable(measurement->object);
105
+ }
106
+
107
+ void prof_measurement_compact(void* data)
108
+ {
109
+ prof_measurement_t* measurement = (prof_measurement_t*)data;
110
+ measurement->object = rb_gc_location(measurement->object);
111
+ }
112
+
113
+ void prof_measurement_free(prof_measurement_t* measurement)
114
+ {
115
+ /* Has this measurement object been accessed by Ruby? If
116
+ yes clean it up so to avoid a segmentation fault. */
117
+ if (measurement->object != Qnil)
118
+ {
119
+ RTYPEDDATA(measurement->object)->data = NULL;
120
+ measurement->object = Qnil;
121
+ }
122
+
123
+ xfree(measurement);
124
+ }
125
+
126
+ static void prof_measurement_ruby_gc_free(void* data)
127
+ {
128
+ prof_measurement_t* measurement = (prof_measurement_t*)data;
129
+
130
+ if (!measurement)
131
+ {
132
+ // Object has already been freed by C code
133
+ return;
134
+ }
135
+ else if (measurement->owner == OWNER_RUBY)
136
+ {
137
+ // Ruby owns this object, we need to free the underlying C struct
138
+ prof_measurement_free(measurement);
139
+ }
140
+ else
141
+ {
142
+ // The Ruby object is being freed, but not the underlying C structure. So unlink the two.
143
+ measurement->object = Qnil;
144
+ }
145
+ }
146
+
147
+ size_t prof_measurement_size(const void* data)
148
+ {
149
+ return sizeof(prof_measurement_t);
150
+ }
151
+
152
+ static const rb_data_type_t measurement_type =
153
+ {
154
+ .wrap_struct_name = "Measurement",
155
+ .function =
156
+ {
157
+ .dmark = prof_measurement_mark,
158
+ .dfree = prof_measurement_ruby_gc_free,
159
+ .dsize = prof_measurement_size,
160
+ .dcompact = prof_measurement_compact
161
+ },
162
+ .data = NULL,
163
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
164
+ };
165
+
166
+ VALUE prof_measurement_wrap(prof_measurement_t* measurement)
167
+ {
168
+ if (measurement->object == Qnil)
169
+ {
170
+ measurement->object = TypedData_Wrap_Struct(cRpMeasurement, &measurement_type, measurement);
171
+ }
172
+ return measurement->object;
173
+ }
174
+
175
+ static VALUE prof_measurement_allocate(VALUE klass)
176
+ {
177
+ prof_measurement_t* measurement = prof_measurement_create();
178
+ // This object is being created by Ruby
179
+ measurement->owner = OWNER_RUBY;
180
+ measurement->object = prof_measurement_wrap(measurement);
181
+ return measurement->object;
182
+ }
183
+
184
+ prof_measurement_t* prof_get_measurement(VALUE self)
185
+ {
186
+ /* Can't use Data_Get_Struct because that triggers the event hook
187
+ ending up in endless recursion. */
188
+ prof_measurement_t* result = RTYPEDDATA_DATA(self);
189
+
190
+ if (!result)
191
+ rb_raise(rb_eRuntimeError, "This RubyProf::Measurement instance has already been freed, likely because its profile has been freed.");
192
+
193
+ return result;
194
+ }
195
+
196
+ /* call-seq:
197
+ total_time -> float
198
+
199
+ Returns the total amount of time spent in this method and its children. */
200
+ static VALUE prof_measurement_total_time(VALUE self)
201
+ {
202
+ prof_measurement_t* result = prof_get_measurement(self);
203
+ return rb_float_new(result->total_time);
204
+ }
205
+
206
+ /* call-seq:
207
+ total_time=value -> value
208
+
209
+ Sets the call count to n. */
210
+ static VALUE prof_measurement_set_total_time(VALUE self, VALUE value)
211
+ {
212
+ prof_measurement_t* result = prof_get_measurement(self);
213
+ result->total_time = NUM2DBL(value);
214
+ return value;
215
+ }
216
+
217
+ /* call-seq:
218
+ self_time -> float
219
+
220
+ Returns the total amount of time spent in this method. */
221
+ static VALUE
222
+ prof_measurement_self_time(VALUE self)
223
+ {
224
+ prof_measurement_t* result = prof_get_measurement(self);
225
+
226
+ return rb_float_new(result->self_time);
227
+ }
228
+
229
+ /* call-seq:
230
+ self_time=value -> value
231
+
232
+ Sets the call count to value. */
233
+ static VALUE prof_measurement_set_self_time(VALUE self, VALUE value)
234
+ {
235
+ prof_measurement_t* result = prof_get_measurement(self);
236
+ result->self_time = NUM2DBL(value);
237
+ return value;
238
+ }
239
+
240
+ /* call-seq:
241
+ wait_time -> float
242
+
243
+ Returns the total amount of time this method waited for other threads. */
244
+ static VALUE prof_measurement_wait_time(VALUE self)
245
+ {
246
+ prof_measurement_t* result = prof_get_measurement(self);
247
+
248
+ return rb_float_new(result->wait_time);
249
+ }
250
+
251
+ /* call-seq:
252
+ wait_time=value -> value
253
+
254
+ Sets the wait time to value. */
255
+ static VALUE prof_measurement_set_wait_time(VALUE self, VALUE value)
256
+ {
257
+ prof_measurement_t* result = prof_get_measurement(self);
258
+ result->wait_time = NUM2DBL(value);
259
+ return value;
260
+ }
261
+
262
+ /* call-seq:
263
+ called -> int
264
+
265
+ Returns the total amount of times this method was called. */
266
+ static VALUE prof_measurement_called(VALUE self)
267
+ {
268
+ prof_measurement_t* result = prof_get_measurement(self);
269
+ return INT2NUM(result->called);
270
+ }
271
+
272
+ /* call-seq:
273
+ called=value -> value
274
+
275
+ Sets the call count to value. */
276
+ static VALUE prof_measurement_set_called(VALUE self, VALUE value)
277
+ {
278
+ prof_measurement_t* result = prof_get_measurement(self);
279
+ result->called = NUM2INT(value);
280
+ return value;
281
+ }
282
+
283
+ /* :nodoc: */
284
+ void prof_measurement_merge_internal(prof_measurement_t* self, prof_measurement_t* other)
285
+ {
286
+ self->called += other->called;
287
+ self->total_time += other->total_time;
288
+ self->self_time += other->self_time;
289
+ self->wait_time += other->wait_time;
290
+ }
291
+
292
+ /* call-seq:
293
+ merge(other)
294
+
295
+ Adds the content of other measurement to this measurement */
296
+ VALUE prof_measurement_merge(VALUE self, VALUE other)
297
+ {
298
+ prof_measurement_t* self_ptr = prof_get_measurement(self);
299
+ prof_measurement_t* other_ptr = prof_get_measurement(other);
300
+ prof_measurement_merge_internal(self_ptr, other_ptr);
301
+ return self;
302
+ }
303
+
304
+ /* :nodoc: */
305
+ static VALUE prof_measurement_dump(VALUE self)
306
+ {
307
+ prof_measurement_t* measurement_data = prof_get_measurement(self);
308
+ VALUE result = rb_hash_new();
309
+
310
+ rb_hash_aset(result, ID2SYM(rb_intern("owner")), INT2FIX(measurement_data->owner));
311
+ rb_hash_aset(result, ID2SYM(rb_intern("total_time")), rb_float_new(measurement_data->total_time));
312
+ rb_hash_aset(result, ID2SYM(rb_intern("self_time")), rb_float_new(measurement_data->self_time));
313
+ rb_hash_aset(result, ID2SYM(rb_intern("wait_time")), rb_float_new(measurement_data->wait_time));
314
+ rb_hash_aset(result, ID2SYM(rb_intern("called")), INT2FIX(measurement_data->called));
315
+
316
+ return result;
317
+ }
318
+
319
+ /* :nodoc: */
320
+ static VALUE
321
+ prof_measurement_load(VALUE self, VALUE data)
322
+ {
323
+ prof_measurement_t* measurement = prof_get_measurement(self);
324
+ measurement->object = self;
325
+
326
+ measurement->owner = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("owner"))));
327
+ measurement->total_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("total_time"))));
328
+ measurement->self_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("self_time"))));
329
+ measurement->wait_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("wait_time"))));
330
+ measurement->called = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("called"))));
331
+
332
+ return data;
333
+ }
334
+
335
+ void rp_init_measure(void)
336
+ {
337
+ mMeasure = rb_define_module_under(mProf, "Measure");
338
+ rp_init_measure_wall_time();
339
+ rp_init_measure_process_time();
340
+ rp_init_measure_allocations();
341
+
342
+ cRpMeasurement = rb_define_class_under(mProf, "Measurement", rb_cObject);
343
+ rb_define_alloc_func(cRpMeasurement, prof_measurement_allocate);
344
+
345
+ rb_define_method(cRpMeasurement, "initialize", prof_measurement_initialize, 4);
346
+ rb_define_method(cRpMeasurement, "initialize_copy", prof_measurement_initialize_copy, 1);
347
+ rb_define_method(cRpMeasurement, "merge!", prof_measurement_merge, 1);
348
+ rb_define_method(cRpMeasurement, "called", prof_measurement_called, 0);
349
+ rb_define_method(cRpMeasurement, "called=", prof_measurement_set_called, 1);
350
+ rb_define_method(cRpMeasurement, "total_time", prof_measurement_total_time, 0);
351
+ rb_define_method(cRpMeasurement, "total_time=", prof_measurement_set_total_time, 1);
352
+ rb_define_method(cRpMeasurement, "self_time", prof_measurement_self_time, 0);
353
+ rb_define_method(cRpMeasurement, "self_time=", prof_measurement_set_self_time, 1);
354
+ rb_define_method(cRpMeasurement, "wait_time", prof_measurement_wait_time, 0);
355
+ rb_define_method(cRpMeasurement, "wait_time=", prof_measurement_set_wait_time, 1);
356
+
357
+ rb_define_method(cRpMeasurement, "_dump_data", prof_measurement_dump, 0);
358
+ rb_define_method(cRpMeasurement, "_load_data", prof_measurement_load, 1);
359
+ }
@@ -0,0 +1,52 @@
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_measurementMENT_H__
5
+ #define __rp_measurementMENT_H__
6
+
7
+ #include "ruby_prof.h"
8
+
9
+ extern VALUE mMeasure;
10
+
11
+ typedef double (*get_measurement)(rb_trace_arg_t* trace_arg);
12
+
13
+ typedef enum
14
+ {
15
+ MEASURE_WALL_TIME,
16
+ MEASURE_PROCESS_TIME,
17
+ MEASURE_ALLOCATIONS
18
+ } prof_measure_mode_t;
19
+
20
+ typedef struct prof_measurer_t
21
+ {
22
+ get_measurement measure;
23
+ prof_measure_mode_t mode;
24
+ double multiplier;
25
+ bool track_allocations;
26
+ } prof_measurer_t;
27
+
28
+ /* Callers and callee information for a method. */
29
+ typedef struct prof_measurement_t
30
+ {
31
+ prof_owner_t owner;
32
+ double total_time;
33
+ double self_time;
34
+ double wait_time;
35
+ int called;
36
+ VALUE object;
37
+ } prof_measurement_t;
38
+
39
+ prof_measurer_t* prof_measurer_create(prof_measure_mode_t measure, bool track_allocations);
40
+ double prof_measure(prof_measurer_t* measurer, rb_trace_arg_t* trace_arg);
41
+
42
+ prof_measurement_t* prof_measurement_create(void);
43
+ prof_measurement_t* prof_measurement_copy(prof_measurement_t* other);
44
+ void prof_measurement_free(prof_measurement_t* measurement);
45
+ VALUE prof_measurement_wrap(prof_measurement_t* measurement);
46
+ prof_measurement_t* prof_get_measurement(VALUE self);
47
+ void prof_measurement_mark(void* data);
48
+ void prof_measurement_merge_internal(prof_measurement_t* destination, prof_measurement_t* other);
49
+
50
+ void rp_init_measure(void);
51
+
52
+ #endif //__rp_measurementMENT_H__