ruby-prof 0.18.0 → 1.2.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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +44 -1
  3. data/LICENSE +2 -2
  4. data/README.rdoc +1 -483
  5. data/Rakefile +3 -6
  6. data/bin/ruby-prof +111 -128
  7. data/ext/ruby_prof/extconf.rb +6 -38
  8. data/ext/ruby_prof/rp_aggregate_call_tree.c +41 -0
  9. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  10. data/ext/ruby_prof/rp_allocation.c +259 -0
  11. data/ext/ruby_prof/rp_allocation.h +31 -0
  12. data/ext/ruby_prof/rp_call_tree.c +353 -0
  13. data/ext/ruby_prof/rp_call_tree.h +43 -0
  14. data/ext/ruby_prof/rp_call_trees.c +266 -0
  15. data/ext/ruby_prof/rp_call_trees.h +29 -0
  16. data/ext/ruby_prof/rp_measure_allocations.c +25 -51
  17. data/ext/ruby_prof/rp_measure_memory.c +21 -56
  18. data/ext/ruby_prof/rp_measure_process_time.c +37 -43
  19. data/ext/ruby_prof/rp_measure_wall_time.c +40 -21
  20. data/ext/ruby_prof/rp_measurement.c +221 -0
  21. data/ext/ruby_prof/rp_measurement.h +50 -0
  22. data/ext/ruby_prof/rp_method.c +279 -439
  23. data/ext/ruby_prof/rp_method.h +33 -45
  24. data/ext/ruby_prof/rp_profile.c +902 -0
  25. data/ext/ruby_prof/rp_profile.h +36 -0
  26. data/ext/ruby_prof/rp_stack.c +163 -132
  27. data/ext/ruby_prof/rp_stack.h +18 -28
  28. data/ext/ruby_prof/rp_thread.c +192 -124
  29. data/ext/ruby_prof/rp_thread.h +18 -8
  30. data/ext/ruby_prof/ruby_prof.c +36 -778
  31. data/ext/ruby_prof/ruby_prof.h +11 -45
  32. data/ext/ruby_prof/vc/ruby_prof.vcxproj +18 -12
  33. data/lib/ruby-prof.rb +4 -21
  34. data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
  35. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  36. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  37. data/lib/ruby-prof/call_tree.rb +57 -0
  38. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  39. data/lib/ruby-prof/compatibility.rb +37 -107
  40. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  41. data/lib/ruby-prof/measurement.rb +17 -0
  42. data/lib/ruby-prof/method_info.rb +47 -90
  43. data/lib/ruby-prof/printers/abstract_printer.rb +73 -50
  44. data/lib/ruby-prof/printers/call_info_printer.rb +24 -12
  45. data/lib/ruby-prof/printers/call_stack_printer.rb +66 -152
  46. data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
  47. data/lib/ruby-prof/printers/dot_printer.rb +5 -5
  48. data/lib/ruby-prof/printers/flat_printer.rb +6 -24
  49. data/lib/ruby-prof/printers/graph_html_printer.rb +6 -192
  50. data/lib/ruby-prof/printers/graph_printer.rb +11 -14
  51. data/lib/ruby-prof/printers/multi_printer.rb +66 -23
  52. data/lib/ruby-prof/profile.rb +10 -3
  53. data/lib/ruby-prof/thread.rb +5 -20
  54. data/lib/ruby-prof/version.rb +1 -1
  55. data/ruby-prof.gemspec +9 -2
  56. data/test/abstract_printer_test.rb +0 -27
  57. data/test/alias_test.rb +126 -0
  58. data/test/basic_test.rb +1 -86
  59. data/test/call_tree_visitor_test.rb +32 -0
  60. data/test/call_trees_test.rb +66 -0
  61. data/test/dynamic_method_test.rb +0 -2
  62. data/test/exclude_methods_test.rb +17 -12
  63. data/test/fiber_test.rb +214 -23
  64. data/test/gc_test.rb +105 -0
  65. data/test/inverse_call_tree_test.rb +175 -0
  66. data/test/line_number_test.rb +118 -40
  67. data/test/marshal_test.rb +115 -0
  68. data/test/measure_allocations.rb +30 -0
  69. data/test/measure_allocations_test.rb +361 -12
  70. data/test/measure_allocations_trace_test.rb +375 -0
  71. data/test/measure_memory_trace_test.rb +1101 -0
  72. data/test/measure_process_time_test.rb +757 -33
  73. data/test/measure_times.rb +56 -0
  74. data/test/measure_wall_time_test.rb +329 -149
  75. data/test/multi_printer_test.rb +1 -34
  76. data/test/pause_resume_test.rb +24 -15
  77. data/test/prime.rb +1 -1
  78. data/test/prime_script.rb +6 -0
  79. data/test/printer_call_stack_test.rb +28 -0
  80. data/test/printer_call_tree_test.rb +31 -0
  81. data/test/printer_flat_test.rb +68 -0
  82. data/test/printer_graph_html_test.rb +60 -0
  83. data/test/printer_graph_test.rb +41 -0
  84. data/test/printers_test.rb +32 -166
  85. data/test/printing_recursive_graph_test.rb +26 -72
  86. data/test/recursive_test.rb +68 -77
  87. data/test/stack_printer_test.rb +2 -15
  88. data/test/start_stop_test.rb +22 -25
  89. data/test/test_helper.rb +6 -261
  90. data/test/thread_test.rb +11 -54
  91. data/test/unique_call_path_test.rb +25 -107
  92. data/test/yarv_test.rb +1 -0
  93. metadata +43 -41
  94. data/examples/flat.txt +0 -50
  95. data/examples/graph.dot +0 -84
  96. data/examples/graph.html +0 -823
  97. data/examples/graph.txt +0 -139
  98. data/examples/multi.flat.txt +0 -23
  99. data/examples/multi.graph.html +0 -760
  100. data/examples/multi.grind.dat +0 -114
  101. data/examples/multi.stack.html +0 -547
  102. data/examples/stack.html +0 -547
  103. data/ext/ruby_prof/rp_call_info.c +0 -425
  104. data/ext/ruby_prof/rp_call_info.h +0 -53
  105. data/ext/ruby_prof/rp_measure.c +0 -40
  106. data/ext/ruby_prof/rp_measure.h +0 -45
  107. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  108. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  109. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  110. data/lib/ruby-prof/aggregate_call_info.rb +0 -76
  111. data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
  112. data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
  113. data/lib/ruby-prof/call_info.rb +0 -115
  114. data/lib/ruby-prof/call_info_visitor.rb +0 -40
  115. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
  116. data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
  117. data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
  118. data/test/aggregate_test.rb +0 -136
  119. data/test/block_test.rb +0 -74
  120. data/test/call_info_test.rb +0 -78
  121. data/test/call_info_visitor_test.rb +0 -31
  122. data/test/issue137_test.rb +0 -63
  123. data/test/measure_cpu_time_test.rb +0 -212
  124. data/test/measure_gc_runs_test.rb +0 -32
  125. data/test/measure_gc_time_test.rb +0 -36
  126. data/test/measure_memory_test.rb +0 -33
  127. data/test/method_elimination_test.rb +0 -84
  128. data/test/module_test.rb +0 -45
  129. data/test/stack_test.rb +0 -138
