ruby-prof 1.4.4-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +608 -0
  3. data/LICENSE +25 -0
  4. data/README.md +5 -0
  5. data/Rakefile +98 -0
  6. data/bin/ruby-prof +328 -0
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +22 -0
  9. data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
  10. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  11. data/ext/ruby_prof/rp_allocation.c +287 -0
  12. data/ext/ruby_prof/rp_allocation.h +31 -0
  13. data/ext/ruby_prof/rp_call_tree.c +367 -0
  14. data/ext/ruby_prof/rp_call_tree.h +43 -0
  15. data/ext/ruby_prof/rp_call_trees.c +288 -0
  16. data/ext/ruby_prof/rp_call_trees.h +28 -0
  17. data/ext/ruby_prof/rp_measure_allocations.c +47 -0
  18. data/ext/ruby_prof/rp_measure_memory.c +46 -0
  19. data/ext/ruby_prof/rp_measure_process_time.c +66 -0
  20. data/ext/ruby_prof/rp_measure_wall_time.c +64 -0
  21. data/ext/ruby_prof/rp_measurement.c +237 -0
  22. data/ext/ruby_prof/rp_measurement.h +50 -0
  23. data/ext/ruby_prof/rp_method.c +491 -0
  24. data/ext/ruby_prof/rp_method.h +62 -0
  25. data/ext/ruby_prof/rp_profile.c +915 -0
  26. data/ext/ruby_prof/rp_profile.h +35 -0
  27. data/ext/ruby_prof/rp_stack.c +212 -0
  28. data/ext/ruby_prof/rp_stack.h +53 -0
  29. data/ext/ruby_prof/rp_thread.c +362 -0
  30. data/ext/ruby_prof/rp_thread.h +39 -0
  31. data/ext/ruby_prof/ruby_prof.c +52 -0
  32. data/ext/ruby_prof/ruby_prof.h +26 -0
  33. data/ext/ruby_prof/vc/ruby_prof.sln +39 -0
  34. data/ext/ruby_prof/vc/ruby_prof.vcxproj +160 -0
  35. data/lib/3.1/ruby_prof.so +0 -0
  36. data/lib/ruby-prof/assets/call_stack_printer.html.erb +711 -0
  37. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  38. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  39. data/lib/ruby-prof/call_tree.rb +57 -0
  40. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  41. data/lib/ruby-prof/compatibility.rb +99 -0
  42. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  43. data/lib/ruby-prof/measurement.rb +17 -0
  44. data/lib/ruby-prof/method_info.rb +78 -0
  45. data/lib/ruby-prof/printers/abstract_printer.rb +137 -0
  46. data/lib/ruby-prof/printers/call_info_printer.rb +53 -0
  47. data/lib/ruby-prof/printers/call_stack_printer.rb +180 -0
  48. data/lib/ruby-prof/printers/call_tree_printer.rb +147 -0
  49. data/lib/ruby-prof/printers/dot_printer.rb +132 -0
  50. data/lib/ruby-prof/printers/flat_printer.rb +53 -0
  51. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -0
  52. data/lib/ruby-prof/printers/graph_printer.rb +113 -0
  53. data/lib/ruby-prof/printers/multi_printer.rb +127 -0
  54. data/lib/ruby-prof/profile.rb +37 -0
  55. data/lib/ruby-prof/rack.rb +95 -0
  56. data/lib/ruby-prof/task.rb +147 -0
  57. data/lib/ruby-prof/thread.rb +20 -0
  58. data/lib/ruby-prof/version.rb +3 -0
  59. data/lib/ruby-prof.rb +52 -0
  60. data/lib/unprof.rb +10 -0
  61. data/ruby-prof.gemspec +64 -0
  62. data/test/abstract_printer_test.rb +26 -0
  63. data/test/alias_test.rb +122 -0
  64. data/test/basic_test.rb +43 -0
  65. data/test/call_tree_visitor_test.rb +32 -0
  66. data/test/call_trees_test.rb +66 -0
  67. data/test/duplicate_names_test.rb +32 -0
  68. data/test/dynamic_method_test.rb +67 -0
  69. data/test/enumerable_test.rb +21 -0
  70. data/test/exceptions_test.rb +24 -0
  71. data/test/exclude_methods_test.rb +151 -0
  72. data/test/exclude_threads_test.rb +53 -0
  73. data/test/fiber_test.rb +129 -0
  74. data/test/gc_test.rb +100 -0
  75. data/test/inverse_call_tree_test.rb +175 -0
  76. data/test/line_number_test.rb +158 -0
  77. data/test/marshal_test.rb +145 -0
  78. data/test/measure_allocations.rb +26 -0
  79. data/test/measure_allocations_test.rb +333 -0
  80. data/test/measure_memory_test.rb +688 -0
  81. data/test/measure_process_time_test.rb +1614 -0
  82. data/test/measure_times.rb +56 -0
  83. data/test/measure_wall_time_test.rb +426 -0
  84. data/test/multi_printer_test.rb +71 -0
  85. data/test/no_method_class_test.rb +15 -0
  86. data/test/pause_resume_test.rb +175 -0
  87. data/test/prime.rb +54 -0
  88. data/test/prime_script.rb +6 -0
  89. data/test/printer_call_stack_test.rb +27 -0
  90. data/test/printer_call_tree_test.rb +30 -0
  91. data/test/printer_flat_test.rb +99 -0
  92. data/test/printer_graph_html_test.rb +59 -0
  93. data/test/printer_graph_test.rb +40 -0
  94. data/test/printers_test.rb +141 -0
  95. data/test/printing_recursive_graph_test.rb +81 -0
  96. data/test/profile_test.rb +16 -0
  97. data/test/rack_test.rb +93 -0
  98. data/test/recursive_test.rb +430 -0
  99. data/test/singleton_test.rb +38 -0
  100. data/test/stack_printer_test.rb +64 -0
  101. data/test/start_stop_test.rb +109 -0
  102. data/test/test_helper.rb +13 -0
  103. data/test/thread_test.rb +144 -0
  104. data/test/unique_call_path_test.rb +136 -0
  105. data/test/yarv_test.rb +60 -0
  106. metadata +187 -0
