ruby-prof 1.0.0

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 (97) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +523 -0
  3. data/LICENSE +25 -0
  4. data/README.rdoc +5 -0
  5. data/Rakefile +110 -0
  6. data/bin/ruby-prof +380 -0
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +36 -0
  9. data/ext/ruby_prof/rp_allocation.c +292 -0
  10. data/ext/ruby_prof/rp_allocation.h +31 -0
  11. data/ext/ruby_prof/rp_call_info.c +283 -0
  12. data/ext/ruby_prof/rp_call_info.h +35 -0
  13. data/ext/ruby_prof/rp_measure_allocations.c +52 -0
  14. data/ext/ruby_prof/rp_measure_memory.c +42 -0
  15. data/ext/ruby_prof/rp_measure_process_time.c +63 -0
  16. data/ext/ruby_prof/rp_measure_wall_time.c +62 -0
  17. data/ext/ruby_prof/rp_measurement.c +236 -0
  18. data/ext/ruby_prof/rp_measurement.h +49 -0
  19. data/ext/ruby_prof/rp_method.c +642 -0
  20. data/ext/ruby_prof/rp_method.h +70 -0
  21. data/ext/ruby_prof/rp_profile.c +881 -0
  22. data/ext/ruby_prof/rp_profile.h +36 -0
  23. data/ext/ruby_prof/rp_stack.c +196 -0
  24. data/ext/ruby_prof/rp_stack.h +56 -0
  25. data/ext/ruby_prof/rp_thread.c +338 -0
  26. data/ext/ruby_prof/rp_thread.h +36 -0
  27. data/ext/ruby_prof/ruby_prof.c +48 -0
  28. data/ext/ruby_prof/ruby_prof.h +17 -0
  29. data/ext/ruby_prof/vc/ruby_prof.sln +31 -0
  30. data/ext/ruby_prof/vc/ruby_prof.vcxproj +143 -0
  31. data/lib/ruby-prof.rb +53 -0
  32. data/lib/ruby-prof/assets/call_stack_printer.css.html +117 -0
  33. data/lib/ruby-prof/assets/call_stack_printer.js.html +385 -0
  34. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  35. data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
  36. data/lib/ruby-prof/call_info.rb +57 -0
  37. data/lib/ruby-prof/call_info_visitor.rb +38 -0
  38. data/lib/ruby-prof/compatibility.rb +109 -0
  39. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  40. data/lib/ruby-prof/measurement.rb +14 -0
  41. data/lib/ruby-prof/method_info.rb +90 -0
  42. data/lib/ruby-prof/printers/abstract_printer.rb +118 -0
  43. data/lib/ruby-prof/printers/call_info_printer.rb +51 -0
  44. data/lib/ruby-prof/printers/call_stack_printer.rb +269 -0
  45. data/lib/ruby-prof/printers/call_tree_printer.rb +151 -0
  46. data/lib/ruby-prof/printers/dot_printer.rb +132 -0
  47. data/lib/ruby-prof/printers/flat_printer.rb +52 -0
  48. data/lib/ruby-prof/printers/graph_html_printer.rb +64 -0
  49. data/lib/ruby-prof/printers/graph_printer.rb +114 -0
  50. data/lib/ruby-prof/printers/multi_printer.rb +127 -0
  51. data/lib/ruby-prof/profile.rb +33 -0
  52. data/lib/ruby-prof/rack.rb +171 -0
  53. data/lib/ruby-prof/task.rb +147 -0
  54. data/lib/ruby-prof/thread.rb +35 -0
  55. data/lib/ruby-prof/version.rb +3 -0
  56. data/lib/unprof.rb +10 -0
  57. data/ruby-prof.gemspec +58 -0
  58. data/test/abstract_printer_test.rb +26 -0
  59. data/test/alias_test.rb +129 -0
  60. data/test/basic_test.rb +129 -0
  61. data/test/call_info_visitor_test.rb +31 -0
  62. data/test/duplicate_names_test.rb +32 -0
  63. data/test/dynamic_method_test.rb +53 -0
  64. data/test/enumerable_test.rb +21 -0
  65. data/test/exceptions_test.rb +24 -0
  66. data/test/exclude_methods_test.rb +146 -0
  67. data/test/exclude_threads_test.rb +53 -0
  68. data/test/line_number_test.rb +161 -0
  69. data/test/marshal_test.rb +119 -0
  70. data/test/measure_allocations.rb +30 -0
  71. data/test/measure_allocations_test.rb +385 -0
  72. data/test/measure_allocations_trace_test.rb +385 -0
  73. data/test/measure_memory_trace_test.rb +756 -0
  74. data/test/measure_process_time_test.rb +849 -0
  75. data/test/measure_times.rb +54 -0
  76. data/test/measure_wall_time_test.rb +459 -0
  77. data/test/multi_printer_test.rb +71 -0
  78. data/test/no_method_class_test.rb +15 -0
  79. data/test/parser_timings.rb +24 -0
  80. data/test/pause_resume_test.rb +166 -0
  81. data/test/prime.rb +56 -0
  82. data/test/printer_call_tree_test.rb +31 -0
  83. data/test/printer_flat_test.rb +68 -0
  84. data/test/printer_graph_html_test.rb +60 -0
  85. data/test/printer_graph_test.rb +41 -0
  86. data/test/printers_test.rb +141 -0
  87. data/test/printing_recursive_graph_test.rb +81 -0
  88. data/test/rack_test.rb +157 -0
  89. data/test/recursive_test.rb +210 -0
  90. data/test/singleton_test.rb +38 -0
  91. data/test/stack_printer_test.rb +64 -0
  92. data/test/start_stop_test.rb +109 -0
  93. data/test/test_helper.rb +24 -0
  94. data/test/thread_test.rb +144 -0
  95. data/test/unique_call_path_test.rb +190 -0
  96. data/test/yarv_test.rb +56 -0
  97. metadata +189 -0