@@ -1,71 +1,65 @@
1
- /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2019 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
- #include "ruby_prof.h"
4
+ #include "rp_measurement.h"
5
5
  #include <time.h>
6
6
 
7
7
  static VALUE cMeasureProcessTime;
8
8
 
9
- static double
10
- measure_process_time()
9
+ static double measure_process_time(rb_trace_arg_t* trace_arg)
11
10
  {
12
- #if defined(__linux__)
13
- struct timespec clock;
14
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID , &clock);
15
- return clock.tv_sec + (clock.tv_nsec/1000000000.0);
16
- #elif defined(_win32)
17
- FILETIME createTime;
18
- FILETIME exitTime;
19
- FILETIME sysTime;
20
- FILETIME cpuTime;
21
-
22
- ULARGE_INTEGER sysTimeInt;
23
- ULARGE_INTEGER cpuTimeInt;
24
- ULONGLONG totalTime;
11
+ #if defined(_WIN32)
12
+ FILETIME createTime;
13
+ FILETIME exitTime;
14
+ FILETIME sysTime;
15
+ FILETIME userTime;
25
16
 
26
- GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &sysTime, &cpuTime);
17
+ ULARGE_INTEGER sysTimeInt;
18
+ ULARGE_INTEGER userTimeInt;
27
19
 
28
- /* Doing this based on MSFT's recommendation in the FILETIME structure documentation at
29
- http://msdn.microsoft.com/en-us/library/ms724284%28VS.85%29.aspx*/
20
+ GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &sysTime, &userTime);
30
21
 
