ruby-prof 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +532 -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 +279 -0
  10. data/ext/ruby_prof/rp_allocation.h +31 -0
  11. data/ext/ruby_prof/rp_call_info.c +271 -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 +67 -0
  16. data/ext/ruby_prof/rp_measure_wall_time.c +62 -0
  17. data/ext/ruby_prof/rp_measurement.c +230 -0
  18. data/ext/ruby_prof/rp_measurement.h +50 -0
  19. data/ext/ruby_prof/rp_method.c +630 -0
  20. data/ext/ruby_prof/rp_method.h +70 -0
  21. data/ext/ruby_prof/rp_profile.c +895 -0
  22. data/ext/ruby_prof/rp_profile.h +37 -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 +337 -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 +52 -0
  32. data/lib/ruby-prof/assets/call_stack_printer.html.erb +713 -0
  33. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  34. data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
  35. data/lib/ruby-prof/call_info.rb +57 -0
  36. data/lib/ruby-prof/call_info_visitor.rb +38 -0
  37. data/lib/ruby-prof/compatibility.rb +109 -0
  38. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  39. data/lib/ruby-prof/measurement.rb +14 -0
  40. data/lib/ruby-prof/method_info.rb +90 -0
  41. data/lib/ruby-prof/printers/abstract_printer.rb +127 -0
  42. data/lib/ruby-prof/printers/call_info_printer.rb +51 -0
  43. data/lib/ruby-prof/printers/call_stack_printer.rb +182 -0
  44. data/lib/ruby-prof/printers/call_tree_printer.rb +151 -0
  45. data/lib/ruby-prof/printers/dot_printer.rb +132 -0
  46. data/lib/ruby-prof/printers/flat_printer.rb +52 -0
  47. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -0
  48. data/lib/ruby-prof/printers/graph_printer.rb +114 -0
  49. data/lib/ruby-prof/printers/multi_printer.rb +127 -0
  50. data/lib/ruby-prof/profile.rb +33 -0
  51. data/lib/ruby-prof/rack.rb +171 -0
  52. data/lib/ruby-prof/task.rb +147 -0
  53. data/lib/ruby-prof/thread.rb +35 -0
  54. data/lib/ruby-prof/version.rb +3 -0
  55. data/lib/unprof.rb +10 -0
  56. data/ruby-prof.gemspec +58 -0
  57. data/test/abstract_printer_test.rb +26 -0
  58. data/test/alias_test.rb +129 -0
  59. data/test/basic_test.rb +129 -0
  60. data/test/call_info_visitor_test.rb +31 -0
  61. data/test/duplicate_names_test.rb +32 -0
  62. data/test/dynamic_method_test.rb +53 -0
  63. data/test/enumerable_test.rb +21 -0
  64. data/test/exceptions_test.rb +24 -0
  65. data/test/exclude_methods_test.rb +146 -0
  66. data/test/exclude_threads_test.rb +53 -0
  67. data/test/fiber_test.rb +73 -0
  68. data/test/gc_test.rb +96 -0
  69. data/test/line_number_test.rb +161 -0
  70. data/test/marshal_test.rb +119 -0
  71. data/test/measure_allocations.rb +30 -0
  72. data/test/measure_allocations_test.rb +385 -0
  73. data/test/measure_allocations_trace_test.rb +385 -0
  74. data/test/measure_memory_trace_test.rb +756 -0
  75. data/test/measure_process_time_test.rb +849 -0
  76. data/test/measure_times.rb +54 -0
  77. data/test/measure_wall_time_test.rb +459 -0
  78. data/test/multi_printer_test.rb +71 -0
  79. data/test/no_method_class_test.rb +15 -0
  80. data/test/parser_timings.rb +24 -0
  81. data/test/pause_resume_test.rb +166 -0
  82. data/test/prime.rb +56 -0
  83. data/test/printer_call_stack_test.rb +28 -0
  84. data/test/printer_call_tree_test.rb +31 -0
  85. data/test/printer_flat_test.rb +68 -0
  86. data/test/printer_graph_html_test.rb +60 -0
  87. data/test/printer_graph_test.rb +41 -0
  88. data/test/printers_test.rb +141 -0
  89. data/test/printing_recursive_graph_test.rb +81 -0
  90. data/test/rack_test.rb +157 -0
  91. data/test/recursive_test.rb +210 -0
  92. data/test/singleton_test.rb +38 -0
  93. data/test/stack_printer_test.rb +64 -0
  94. data/test/start_stop_test.rb +109 -0
  95. data/test/test_helper.rb +24 -0
  96. data/test/thread_test.rb +144 -0
  97. data/test/unique_call_path_test.rb +190 -0
  98. data/test/yarv_test.rb +56 -0
  99. metadata +191 -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,67 @@
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
+ #elif !defined(CLOCK_PROCESS_CPUTIME_ID)
30
+ struct rusage usage;
31
+ getrusage(RUSAGE_SELF, &usage);
32
+ return usage.ru_stime.tv_sec + usage.ru_utime.tv_sec + ((usage.ru_stime.tv_usec + usage.ru_utime.tv_usec)/1000000.0);
33
+ #else
34
+ struct timespec clock;
35
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID , &clock);
36
+ return clock.tv_sec + (clock.tv_nsec/1000000000.0);
37
+ #endif
38
+ }
39
+
40
+ static double
41
+ multiplier_process_time(void)
42
+ {
43
+ #if defined(_WIN32)
44
+ // Times are in 100-nanosecond time units. So instead of 10-9 use 10-7
45
+ return 1.0 / 10000000.0;
46
+ #else
47
+ return 1.0;
48
+ #endif
49
+ }
50
+
51
+ prof_measurer_t* prof_measurer_process_time(bool track_allocations)
52
+ {
53
+ prof_measurer_t* measure = ALLOC(prof_measurer_t);
54
+ measure->mode = MEASURE_PROCESS_TIME;
55
+ measure->measure = measure_process_time;
56
+ measure->multiplier = multiplier_process_time();
57
+ measure->track_allocations = track_allocations;
58
+ return measure;
59
+ }
60
+
61
+ void rp_init_measure_process_time()
62
+ {
63
+ rb_define_const(mProf, "CLOCKS_PER_SEC", INT2NUM(CLOCKS_PER_SEC));
64
+ rb_define_const(mProf, "PROCESS_TIME", INT2NUM(MEASURE_PROCESS_TIME));
65
+
66
+ cMeasureProcessTime = rb_define_class_under(mMeasure, "ProcessTime", rb_cObject);
67
+ }
@@ -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,230 @@
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 measurement 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)->dmark = NULL;
64
+ RDATA(measurement->object)->dfree = NULL;
65
+ RDATA(measurement->object)->data = NULL;
66
+ measurement->object = Qnil;
67
+ }
68
+ }
69
+
70
+ void
71
+ prof_measurement_free(prof_measurement_t* measurement)
72
+ {
73
+ prof_measurement_ruby_gc_free(measurement);
74
+ xfree(measurement);
75
+ }
76
+
77
+ size_t
78
+ prof_measurement_size(const void *data)
79
+ {
80
+ return sizeof(prof_measurement_t);
81
+ }
82
+
83
+ void
84
+ prof_measurement_mark(void *data)
85
+ {
86
+ prof_measurement_t* measurement = (prof_measurement_t*)data;
87
+ if (measurement->object != Qnil)
88
+ rb_gc_mark(measurement->object);
89
+ }
90
+
91
+ VALUE
92
+ prof_measurement_wrap(prof_measurement_t* measurement)
93
+ {
94
+ if (measurement->object == Qnil)
95
+ {
96
+ measurement->object = Data_Wrap_Struct(cRpMeasurement, prof_measurement_mark, prof_measurement_ruby_gc_free, measurement);
97
+ }
98
+ return measurement->object;
99
+ }
100
+
101
+ static VALUE
102
+ prof_measurement_allocate(VALUE klass)
103
+ {
104
+ prof_measurement_t *measurement = prof_measurement_create();
105
+ measurement->object = prof_measurement_wrap(measurement);
106
+ return measurement->object;
107
+ }
108
+
109
+ prof_measurement_t*
110
+ prof_get_measurement(VALUE self)
111
+ {
112
+ /* Can't use Data_Get_Struct because that triggers the event hook
113
+ ending up in endless recursion. */
114
+ prof_measurement_t* result = DATA_PTR(self);
115
+
116
+ if (!result)
117
+ rb_raise(rb_eRuntimeError, "This RubyProf::Measurement instance has already been freed, likely because its profile has been freed.");
118
+
119
+ return result;
120
+ }
121
+
122
+ /* call-seq:
123
+ total_time -> float
124
+
125
+ Returns the total amount of time spent in this method and its children. */
126
+ static VALUE
127
+ prof_measurement_total_time(VALUE self)
128
+ {
129
+ prof_measurement_t* result = prof_get_measurement(self);
130
+ return rb_float_new(result->total_time);
131
+ }
132
+
133
+ /* call-seq:
134
+ self_time -> float
135
+
136
+ Returns the total amount of time spent in this method. */
137
+ static VALUE
138
+ prof_measurement_self_time(VALUE self)
139
+ {
140
+ prof_measurement_t* result = prof_get_measurement(self);
141
+
142
+ return rb_float_new(result->self_time);
143
+ }
144
+
145
+ /* call-seq:
146
+ wait_time -> float
147
+
148
+ Returns the total amount of time this method waited for other threads. */
149
+ static VALUE
150
+ prof_measurement_wait_time(VALUE self)
151
+ {
152
+ prof_measurement_t* result = prof_get_measurement(self);
153
+
154
+ return rb_float_new(result->wait_time);
155
+ }
156
+
157
+ /* call-seq:
158
+ called -> int
159
+
160
+ Returns the total amount of times this method was called. */
161
+ static VALUE
162
+ prof_measurement_called(VALUE self)
163
+ {
164
+ prof_measurement_t *result = prof_get_measurement(self);
165
+ return INT2NUM(result->called);
166
+ }
167
+
168
+ /* call-seq:
169
+ called=n -> n
170
+
171
+ Sets the call count to n. */
172
+ static VALUE
173
+ prof_measurement_set_called(VALUE self, VALUE called)
174
+ {
175
+ prof_measurement_t *result = prof_get_measurement(self);
176
+ result->called = NUM2INT(called);
177
+ return called;
178
+ }
179
+
180
+ /* :nodoc: */
181
+ static VALUE
182
+ prof_measurement_dump(VALUE self)
183
+ {
184
+ prof_measurement_t* measurement_data = prof_get_measurement(self);
185
+ VALUE result = rb_hash_new();
186
+
187
+ rb_hash_aset(result, ID2SYM(rb_intern("total_time")), rb_float_new(measurement_data->total_time));
188
+ rb_hash_aset(result, ID2SYM(rb_intern("self_time")), rb_float_new(measurement_data->self_time));
189
+ rb_hash_aset(result, ID2SYM(rb_intern("wait_time")), rb_float_new(measurement_data->wait_time));
190
+ rb_hash_aset(result, ID2SYM(rb_intern("called")), INT2FIX(measurement_data->called));
191
+
192
+ return result;
193
+ }
194
+
195
+ /* :nodoc: */
196
+ static VALUE
197
+ prof_measurement_load(VALUE self, VALUE data)
198
+ {
199
+ prof_measurement_t* measurement = prof_get_measurement(self);
200
+ measurement->object = self;
201
+
202
+ measurement->total_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("total_time"))));
203
+ measurement->self_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("self_time"))));
204
+ measurement->wait_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("wait_time"))));
205
+ measurement->called = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("called"))));
206
+
207
+ return data;
208
+ }
209
+
210
+ void rp_init_measure()
211
+ {
212
+ mMeasure = rb_define_module_under(mProf, "Measure");
213
+ rp_init_measure_wall_time();
214
+ rp_init_measure_process_time();
215
+ rp_init_measure_allocations();
216
+ rp_init_measure_memory();
217
+
218
+ cRpMeasurement = rb_define_class_under(mProf, "Measurement", rb_cData);
219
+ rb_undef_method(CLASS_OF(cRpMeasurement), "new");
220
+ rb_define_alloc_func(cRpMeasurement, prof_measurement_allocate);
221
+
222
+ rb_define_method(cRpMeasurement, "called", prof_measurement_called, 0);
223
+ rb_define_method(cRpMeasurement, "called=", prof_measurement_set_called, 1);
224
+ rb_define_method(cRpMeasurement, "total_time", prof_measurement_total_time, 0);
225
+ rb_define_method(cRpMeasurement, "self_time", prof_measurement_self_time, 0);
226
+ rb_define_method(cRpMeasurement, "wait_time", prof_measurement_wait_time, 0);
227
+
228
+ rb_define_method(cRpMeasurement, "_dump_data", prof_measurement_dump, 0);
229
+ rb_define_method(cRpMeasurement, "_load_data", prof_measurement_load, 1);
230
+ }