@@ -0,0 +1,35 @@
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_CALL_INFO_H__
5
+ #define __RP_CALL_INFO_H__
6
+
7
+ #include "ruby_prof.h"
8
+ #include "rp_measurement.h"
9
+ #include "rp_method.h"
10
+
11
+ /* Callers and callee information for a method. */
12
+ typedef struct prof_call_info_t
13
+ {
14
+ prof_method_t *method;
15
+ prof_method_t *parent;
16
+ prof_measurement_t *measurement;
17
+ VALUE object;
18
+
19
+ int visits; /* Current visits on the stack */
20
+
21
+ unsigned int depth;
22
+ unsigned int source_line;
23
+ VALUE source_file;
24
+ } prof_call_info_t;
25
+
26
+ prof_call_info_t *prof_call_info_create(prof_method_t *method, prof_method_t *parent, VALUE source_file, int source_line);
27
+ void prof_call_info_mark(void *data);
28
+ prof_call_info_t *call_info_table_lookup(st_table* table, st_data_t key);
29
+ size_t call_info_table_insert(st_table *table, st_data_t key, prof_call_info_t *val);
30
+ prof_call_info_t *prof_get_call_info(VALUE self);
31
+ VALUE prof_call_info_wrap(prof_call_info_t* call_info);
32
+ void prof_call_info_free(prof_call_info_t* call_info);
33
+ void rp_init_call_info(void);
34
+
35
+ #endif //__RP_CALL_INFO_H__
@@ -0,0 +1,52 @@
1
+ /* Copyright (C) 2005-2013 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
+ /* :nodoc: */
5
+
6
+ #include "rp_measurement.h"
7
+
8
+ static VALUE cMeasureAllocations;
9
+ VALUE total_allocated_objects_key;
10
+
11
+ static double
12
+ measure_allocations_via_gc_stats(rb_trace_arg_t* trace_arg)
13
+ {
14
+ return rb_gc_stat(total_allocated_objects_key);
15
+ }
16
+
17
+ static double
18
+ measure_allocations_via_tracing(rb_trace_arg_t* trace_arg)
19
+ {
20
+ static double result = 0;
21
+
22
+ if (trace_arg)
23
+ {
24
+ rb_event_flag_t event = rb_tracearg_event_flag(trace_arg);
25
+ if (event == RUBY_INTERNAL_EVENT_NEWOBJ)
26
+ result++;
27
+ }
28
+ return result;
29
+ }
30
+
31
+ prof_measurer_t* prof_measurer_allocations(bool track_allocations)
32
+ {
33
+ prof_measurer_t* measure = ALLOC(prof_measurer_t);
34
+ measure->mode = MEASURE_ALLOCATIONS;
35
+ measure->multiplier = 1;
36
+ measure->track_allocations = track_allocations;
37
+
38
+ if (track_allocations)
39
+ measure->measure = measure_allocations_via_tracing;
40
+ else
41
+ measure->measure = measure_allocations_via_gc_stats;
42
+
43
+ return measure;
44
+ }
45
+
46
+ void rp_init_measure_allocations()
47
+ {
48
+ total_allocated_objects_key = ID2SYM(rb_intern("total_allocated_objects"));
49
+ rb_define_const(mProf, "ALLOCATIONS", INT2NUM(MEASURE_ALLOCATIONS));
50
+
51
+ cMeasureAllocations = rb_define_class_under(mMeasure, "Allocations", rb_cObject);
52
+ }
@@ -0,0 +1,42 @@
1
+ /* Copyright (C) 2005-2013 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
+ /* :nodoc: */
5
+
6
+ #include "rp_measurement.h"
7
+
8
+ static VALUE cMeasureMemory;
9
+
10
+ static double
11
+ measure_memory_via_tracing(rb_trace_arg_t* trace_arg)
12
+ {
13
+ static double result = 0;
14
+
15
+ if (trace_arg)
16
+ {
17
+ rb_event_flag_t event = rb_tracearg_event_flag(trace_arg);
18
+ if (event == RUBY_INTERNAL_EVENT_NEWOBJ)
19
+ {
20
+ VALUE object = rb_tracearg_object(trace_arg);
21
+ result += rb_obj_memsize_of(object);
22
+ }
23
+ }
24
+ return result;
25
+ }
26
+
27
+ prof_measurer_t* prof_measurer_memory(bool track_allocations)
28
+ {
29
+ prof_measurer_t* measure = ALLOC(prof_measurer_t);
30
+ measure->mode = MEASURE_MEMORY;
31
+ measure->measure = measure_memory_via_tracing;
32
+ measure->multiplier = 1;
33
+ measure->track_allocations = true;
34
+ return measure;
35
+ }
36
+
37
+ void rp_init_measure_memory()
38
+ {
39
+ rb_define_const(mProf, "MEMORY", INT2NUM(MEASURE_MEMORY));
40
+
41
+ cMeasureMemory = rb_define_class_under(mMeasure, "Allocations", rb_cObject);
42
+ }
@@ -0,0 +1,63 @@
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
+ #include <time.h>
6
+
7
+ static VALUE cMeasureProcessTime;
8
+
9
+ static double
10
+ measure_process_time(rb_trace_arg_t* trace_arg)
11
+ {
12
+ #if defined(_WIN32)
13
+ FILETIME createTime;
14
+ FILETIME exitTime;
15
+ FILETIME sysTime;
16
+ FILETIME userTime;
17
+
18
+ ULARGE_INTEGER sysTimeInt;
19
+ ULARGE_INTEGER userTimeInt;
20
+
21
+ GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &sysTime, &userTime);
22
+
23
+ sysTimeInt.LowPart = sysTime.dwLowDateTime;
24
+ sysTimeInt.HighPart = sysTime.dwHighDateTime;
25
+ userTimeInt.LowPart = userTime.dwLowDateTime;
26
+ userTimeInt.HighPart = userTime.dwHighDateTime;
27
+
28
+ return sysTimeInt.QuadPart + userTimeInt.QuadPart;
29
+ #else
30
+ struct timespec clock;
31
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID , &clock);
32
+ return clock.tv_sec + (clock.tv_nsec/1000000000.0);
33
+ #endif
34
+ }
35
+
36
+ static double
37
+ multiplier_process_time(void)
38
+ {
39
+ #if defined(_WIN32)
40
+ // Times are in 100-nanosecond time units. So instead of 10-9 use 10-7
41
+ return 1.0 / 10000000.0;
42
+ #else
43
+ return 1.0;
44
+ #endif
45
+ }
46
+
47
+ prof_measurer_t* prof_measurer_process_time(bool track_allocations)
48
+ {
49
+ prof_measurer_t* measure = ALLOC(prof_measurer_t);
50
+ measure->mode = MEASURE_PROCESS_TIME;
51
+ measure->measure = measure_process_time;
52
+ measure->multiplier = multiplier_process_time();
53
+ measure->track_allocations = track_allocations;
54
+ return measure;
55
+ }
56
+
57
+ void rp_init_measure_process_time()
58
+ {
59
+ rb_define_const(mProf, "CLOCKS_PER_SEC", INT2NUM(CLOCKS_PER_SEC));
60
+ rb_define_const(mProf, "PROCESS_TIME", INT2NUM(MEASURE_PROCESS_TIME));
61
+
62
+ cMeasureProcessTime = rb_define_class_under(mMeasure, "ProcessTime", rb_cObject);
63
+ }
@@ -0,0 +1,62 @@
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
+ /* :nodoc: */
5
+ #include "rp_measurement.h"
6
+
7
+ #if defined(__APPLE__)
8
+ #include <mach/mach_time.h>
9
+ #elif !defined(_WIN32)
10
+ #include <time.h>
11
+ #endif
12
+
13
+ static VALUE cMeasureWallTime;
14
+
15
+ static double
16
+ measure_wall_time(rb_trace_arg_t* trace_arg)
17
+ {
18
+ #if defined(_WIN32)
19
+ return GetTickCount();
20
+ #elif defined(__APPLE__)
21
+ return mach_absolute_time();// * (uint64_t)mach_timebase.numer / (uint64_t)mach_timebase.denom;
22
+ #elif defined(__linux__)
23
+ struct timespec tv;
24
+ clock_gettime(CLOCK_MONOTONIC, &tv);
25
+ return tv.tv_sec + (tv.tv_nsec / 1000000000.0);
26
+ #else
27
+ struct timeval tv;
28
+ gettimeofday(&tv, NULL);
29
+ return tv.tv_sec + (tv.tv_usec / 1000000.0);
30
+ #endif
31
+ }
32
+
33
+ static double
34
+ multiplier_wall_time(void)
35
+ {
36
+ #if defined(_WIN32)
37
+ return 1.0/1000.0;
38
+ #elif defined(__APPLE__)
39
+ mach_timebase_info_data_t mach_timebase;
40
+ mach_timebase_info (&mach_timebase);
41
+ return (uint64_t)mach_timebase.numer / (uint64_t)mach_timebase.denom / 1000000000.0;
42
+ #else
43
+ return 1.0;
44
+ #endif
45
+ }
46
+
47
+ prof_measurer_t* prof_measurer_wall_time(bool track_allocations)
48
+ {
49
+ prof_measurer_t* measure = ALLOC(prof_measurer_t);
50
+ measure->mode = MEASURE_WALL_TIME;
51
+ measure->measure = measure_wall_time;
52
+ measure->multiplier = multiplier_wall_time();
53
+ measure->track_allocations = track_allocations;
54
+ return measure;
55
+ }
56
+
57
+ void rp_init_measure_wall_time()
58
+ {
59
+ rb_define_const(mProf, "WALL_TIME", INT2NUM(MEASURE_WALL_TIME));
60
+
61
+ cMeasureWallTime = rb_define_class_under(mMeasure, "WallTime", rb_cObject);
62
+ }
@@ -0,0 +1,236 @@
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_get_measurer(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
+ static void
55
+ prof_measurement_ruby_gc_free(void *data)
56
+ {
57
+ prof_measurement_t* measurement = (prof_measurement_t*)data;
58
+
59
+ /* Has this thread object been accessed by Ruby? If
60
+ yes clean it up so to avoid a segmentation fault. */
61
+ if (measurement->object != Qnil)
62
+ {
63
+ RDATA(measurement->object)->data = NULL;
64
+ RDATA(measurement->object)->dfree = NULL;
65
+ RDATA(measurement->object)->dmark = NULL;
66
+ }
67
+ measurement->object = Qnil;
68
+ }
69
+
70
+ size_t
71
+ prof_measurement_size(const void *data)
72
+ {
73
+ return sizeof(prof_measurement_t);
74
+ }
75
+
76
+ void
77
+ prof_measurement_mark(void *data)
78
+ {
79
+ prof_measurement_t* measurement = (prof_measurement_t*)data;
80
+ if (measurement->object != Qnil)
81
+ rb_gc_mark(measurement->object);
82
+ }
83
+
84
+ static const rb_data_type_t measurement_type =
85
+ {
86
+ .wrap_struct_name = "Measurement",
87
+ .function =
88
+ {
89
+ .dmark = prof_measurement_mark,
90
+ .dfree = prof_measurement_ruby_gc_free,
91
+ .dsize = prof_measurement_size,
92
+ },
93
+ .data = NULL,
94
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
95
+ };
96
+
97
+ VALUE
98
+ prof_measurement_wrap(prof_measurement_t* measurement)
99
+ {
100
+ if (measurement->object == Qnil)
101
+ {
102
+ measurement->object = TypedData_Wrap_Struct(cRpMeasurement, &measurement_type, measurement);
103
+ }
104
+ return measurement->object;
105
+ }
106
+
107
+ static VALUE
108
+ prof_measurement_allocate(VALUE klass)
109
+ {
110
+ prof_measurement_t *measurement = prof_measurement_create();
111
+ measurement->object = prof_measurement_wrap(measurement);
112
+ return measurement->object;
113
+ }
114
+
115
+ prof_measurement_t*
116
+ prof_get_measurement(VALUE self)
117
+ {
118
+ /* Can't use Data_Get_Struct because that triggers the event hook
119
+ ending up in endless recursion. */
120
+ prof_measurement_t* result = DATA_PTR(self);
121
+
122
+ if (!result)
123
+ rb_raise(rb_eRuntimeError, "This RubyProf::Measurement instance has already been freed, likely because its profile has been freed.");
124
+
125
+ return result;
126
+ }
127
+
128
+ /* call-seq:
129
+ total_time -> float
130
+
131
+ Returns the total amount of time spent in this method and its children. */
132
+ static VALUE
133
+ prof_measurement_total_time(VALUE self)
134
+ {
135
+ prof_measurement_t* result = prof_get_measurement(self);
136
+ return rb_float_new(result->total_time);
137
+ }
138
+
139
+ /* call-seq:
140
+ self_time -> float
141
+
142
+ Returns the total amount of time spent in this method. */
143
+ static VALUE
144
+ prof_measurement_self_time(VALUE self)
145
+ {
146
+ prof_measurement_t* result = prof_get_measurement(self);
147
+
148
+ return rb_float_new(result->self_time);
149
+ }
150
+
151
+ /* call-seq:
152
+ wait_time -> float
153
+
154
+ Returns the total amount of time this method waited for other threads. */
155
+ static VALUE
156
+ prof_measurement_wait_time(VALUE self)
157
+ {
158
+ prof_measurement_t* result = prof_get_measurement(self);
159
+
160
+ return rb_float_new(result->wait_time);
161
+ }
162
+
163
+ /* call-seq:
164
+ called -> int
165
+
166
+ Returns the total amount of times this method was called. */
167
+ static VALUE
168
+ prof_measurement_called(VALUE self)
169
+ {
170
+ prof_measurement_t *result = prof_get_measurement(self);
171
+ return INT2NUM(result->called);
172
+ }
173
+
174
+ /* call-seq:
175
+ called=n -> n
176
+
177
+ Sets the call count to n. */
178
+ static VALUE
179
+ prof_measurement_set_called(VALUE self, VALUE called)
180
+ {
181
+ prof_measurement_t *result = prof_get_measurement(self);
182
+ result->called = NUM2INT(called);
183
+ return called;
184
+ }
185
+
186
+ /* :nodoc: */
187
+ static VALUE
188
+ prof_measurement_dump(VALUE self)
189
+ {
190
+ prof_measurement_t* measurement_data = prof_get_measurement(self);
191
+ VALUE result = rb_hash_new();
192
+
193
+ rb_hash_aset(result, ID2SYM(rb_intern("total_time")), rb_float_new(measurement_data->total_time));
194
+ rb_hash_aset(result, ID2SYM(rb_intern("self_time")), rb_float_new(measurement_data->self_time));
195
+ rb_hash_aset(result, ID2SYM(rb_intern("wait_time")), rb_float_new(measurement_data->wait_time));
196
+ rb_hash_aset(result, ID2SYM(rb_intern("called")), INT2FIX(measurement_data->called));
197
+
198
+ return result;
199
+ }
200
+
201
+ /* :nodoc: */
202
+ static VALUE
203
+ prof_measurement_load(VALUE self, VALUE data)
204
+ {
205
+ prof_measurement_t* measurement = prof_get_measurement(self);
206
+ measurement->object = self;
207
+
208
+ measurement->total_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("total_time"))));
209
+ measurement->self_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("self_time"))));
210
+ measurement->wait_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("wait_time"))));
211
+ measurement->called = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("called"))));
212
+
213
+ return data;
214
+ }
215
+
216
+ void rp_init_measure()
217
+ {
218
+ mMeasure = rb_define_module_under(mProf, "Measure");
219
+ rp_init_measure_wall_time();
220
+ rp_init_measure_process_time();
221
+ rp_init_measure_allocations();
222
+ rp_init_measure_memory();
223
+
224
+ cRpMeasurement = rb_define_class_under(mProf, "Measurement", rb_cData);
225
+ rb_undef_method(CLASS_OF(cRpMeasurement), "new");
226
+ rb_define_alloc_func(cRpMeasurement, prof_measurement_allocate);
227
+
228
+ rb_define_method(cRpMeasurement, "called", prof_measurement_called, 0);
229
+ rb_define_method(cRpMeasurement, "called=", prof_measurement_set_called, 1);
230
+ rb_define_method(cRpMeasurement, "total_time", prof_measurement_total_time, 0);
231
+ rb_define_method(cRpMeasurement, "self_time", prof_measurement_self_time, 0);
232
+ rb_define_method(cRpMeasurement, "wait_time", prof_measurement_wait_time, 0);
233
+
234
+ rb_define_method(cRpMeasurement, "_dump_data", prof_measurement_dump, 0);
235
+ rb_define_method(cRpMeasurement, "_load_data", prof_measurement_load, 1);
236
+ }