31
- sysTimeInt.LowPart = sysTime.dwLowDateTime;
32
- sysTimeInt.HighPart = sysTime.dwHighDateTime;
33
- cpuTimeInt.LowPart = cpuTime.dwLowDateTime;
34
- cpuTimeInt.HighPart = cpuTime.dwHighDateTime;
22
+ sysTimeInt.LowPart = sysTime.dwLowDateTime;
23
+ sysTimeInt.HighPart = sysTime.dwHighDateTime;
24
+ userTimeInt.LowPart = userTime.dwLowDateTime;
25
+ userTimeInt.HighPart = userTime.dwHighDateTime;
35
26
 
36
- totalTime = sysTimeInt.QuadPart + cpuTimeInt.QuadPart;
37
-
38
- // Times are in 100-nanosecond time units. So instead of 10-9 use 10-7
39
- return totalTime / 10000000.0;
27
+ return sysTimeInt.QuadPart + userTimeInt.QuadPart;
28
+ #elif !defined(CLOCK_PROCESS_CPUTIME_ID)
29
+ struct rusage usage;
30
+ getrusage(RUSAGE_SELF, &usage);
31
+ return usage.ru_stime.tv_sec + usage.ru_utime.tv_sec + ((usage.ru_stime.tv_usec + usage.ru_utime.tv_usec) / 1000000.0);
40
32
  #else
41
- return ((double)clock()) / CLOCKS_PER_SEC;
33
+ struct timespec clock;
34
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &clock);
35
+ return clock.tv_sec + (clock.tv_nsec / 1000000000.0);
42
36
  #endif
43
37
  }
44
38
 
45
- /* call-seq:
46
- measure_process_time -> float
47
-
48
- Returns the process time.*/
49
- static VALUE
50
- prof_measure_process_time(VALUE self)
39
+ static double multiplier_process_time(void)
51
40
  {
52
- return rb_float_new(measure_process_time());
41
+ #if defined(_WIN32)
42
+ // Times are in 100-nanosecond time units. So instead of 10-9 use 10-7
43
+ return 1.0 / 10000000.0;
44
+ #else
45
+ return 1.0;
46
+ #endif
53
47
  }
54
48
 
55
- prof_measurer_t* prof_measurer_process_time()
49
+ prof_measurer_t* prof_measurer_process_time(bool track_allocations)
56
50
  {
57
- prof_measurer_t* measure = ALLOC(prof_measurer_t);
58
- measure->measure = measure_process_time;
59
- return measure;
51
+ prof_measurer_t* measure = ALLOC(prof_measurer_t);
52
+ measure->mode = MEASURE_PROCESS_TIME;
53
+ measure->measure = measure_process_time;
54
+ measure->multiplier = multiplier_process_time();
55
+ measure->track_allocations = track_allocations;
56
+ return measure;
60
57
  }
61
58
 
62
-
63
59
  void rp_init_measure_process_time()
64
60
  {
65
61
  rb_define_const(mProf, "CLOCKS_PER_SEC", INT2NUM(CLOCKS_PER_SEC));
66
62
  rb_define_const(mProf, "PROCESS_TIME", INT2NUM(MEASURE_PROCESS_TIME));
67
- rb_define_const(mProf, "PROCESS_TIME_ENABLED", Qtrue);
68
63
 
69
64
  cMeasureProcessTime = rb_define_class_under(mMeasure, "ProcessTime", rb_cObject);
70
- rb_define_singleton_method(cMeasureProcessTime, "measure", prof_measure_process_time, 0);
71
65
  }
@@ -1,45 +1,64 @@
1
1
  /* Copyright (C) 2005-2019 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
- /* :nodoc: */
5
- #include "ruby_prof.h"
6
- #if HAVE_GETTIMEOFDAY && !defined(_WIN32)
7
- #include <sys/time.h>
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>
8
11
  #endif
9
12
 
10
13
  static VALUE cMeasureWallTime;
11
14
 
12
- static double
13
- measure_wall_time()
15
+ static double measure_wall_time(rb_trace_arg_t* trace_arg)
14
16
  {
17
+ #if defined(_WIN32)
18
+ LARGE_INTEGER time;
19
+ QueryPerformanceCounter(&time);
20
+ return time.QuadPart;
21
+ #elif defined(__APPLE__)
22
+ return mach_absolute_time();// * (uint64_t)mach_timebase.numer / (uint64_t)mach_timebase.denom;
23
+ #elif defined(__linux__)
24
+ struct timespec tv;
25
+ clock_gettime(CLOCK_MONOTONIC, &tv);
26
+ return tv.tv_sec + (tv.tv_nsec / 1000000000.0);
27
+ #else
15
28
  struct timeval tv;
16
29
  gettimeofday(&tv, NULL);
17
- return tv.tv_sec + (tv.tv_usec/1000000.0);
30
+ return tv.tv_sec + (tv.tv_usec / 1000000.0);
31
+ #endif
18
32
  }