@@ -0,0 +1,237 @@
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_memory(bool track_allocations);
11
+ prof_measurer_t* prof_measurer_process_time(bool track_allocations);
12
+ prof_measurer_t* prof_measurer_wall_time(bool track_allocations);
13
+
14
+ void rp_init_measure_allocations(void);
15
+ void rp_init_measure_memory(void);
16
+ void rp_init_measure_process_time(void);
17
+ void rp_init_measure_wall_time(void);
18
+
19
+ prof_measurer_t* prof_measurer_create(prof_measure_mode_t measure, bool track_allocations)
20
+ {
21
+ switch (measure)
22
+ {
23
+ case MEASURE_WALL_TIME:
24
+ return prof_measurer_wall_time(track_allocations);
25
+ case MEASURE_PROCESS_TIME:
26
+ return prof_measurer_process_time(track_allocations);
27
+ case MEASURE_ALLOCATIONS:
28
+ return prof_measurer_allocations(track_allocations);
29
+ case MEASURE_MEMORY:
30
+ return prof_measurer_memory(track_allocations);
31
+ default:
32
+ rb_raise(rb_eArgError, "Unknown measure mode: %d", measure);
33
+ }
34
+ };
35
+
36
+ double prof_measure(prof_measurer_t* measurer, rb_trace_arg_t* trace_arg)
37
+ {
38
+ double measurement = measurer->measure(trace_arg);
39
+ return measurement * measurer->multiplier;
40
+ }
41
+
42
+ /* ======= prof_measurement_t ========*/
43
+ prof_measurement_t* prof_measurement_create(void)
44
+ {
45
+ prof_measurement_t* result = ALLOC(prof_measurement_t);
46
+ result->total_time = 0;
47
+ result->self_time = 0;
48
+ result->wait_time = 0;
49
+ result->called = 0;
50
+ result->object = Qnil;
51
+ return result;
52
+ }
53
+
54
+ void prof_measurement_mark(void* data)
55
+ {
56
+ if (!data) return;
57
+
58
+ prof_measurement_t* measurement_data = (prof_measurement_t*)data;
59
+
60
+ if (measurement_data->object != Qnil)
61
+ rb_gc_mark(measurement_data->object);
62
+ }
63
+
64
+ static void prof_measurement_ruby_gc_free(void* data)
65
+ {
66
+ if (data)
67
+ {
68
+ // Measurements are freed by their owning object (call info or method)
69
+ prof_measurement_t* measurement = (prof_measurement_t*)data;
70
+ measurement->object = Qnil;
71
+ }
72
+ }
73
+
74
+ void prof_measurement_free(prof_measurement_t* measurement)
75
+ {
76
+ /* Has this measurement object been accessed by Ruby? If
77
+ yes clean it up so to avoid a segmentation fault. */
78
+ if (measurement->object != Qnil)
79
+ {
80
+ RTYPEDDATA(measurement->object)->data = NULL;
81
+ measurement->object = Qnil;
82
+ }
83
+
84
+ xfree(measurement);
85
+ }
86
+
87
+ size_t prof_measurement_size(const void* data)
88
+ {
89
+ return sizeof(prof_measurement_t);
90
+ }
91
+
92
+ static const rb_data_type_t measurement_type =
93
+ {
94
+ .wrap_struct_name = "Measurement",
95
+ .function =
96
+ {
97
+ .dmark = prof_measurement_mark,
98
+ .dfree = prof_measurement_ruby_gc_free,
99
+ .dsize = prof_measurement_size,
100
+ },
101
+ .data = NULL,
102
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
103
+ };
104
+
105
+ VALUE prof_measurement_wrap(prof_measurement_t* measurement)
106
+ {
107
+ if (measurement->object == Qnil)
108
+ {
109
+ measurement->object = TypedData_Wrap_Struct(cRpMeasurement, &measurement_type, measurement);
110
+ }
111
+ return measurement->object;
112
+ }
113
+
114
+ static VALUE prof_measurement_allocate(VALUE klass)
115
+ {
116
+ prof_measurement_t* measurement = prof_measurement_create();
117
+ measurement->object = prof_measurement_wrap(measurement);
118
+ return measurement->object;
119
+ }
120
+
121
+ prof_measurement_t* prof_get_measurement(VALUE self)
122
+ {
123
+ /* Can't use Data_Get_Struct because that triggers the event hook
124
+ ending up in endless recursion. */
125
+ prof_measurement_t* result = RTYPEDDATA_DATA(self);
126
+
127
+ if (!result)
128
+ rb_raise(rb_eRuntimeError, "This RubyProf::Measurement instance has already been freed, likely because its profile has been freed.");
129
+
130
+ return result;
131
+ }
132
+
133
+ /* call-seq:
134
+ total_time -> float
135
+
136
+ Returns the total amount of time spent in this method and its children. */
137
+ static VALUE prof_measurement_total_time(VALUE self)
138
+ {
139
+ prof_measurement_t* result = prof_get_measurement(self);
140
+ return rb_float_new(result->total_time);
141
+ }
142
+
143
+ /* call-seq:
144
+ self_time -> float
145
+
146
+ Returns the total amount of time spent in this method. */
147
+ static VALUE
148
+ prof_measurement_self_time(VALUE self)
149
+ {
150
+ prof_measurement_t* result = prof_get_measurement(self);
151
+
152
+ return rb_float_new(result->self_time);
153
+ }
154
+
155
+ /* call-seq:
156
+ wait_time -> float
157
+
158
+ Returns the total amount of time this method waited for other threads. */
159
+ static VALUE prof_measurement_wait_time(VALUE self)
160
+ {
161
+ prof_measurement_t* result = prof_get_measurement(self);
162
+
163
+ return rb_float_new(result->wait_time);
164
+ }
165
+
166
+ /* call-seq:
167
+ called -> int
168
+
169
+ Returns the total amount of times this method was called. */
170
+ static VALUE prof_measurement_called(VALUE self)
171
+ {
172
+ prof_measurement_t* result = prof_get_measurement(self);
173
+ return INT2NUM(result->called);
174
+ }
175
+
176
+ /* call-seq:
177
+ called=n -> n
178
+
179
+ Sets the call count to n. */
180
+ static VALUE prof_measurement_set_called(VALUE self, VALUE called)
181
+ {
182
+ prof_measurement_t* result = prof_get_measurement(self);
183
+ result->called = NUM2INT(called);
184
+ return called;
185
+ }
186
+
187
+ /* :nodoc: */
188
+ static VALUE
189
+ prof_measurement_dump(VALUE self)
190
+ {
191
+ prof_measurement_t* measurement_data = prof_get_measurement(self);
192
+ VALUE result = rb_hash_new();
193
+
194
+ rb_hash_aset(result, ID2SYM(rb_intern("total_time")), rb_float_new(measurement_data->total_time));
195
+ rb_hash_aset(result, ID2SYM(rb_intern("self_time")), rb_float_new(measurement_data->self_time));
196
+ rb_hash_aset(result, ID2SYM(rb_intern("wait_time")), rb_float_new(measurement_data->wait_time));
197
+ rb_hash_aset(result, ID2SYM(rb_intern("called")), INT2FIX(measurement_data->called));
198
+
199
+ return result;
200
+ }
201
+
202
+ /* :nodoc: */
203
+ static VALUE
204
+ prof_measurement_load(VALUE self, VALUE data)
205
+ {
206
+ prof_measurement_t* measurement = prof_get_measurement(self);
207
+ measurement->object = self;
208
+
209
+ measurement->total_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("total_time"))));
210
+ measurement->self_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("self_time"))));
211
+ measurement->wait_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("wait_time"))));
212
+ measurement->called = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("called"))));
213
+
214
+ return data;
215
+ }
216
+
217
+ void rp_init_measure()
218
+ {
219
+ mMeasure = rb_define_module_under(mProf, "Measure");
220
+ rp_init_measure_wall_time();
221
+ rp_init_measure_process_time();
222
+ rp_init_measure_allocations();
223
+ rp_init_measure_memory();
224
+
225
+ cRpMeasurement = rb_define_class_under(mProf, "Measurement", rb_cObject);
226
+ rb_undef_method(CLASS_OF(cRpMeasurement), "new");
227
+ rb_define_alloc_func(cRpMeasurement, prof_measurement_allocate);
228
+
229
+ rb_define_method(cRpMeasurement, "called", prof_measurement_called, 0);
230
+ rb_define_method(cRpMeasurement, "called=", prof_measurement_set_called, 1);
231
+ rb_define_method(cRpMeasurement, "total_time", prof_measurement_total_time, 0);
232
+ rb_define_method(cRpMeasurement, "self_time", prof_measurement_self_time, 0);
233
+ rb_define_method(cRpMeasurement, "wait_time", prof_measurement_wait_time, 0);
234
+
235
+ rb_define_method(cRpMeasurement, "_dump_data", prof_measurement_dump, 0);
236
+ rb_define_method(cRpMeasurement, "_load_data", prof_measurement_load, 1);
237
+ }
@@ -0,0 +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
+ #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
+ MEASURE_MEMORY
19
+ } prof_measure_mode_t;
20
+
21
+ typedef struct prof_measurer_t
22
+ {
23
+ get_measurement measure;
24
+ prof_measure_mode_t mode;
25
+ double multiplier;
26
+ bool track_allocations;
27
+ } prof_measurer_t;
28
+
29
+ /* Callers and callee information for a method. */
30
+ typedef struct prof_measurement_t
31
+ {
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
+ void prof_measurement_free(prof_measurement_t* measurement);
44
+ VALUE prof_measurement_wrap(prof_measurement_t* measurement);
45
+ prof_measurement_t* prof_get_measurement(VALUE self);
46
+ void prof_measurement_mark(void* data);
47
+
48
+ void rp_init_measure(void);
49
+
50
+ #endif //__rp_measurementMENT_H__