19
33
 
20
- prof_measurer_t* prof_measurer_wall_time()
34
+ static double multiplier_wall_time(void)
21
35
  {
22
- prof_measurer_t* measure = ALLOC(prof_measurer_t);
23
- measure->measure = measure_wall_time;
24
- return measure;
36
+ #if defined(_WIN32)
37
+ LARGE_INTEGER frequency;
38
+ QueryPerformanceFrequency(&frequency);
39
+ return 1.0 / frequency.QuadPart;
40
+ #elif defined(__APPLE__)
41
+ mach_timebase_info_data_t mach_timebase;
42
+ mach_timebase_info(&mach_timebase);
43
+ return (uint64_t)mach_timebase.numer / (uint64_t)mach_timebase.denom / 1000000000.0;
44
+ #else
45
+ return 1.0;
46
+ #endif
25
47
  }
26
48
 
27
- /* Document-method: prof_measure_wall_time
28
- call-seq:
29
- measure_wall_time -> float
30
-
31
- Returns the wall time.*/
32
- static VALUE
33
- prof_measure_wall_time(VALUE self)
49
+ prof_measurer_t* prof_measurer_wall_time(bool track_allocations)
34
50
  {
35
- return rb_float_new(measure_wall_time());
51
+ prof_measurer_t* measure = ALLOC(prof_measurer_t);
52
+ measure->mode = MEASURE_WALL_TIME;
53
+ measure->measure = measure_wall_time;
54
+ measure->multiplier = multiplier_wall_time();
55
+ measure->track_allocations = track_allocations;
56
+ return measure;
36
57
  }
37
58
 
38
59
  void rp_init_measure_wall_time()
39
60
  {
40
61
  rb_define_const(mProf, "WALL_TIME", INT2NUM(MEASURE_WALL_TIME));
41
- rb_define_const(mProf, "WALL_TIME_ENABLED", Qtrue);
42
62
 
43
63
  cMeasureWallTime = rb_define_class_under(mMeasure, "WallTime", rb_cObject);
44
- rb_define_singleton_method(cMeasureWallTime, "measure", prof_measure_wall_time, 0);
45
64
  }
@@ -0,0 +1,221 @@
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
+ void prof_measurement_mark(void* data)
55
+ {
56
+ prof_measurement_t* measurement_data = (prof_measurement_t*)data;
57
+
58
+ if (measurement_data->object != Qnil)
59
+ rb_gc_mark(measurement_data->object);
60
+ }
61
+
62
+ static void prof_measurement_ruby_gc_free(void* data)
63
+ {
64
+ // Measurements are freed by their owning object (call info or method)
65
+ prof_measurement_t* measurement = (prof_measurement_t*)data;
66
+ measurement->object = Qnil;
67
+ }
68
+
69
+ void prof_measurement_free(prof_measurement_t* measurement)
70
+ {
71
+ /* Has this measurement object been accessed by Ruby? If
72
+ yes clean it up so to avoid a segmentation fault. */
73
+ if (measurement->object != Qnil)
74
+ {
75
+ RDATA(measurement->object)->dmark = NULL;
76
+ RDATA(measurement->object)->dfree = NULL;
77
+ RDATA(measurement->object)->data = NULL;
78
+ measurement->object = Qnil;
79
+ }
80
+
81
+ xfree(measurement);
82
+ }
83
+
84
+ size_t prof_measurement_size(const void* data)
85
+ {
86
+ return sizeof(prof_measurement_t);
87
+ }
88
+
89
+ VALUE prof_measurement_wrap(prof_measurement_t* measurement)
90
+ {
91
+ if (measurement->object == Qnil)
92
+ {
93
+ measurement->object = Data_Wrap_Struct(cRpMeasurement, NULL, prof_measurement_ruby_gc_free, measurement);
94
+ }
95
+ return measurement->object;
96
+ }
97
+
98
+ static VALUE prof_measurement_allocate(VALUE klass)
99
+ {
100
+ prof_measurement_t* measurement = prof_measurement_create();
101
+ measurement->object = prof_measurement_wrap(measurement);
102
+ return measurement->object;
103
+ }
104
+
105
+ prof_measurement_t* prof_get_measurement(VALUE self)
106
+ {
107
+ /* Can't use Data_Get_Struct because that triggers the event hook
108
+ ending up in endless recursion. */
109
+ prof_measurement_t* result = DATA_PTR(self);
110
+
111
+ if (!result)
112
+ rb_raise(rb_eRuntimeError, "This RubyProf::Measurement instance has already been freed, likely because its profile has been freed.");
113
+
114
+ return result;
115
+ }
116
+
117
+ /* call-seq:
118
+ total_time -> float
119
+
120
+ Returns the total amount of time spent in this method and its children. */
121
+ static VALUE prof_measurement_total_time(VALUE self)
122
+ {
123
+ prof_measurement_t* result = prof_get_measurement(self);
124
+ return rb_float_new(result->total_time);
125
+ }
126
+
127
+ /* call-seq:
128
+ self_time -> float
129
+
130
+ Returns the total amount of time spent in this method. */
131
+ static VALUE
132
+ prof_measurement_self_time(VALUE self)
133
+ {
134
+ prof_measurement_t* result = prof_get_measurement(self);
135
+
136
+ return rb_float_new(result->self_time);
137
+ }
138
+
139
+ /* call-seq:
140
+ wait_time -> float
141
+
142
+ Returns the total amount of time this method waited for other threads. */
143
+ static VALUE prof_measurement_wait_time(VALUE self)
144
+ {
145
+ prof_measurement_t* result = prof_get_measurement(self);
146
+
147
+ return rb_float_new(result->wait_time);
148
+ }
149
+
150
+ /* call-seq:
151
+ called -> int
152
+
153
+ Returns the total amount of times this method was called. */
154
+ static VALUE prof_measurement_called(VALUE self)
155
+ {
156
+ prof_measurement_t* result = prof_get_measurement(self);
157
+ return INT2NUM(result->called);
158
+ }
159
+
160
+ /* call-seq:
161
+ called=n -> n
162
+
163
+ Sets the call count to n. */
164
+ static VALUE prof_measurement_set_called(VALUE self, VALUE called)
165
+ {
166
+ prof_measurement_t* result = prof_get_measurement(self);
167
+ result->called = NUM2INT(called);
168
+ return called;
169
+ }
170
+
171
+ /* :nodoc: */
172
+ static VALUE
173
+ prof_measurement_dump(VALUE self)
174
+ {
175
+ prof_measurement_t* measurement_data = prof_get_measurement(self);
176
+ VALUE result = rb_hash_new();
177
+
178
+ rb_hash_aset(result, ID2SYM(rb_intern("total_time")), rb_float_new(measurement_data->total_time));
179
+ rb_hash_aset(result, ID2SYM(rb_intern("self_time")), rb_float_new(measurement_data->self_time));
180
+ rb_hash_aset(result, ID2SYM(rb_intern("wait_time")), rb_float_new(measurement_data->wait_time));
181
+ rb_hash_aset(result, ID2SYM(rb_intern("called")), INT2FIX(measurement_data->called));
182
+
183
+ return result;
184
+ }
185
+
186
+ /* :nodoc: */
187
+ static VALUE
188
+ prof_measurement_load(VALUE self, VALUE data)
189
+ {
190
+ prof_measurement_t* measurement = prof_get_measurement(self);
191
+ measurement->object = self;
192
+
193
+ measurement->total_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("total_time"))));
194
+ measurement->self_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("self_time"))));
195
+ measurement->wait_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("wait_time"))));
196
+ measurement->called = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("called"))));
197
+
198
+ return data;
199
+ }
200
+
201
+ void rp_init_measure()
202
+ {
203
+ mMeasure = rb_define_module_under(mProf, "Measure");
204
+ rp_init_measure_wall_time();
205
+ rp_init_measure_process_time();
206
+ rp_init_measure_allocations();
207
+ rp_init_measure_memory();
208
+
209
+ cRpMeasurement = rb_define_class_under(mProf, "Measurement", rb_cData);
210
+ rb_undef_method(CLASS_OF(cRpMeasurement), "new");
211
+ rb_define_alloc_func(cRpMeasurement, prof_measurement_allocate);
212
+
213
+ rb_define_method(cRpMeasurement, "called", prof_measurement_called, 0);
214
+ rb_define_method(cRpMeasurement, "called=", prof_measurement_set_called, 1);
215
+ rb_define_method(cRpMeasurement, "total_time", prof_measurement_total_time, 0);
216
+ rb_define_method(cRpMeasurement, "self_time", prof_measurement_self_time, 0);
217
+ rb_define_method(cRpMeasurement, "wait_time", prof_measurement_wait_time, 0);
218
+
219
+ rb_define_method(cRpMeasurement, "_dump_data", prof_measurement_dump, 0);
220
+ rb_define_method(cRpMeasurement, "_load_data", prof_measurement_load, 1);
221
+ }
@@ -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
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_get_measurer(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__