ruby-prof 0.11.2 → 0.13.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 (150) hide show
  1. data/CHANGES +31 -0
  2. data/README.rdoc +17 -17
  3. data/Rakefile +28 -5
  4. data/bin/ruby-prof +274 -265
  5. data/doc/LICENSE.html +155 -0
  6. data/doc/README_rdoc.html +640 -0
  7. data/doc/Rack/RubyProf.html +319 -0
  8. data/doc/Rack.html +167 -0
  9. data/doc/RubyProf/AbstractPrinter.html +580 -0
  10. data/doc/RubyProf/AggregateCallInfo.html +570 -0
  11. data/doc/RubyProf/CallInfo.html +512 -0
  12. data/doc/RubyProf/CallInfoPrinter.html +190 -0
  13. data/doc/RubyProf/CallInfoVisitor.html +332 -0
  14. data/doc/RubyProf/CallStackPrinter.html +1600 -0
  15. data/doc/RubyProf/CallTreePrinter.html +413 -0
  16. data/doc/RubyProf/Cmd.html +669 -0
  17. data/doc/RubyProf/DotPrinter.html +312 -0
  18. data/doc/RubyProf/FlatPrinter.html +229 -0
  19. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +267 -0
  20. data/doc/RubyProf/GraphHtmlPrinter.html +631 -0
  21. data/doc/RubyProf/GraphPrinter.html +209 -0
  22. data/doc/RubyProf/MethodInfo.html +713 -0
  23. data/doc/RubyProf/MultiPrinter.html +407 -0
  24. data/doc/RubyProf/Profile.html +821 -0
  25. data/doc/RubyProf/ProfileTask.html +532 -0
  26. data/doc/RubyProf/Test.html +578 -0
  27. data/doc/RubyProf/Thread.html +262 -0
  28. data/doc/RubyProf.html +999 -0
  29. data/doc/created.rid +32 -0
  30. data/doc/examples/flat_txt.html +191 -0
  31. data/doc/examples/graph_txt.html +305 -0
  32. data/doc/images/add.png +0 -0
  33. data/doc/images/brick.png +0 -0
  34. data/doc/images/brick_link.png +0 -0
  35. data/doc/images/bug.png +0 -0
  36. data/doc/images/bullet_black.png +0 -0
  37. data/doc/images/bullet_toggle_minus.png +0 -0
  38. data/doc/images/bullet_toggle_plus.png +0 -0
  39. data/doc/images/date.png +0 -0
  40. data/doc/images/delete.png +0 -0
  41. data/doc/images/find.png +0 -0
  42. data/doc/images/loadingAnimation.gif +0 -0
  43. data/doc/images/macFFBgHack.png +0 -0
  44. data/doc/images/package.png +0 -0
  45. data/doc/images/page_green.png +0 -0
  46. data/doc/images/page_white_text.png +0 -0
  47. data/doc/images/page_white_width.png +0 -0
  48. data/doc/images/plugin.png +0 -0
  49. data/doc/images/ruby.png +0 -0
  50. data/doc/images/tag_blue.png +0 -0
  51. data/doc/images/tag_green.png +0 -0
  52. data/doc/images/transparent.png +0 -0
  53. data/doc/images/wrench.png +0 -0
  54. data/doc/images/wrench_orange.png +0 -0
  55. data/doc/images/zoom.png +0 -0
  56. data/doc/index.html +639 -0
  57. data/doc/js/darkfish.js +155 -0
  58. data/doc/js/jquery.js +18 -0
  59. data/doc/js/navigation.js +142 -0
  60. data/doc/js/search.js +94 -0
  61. data/doc/js/search_index.js +1 -0
  62. data/doc/js/searcher.js +228 -0
  63. data/doc/rdoc.css +543 -0
  64. data/doc/table_of_contents.html +462 -0
  65. data/examples/empty.png +0 -0
  66. data/examples/minus.png +0 -0
  67. data/examples/plus.png +0 -0
  68. data/ext/ruby_prof/extconf.rb +7 -1
  69. data/ext/ruby_prof/rp_call_info.c +33 -24
  70. data/ext/ruby_prof/rp_call_info.h +2 -1
  71. data/ext/ruby_prof/rp_measure.c +1 -1
  72. data/ext/ruby_prof/rp_measure.h +1 -1
  73. data/ext/ruby_prof/rp_measure_allocations.c +1 -1
  74. data/ext/ruby_prof/rp_measure_cpu_time.c +1 -1
  75. data/ext/ruby_prof/rp_measure_gc_runs.c +1 -1
  76. data/ext/ruby_prof/rp_measure_gc_time.c +7 -11
  77. data/ext/ruby_prof/rp_measure_memory.c +1 -2
  78. data/ext/ruby_prof/rp_measure_process_time.c +2 -2
  79. data/ext/ruby_prof/rp_measure_wall_time.c +2 -2
  80. data/ext/ruby_prof/rp_method.c +11 -24
  81. data/ext/ruby_prof/rp_method.h +2 -3
  82. data/ext/ruby_prof/rp_stack.c +50 -14
  83. data/ext/ruby_prof/rp_stack.h +10 -10
  84. data/ext/ruby_prof/rp_thread.c +54 -29
  85. data/ext/ruby_prof/rp_thread.h +8 -7
  86. data/ext/ruby_prof/ruby_prof.c +35 -98
  87. data/ext/ruby_prof/ruby_prof.h +1 -1
  88. data/ext/ruby_prof/vc/ruby_prof.sln +12 -6
  89. data/ext/ruby_prof/vc/{ruby_prof.vcxproj → ruby_prof_19.vcxproj} +1 -0
  90. data/ext/ruby_prof/vc/ruby_prof_20.vcxproj +110 -0
  91. data/ext/ruby_prof/version.h +4 -4
  92. data/lib/ruby-prof/call_info.rb +1 -1
  93. data/lib/ruby-prof/call_info_visitor.rb +4 -2
  94. data/lib/ruby-prof/compatibility.rb +21 -6
  95. data/lib/ruby-prof/images/empty.png +0 -0
  96. data/lib/ruby-prof/images/minus.png +0 -0
  97. data/lib/ruby-prof/images/plus.png +0 -0
  98. data/lib/ruby-prof/method_info.rb +1 -1
  99. data/lib/ruby-prof/printers/call_info_printer.rb +3 -2
  100. data/lib/ruby-prof/printers/call_stack_printer.rb +10 -7
  101. data/lib/ruby-prof/printers/dot_printer.rb +2 -2
  102. data/lib/ruby-prof/printers/flat_printer.rb +5 -4
  103. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +2 -2
  104. data/lib/ruby-prof/printers/graph_html_printer.rb +16 -8
  105. data/lib/ruby-prof/printers/graph_printer.rb +17 -16
  106. data/lib/ruby-prof/profile.rb +1 -1
  107. data/lib/ruby-prof/rack.rb +1 -6
  108. data/lib/ruby-prof/task.rb +0 -0
  109. data/lib/ruby-prof/thread.rb +22 -0
  110. data/lib/ruby-prof.rb +1 -0
  111. data/ruby-prof.gemspec +5 -3
  112. data/test/aggregate_test.rb +0 -0
  113. data/test/basic_test.rb +77 -45
  114. data/test/call_info_test.rb +78 -0
  115. data/test/call_info_visitor_test.rb +1 -1
  116. data/test/duplicate_names_test.rb +0 -0
  117. data/test/dynamic_method_test.rb +21 -8
  118. data/test/enumerable_test.rb +0 -0
  119. data/test/exceptions_test.rb +0 -0
  120. data/test/exclude_threads_test.rb +0 -0
  121. data/test/exec_test.rb +0 -0
  122. data/test/fiber_test.rb +65 -0
  123. data/test/line_number_test.rb +0 -0
  124. data/test/measure_cpu_time_test.rb +23 -12
  125. data/test/measure_gc_runs_test.rb +4 -1
  126. data/test/measure_gc_time_test.rb +10 -3
  127. data/test/measure_memory_test.rb +3 -8
  128. data/test/measure_process_time_test.rb +27 -170
  129. data/test/measure_wall_time_test.rb +59 -13
  130. data/test/method_elimination_test.rb +31 -21
  131. data/test/module_test.rb +0 -0
  132. data/test/multi_printer_test.rb +9 -8
  133. data/test/no_method_class_test.rb +0 -0
  134. data/test/pause_resume_test.rb +125 -20
  135. data/test/prime.rb +1 -2
  136. data/test/printers_test.rb +10 -17
  137. data/test/recursive_test.rb +6 -50
  138. data/test/singleton_test.rb +0 -0
  139. data/test/stack_printer_test.rb +9 -6
  140. data/test/stack_test.rb +0 -0
  141. data/test/start_stop_test.rb +0 -0
  142. data/test/test_helper.rb +45 -11
  143. data/test/test_suite.rb +1 -2
  144. data/test/thread_test.rb +0 -0
  145. data/test/unique_call_path_test.rb +0 -0
  146. metadata +107 -12
  147. data/test/bug_test.rb +0 -6
  148. data/test/gc_test.rb +0 -35
  149. data/test/pause_test.rb +0 -57
  150. data/test/prime_test.rb +0 -13
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 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
4
  /* ruby-prof tracks the time spent executing every method in ruby programming.
@@ -116,80 +116,24 @@ static prof_method_t*
116
116
 
117
117
  method = create_method(event, klass, mid, source_file, line);
118
118
  method_table_insert(thread_data->method_table, method->key, method);
119
-
120
- /* Is this the first method added to the thread? */
121
- if (!thread_data->top)
122
- thread_data->top = method;
123
119
  }
124
120
  return method;
125
121
  }
126
122
 
127
- static prof_frame_t*
128
- pop_frame(prof_profile_t* profile, thread_data_t *thread_data)
129
- {
130
- prof_frame_t *frame = NULL;
131
- prof_frame_t* parent_frame = NULL;
132
- prof_call_info_t *call_info;
133
- double measurement = profile->measurer->measure();
134
- double total_time;
135
- double self_time;
136
- #ifdef _MSC_VER
137
- BOOL frame_paused;
138
- #else
139
- _Bool frame_paused;
140
- #endif
141
-
142
- frame = stack_pop(thread_data->stack); // only time it's called
143
-
144
- /* Frame can be null. This can happen if RubProf.start is called from
145
- a method that exits. And it can happen if an exception is raised
146
- in code that is being profiled and the stack unwinds (RubyProf is
147
- not notified of that by the ruby runtime. */
148
- if (frame == NULL)
149
- return NULL;
150
-
151
- /* Calculate the total time this method took */
152
- frame_paused = frame_is_paused(frame);
153
- frame_unpause(frame, measurement);
154
- total_time = measurement - frame->start_time - frame->dead_time;
155
- self_time = total_time - frame->child_time - frame->wait_time;
156
-
157
- /* Update information about the current method */
158
- call_info = frame->call_info;
159
- call_info->called++;
160
- call_info->total_time += total_time;
161
- call_info->self_time += self_time;
162
- call_info->wait_time += frame->wait_time;
163
-
164
- parent_frame = stack_peek(thread_data->stack);
165
- if (parent_frame)
166
- {
167
- parent_frame->child_time += total_time;
168
- parent_frame->dead_time += frame->dead_time;
169
-
170
- // Repause parent if currently paused
171
- if (frame_paused)
172
- frame_pause(parent_frame, measurement);
173
-
174
- call_info->line = parent_frame->line;
175
- }
176
-
177
- return frame;
178
- }
179
-
180
123
  static int
181
124
  pop_frames(st_data_t key, st_data_t value, st_data_t data)
182
125
  {
183
- VALUE thread_id = (VALUE)key;
126
+ VALUE fiber_id = (VALUE)key;
184
127
  thread_data_t* thread_data = (thread_data_t *) value;
185
128
  prof_profile_t* profile = (prof_profile_t*) data;
129
+ double measurement = profile->measurer->measure();
186
130
 
187
- if (!profile->last_thread_data || profile->last_thread_data->thread_id != thread_id)
188
- thread_data = switch_thread(profile, thread_id);
131
+ if (!profile->last_thread_data || profile->last_thread_data->fiber_id != fiber_id)
132
+ thread_data = switch_thread(profile, Qnil, fiber_id);
189
133
  else
190
134
  thread_data = profile->last_thread_data;
191
135
 
192
- while (pop_frame(profile, thread_data))
136
+ while (prof_stack_pop(thread_data->stack, measurement))
193
137
  {
194
138
  }
195
139
 
@@ -211,10 +155,16 @@ static void
211
155
  prof_trace(prof_profile_t* profile, rb_event_flag_t event, NODE *node, ID mid, VALUE klass, double measurement)
212
156
  #endif
213
157
  {
214
- static VALUE last_thread_id = Qnil;
158
+ static VALUE last_fiber_id = Qnil;
215
159
 
216
160
  VALUE thread = rb_thread_current();
217
161
  VALUE thread_id = rb_obj_id(thread);
162
+ #if defined(HAVE_RB_FIBER_CURRENT)
163
+ VALUE fiber = rb_fiber_current();
164
+ VALUE fiber_id = rb_obj_id(fiber);
165
+ #else
166
+ VALUE fiber_id = thread_id;
167
+ #endif
218
168
  const char* class_name = NULL;
219
169
  const char* method_name = rb_id2name(mid);
220
170
  const char* source_file = rb_sourcefile();
@@ -227,15 +177,16 @@ prof_trace(prof_profile_t* profile, rb_event_flag_t event, NODE *node, ID mid, V
227
177
 
228
178
  class_name = rb_class2name(klass);
229
179
 
230
- if (last_thread_id != thread_id)
180
+ if (last_fiber_id != fiber_id)
231
181
  {
232
182
  fprintf(trace_file, "\n");
233
183
  }
234
184
 
235
- fprintf(trace_file, "%2u:%2ums %-8s %s:%2d %s#%s\n",
236
- (unsigned int) thread_id, (unsigned int) measurement, event_name, source_file, source_line, class_name, method_name);
185
+ fprintf(trace_file, "%2lu:%2lu:%2ums %-8s %s:%2d %s#%s\n",
186
+ (unsigned long) thread_id, (unsigned long) fiber_id, (unsigned int) measurement*1000,
187
+ event_name, source_file, source_line, class_name, method_name);
237
188
  fflush(trace_file);
238
- last_thread_id = thread_id;
189
+ last_fiber_id = fiber_id;
239
190
  }
240
191
 
241
192
  #ifdef RUBY_VM
@@ -254,6 +205,8 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
254
205
 
255
206
  VALUE thread = Qnil;
256
207
  VALUE thread_id = Qnil;
208
+ VALUE fiber = Qnil;
209
+ VALUE fiber_id = Qnil;
257
210
  thread_data_t* thread_data = NULL;
258
211
  prof_frame_t *frame = NULL;
259
212
  double measurement;
@@ -280,11 +233,19 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
280
233
  /* Special case - skip any methods from the mProf
281
234
  module or cProfile class since they clutter
282
235
  the results but aren't important to them results. */
283
- if (self == mProf || klass == cProfile) return;
236
+ if (self == mProf || klass == cProfile)
237
+ return;
284
238
 
285
239
  /* Get the current thread information. */
286
240
  thread = rb_thread_current();
287
241
  thread_id = rb_obj_id(thread);
242
+ #if defined(HAVE_RB_FIBER_CURRENT)
243
+ fiber = rb_fiber_current();
244
+ fiber_id = rb_obj_id(fiber);
245
+ #else
246
+ fiber = thread;
247
+ fiber_id = thread_id;
248
+ #endif
288
249
 
289
250
  if (st_lookup(profile->exclude_threads_tbl, (st_data_t) thread_id, 0))
290
251
  {
@@ -292,13 +253,13 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
292
253
  }
293
254
 
294
255
  /* Was there a context switch? */
295
- if (!profile->last_thread_data || profile->last_thread_data->thread_id != thread_id)
296
- thread_data = switch_thread(profile, thread_id);
256
+ if (!profile->last_thread_data || profile->last_thread_data->fiber_id != fiber_id)
257
+ thread_data = switch_thread(profile, thread_id, fiber_id);
297
258
  else
298
259
  thread_data = profile->last_thread_data;
299
260
 
300
261
  /* Get the current frame for the current thread. */
301
- frame = stack_peek(thread_data->stack);
262
+ frame = prof_stack_peek(thread_data->stack);
302
263
 
303
264
  switch (event) {
304
265
  case RUBY_EVENT_LINE:
@@ -350,23 +311,21 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
350
311
  // Unpause the parent frame. If currently paused then:
351
312
  // 1) The child frame will begin paused.
352
313
  // 2) The parent will inherit the child's dead time.
353
- frame_unpause(frame, measurement);
314
+ prof_frame_unpause(frame, measurement);
354
315
  }
355
316
 
356
317
  /* Push a new frame onto the stack for a new c-call or ruby call (into a method) */
357
- frame = stack_push(thread_data->stack);
318
+ frame = prof_stack_push(thread_data->stack, measurement);
358
319
  frame->call_info = call_info;
359
320
  frame->call_info->depth = frame->depth;
360
- frame->start_time = measurement;
361
321
  frame->pause_time = profile->paused == Qtrue ? measurement : -1;
362
- frame->dead_time = 0;
363
322
  frame->line = rb_sourceline();
364
323
  break;
365
324
  }
366
325
  case RUBY_EVENT_RETURN:
367
326
  case RUBY_EVENT_C_RETURN:
368
327
  {
369
- pop_frame(profile, thread_data);
328
+ prof_stack_pop(thread_data->stack, measurement);
370
329
  break;
371
330
  }
372
331
  }
@@ -517,28 +476,6 @@ prof_initialize(int argc, VALUE *argv, VALUE self)
517
476
  return self;
518
477
  }
519
478
 
520
- static int pause_thread(st_data_t key, st_data_t value, st_data_t data)
521
- {
522
- thread_data_t* thread_data = (thread_data_t *) value;
523
- prof_profile_t* profile = (prof_profile_t*) data;
524
-
525
- prof_frame_t* frame = stack_peek(thread_data->stack);
526
- frame_pause(frame, profile->measurement_at_pause_resume);
527
-
528
- return ST_CONTINUE;
529
- }
530
-
531
- static int unpause_thread(st_data_t key, st_data_t value, st_data_t data)
532
- {
533
- thread_data_t* thread_data = (thread_data_t *) value;
534
- prof_profile_t* profile = (prof_profile_t*) data;
535
-
536
- prof_frame_t* frame = stack_peek(thread_data->stack);
537
- frame_unpause(frame, profile->measurement_at_pause_resume);
538
-
539
- return ST_CONTINUE;
540
- }
541
-
542
479
  /* call-seq:
543
480
  paused? -> boolean
544
481
 
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 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
4
  #ifndef __RUBY_PROF_H__
@@ -1,24 +1,30 @@
1
1
  
2
2
  Microsoft Visual Studio Solution File, Format Version 11.00
3
3
  # Visual Studio 2010
4
- Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ruby_prof", "ruby_prof.vcxproj", "{5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}"
5
- EndProject
6
4
  Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ruby_prof_18", "ruby_prof_18.vcxproj", "{7789FC23-D053-4733-9ED1-D6CE099E1237}"
7
5
  EndProject
6
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ruby_prof_19", "ruby_prof_19.vcxproj", "{5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}"
7
+ EndProject
8
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ruby_prof_20", "ruby_prof_20.vcxproj", "{6B4978F4-3B5F-4D38-81A8-069EC28CC069}"
9
+ EndProject
8
10
  Global
9
11
  GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
12
  Debug|Win32 = Debug|Win32
11
13
  Release|Win32 = Release|Win32
12
14
  EndGlobalSection
13
15
  GlobalSection(ProjectConfigurationPlatforms) = postSolution
14
- {5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}.Debug|Win32.ActiveCfg = Debug|Win32
15
- {5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}.Debug|Win32.Build.0 = Debug|Win32
16
- {5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}.Release|Win32.ActiveCfg = Release|Win32
17
- {5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}.Release|Win32.Build.0 = Release|Win32
18
16
  {7789FC23-D053-4733-9ED1-D6CE099E1237}.Debug|Win32.ActiveCfg = Debug|Win32
19
17
  {7789FC23-D053-4733-9ED1-D6CE099E1237}.Debug|Win32.Build.0 = Debug|Win32
20
18
  {7789FC23-D053-4733-9ED1-D6CE099E1237}.Release|Win32.ActiveCfg = Release|Win32
21
19
  {7789FC23-D053-4733-9ED1-D6CE099E1237}.Release|Win32.Build.0 = Release|Win32
20
+ {5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}.Debug|Win32.ActiveCfg = Debug|Win32
21
+ {5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}.Debug|Win32.Build.0 = Debug|Win32
22
+ {5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}.Release|Win32.ActiveCfg = Release|Win32
23
+ {5AF7F29A-B100-4D61-95DA-DB21D7C8C1B8}.Release|Win32.Build.0 = Release|Win32
24
+ {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Debug|Win32.ActiveCfg = Debug|Win32
25
+ {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Debug|Win32.Build.0 = Debug|Win32
26
+ {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Release|Win32.ActiveCfg = Release|Win32
27
+ {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Release|Win32.Build.0 = Release|Win32
22
28
  EndGlobalSection
23
29
  GlobalSection(SolutionProperties) = preSolution
24
30
  HideSolutionNode = FALSE
@@ -41,6 +41,7 @@
41
41
  <LinkIncremental>true</LinkIncremental>
42
42
  <OutDir>..\..\..\lib\1.9</OutDir>
43
43
  <TargetExt>.so</TargetExt>
44
+ <TargetName>ruby_prof</TargetName>
44
45
  </PropertyGroup>
45
46
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
46
47
  <LinkIncremental>false</LinkIncremental>
@@ -0,0 +1,110 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <ItemGroup Label="ProjectConfigurations">
4
+ <ProjectConfiguration Include="Debug|Win32">
5
+ <Configuration>Debug</Configuration>
6
+ <Platform>Win32</Platform>
7
+ </ProjectConfiguration>
8
+ <ProjectConfiguration Include="Release|Win32">
9
+ <Configuration>Release</Configuration>
10
+ <Platform>Win32</Platform>
11
+ </ProjectConfiguration>
12
+ </ItemGroup>
13
+ <PropertyGroup Label="Globals">
14
+ <ProjectGuid>{6B4978F4-3B5F-4D38-81A8-069EC28CC069}</ProjectGuid>
15
+ <Keyword>Win32Proj</Keyword>
16
+ <RootNamespace>ruby_prof</RootNamespace>
17
+ </PropertyGroup>
18
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
20
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
21
+ <UseDebugLibraries>true</UseDebugLibraries>
22
+ <CharacterSet>Unicode</CharacterSet>
23
+ </PropertyGroup>
24
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
25
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
26
+ <UseDebugLibraries>false</UseDebugLibraries>
27
+ <WholeProgramOptimization>true</WholeProgramOptimization>
28
+ <CharacterSet>Unicode</CharacterSet>
29
+ </PropertyGroup>
30
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
31
+ <ImportGroup Label="ExtensionSettings">
32
+ </ImportGroup>
33
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
34
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
35
+ </ImportGroup>
36
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
37
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
38
+ </ImportGroup>
39
+ <PropertyGroup Label="UserMacros" />
40
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
41
+ <LinkIncremental>true</LinkIncremental>
42
+ <OutDir>..\..\..\lib\2.0</OutDir>
43
+ <TargetExt>.so</TargetExt>
44
+ <TargetName>ruby_prof</TargetName>
45
+ </PropertyGroup>
46
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
47
+ <LinkIncremental>false</LinkIncremental>
48
+ </PropertyGroup>
49
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
50
+ <ClCompile>
51
+ <PrecompiledHeader>
52
+ </PrecompiledHeader>
53
+ <WarningLevel>Level3</WarningLevel>
54
+ <Optimization>Disabled</Optimization>
55
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;RUBY_PROF_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
56
+ <AdditionalIncludeDirectories>C:\MinGW\local\ruby200vc\include\ruby-2.0.0;C:\MinGW\local\ruby200vc\include\ruby-2.0.0\i386-mswin32_100;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
57
+ </ClCompile>
58
+ <Link>
59
+ <SubSystem>Windows</SubSystem>
60
+ <GenerateDebugInformation>true</GenerateDebugInformation>
61
+ <AdditionalLibraryDirectories>C:\MinGW\local\ruby200vc\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
62
+ <AdditionalDependencies>msvcr100-ruby200.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
63
+ <ModuleDefinitionFile>ruby_prof.def</ModuleDefinitionFile>
64
+ </Link>
65
+ </ItemDefinitionGroup>
66
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
67
+ <ClCompile>
68
+ <WarningLevel>Level3</WarningLevel>
69
+ <PrecompiledHeader>
70
+ </PrecompiledHeader>
71
+ <Optimization>MaxSpeed</Optimization>
72
+ <FunctionLevelLinking>true</FunctionLevelLinking>
73
+ <IntrinsicFunctions>true</IntrinsicFunctions>
74
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;RUBY_PROF_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
75
+ </ClCompile>
76
+ <Link>
77
+ <SubSystem>Windows</SubSystem>
78
+ <GenerateDebugInformation>true</GenerateDebugInformation>
79
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
80
+ <OptimizeReferences>true</OptimizeReferences>
81
+ </Link>
82
+ </ItemDefinitionGroup>
83
+ <ItemGroup>
84
+ <ClInclude Include="..\rp_call_info.h" />
85
+ <ClInclude Include="..\rp_measure.h" />
86
+ <ClInclude Include="..\rp_method.h" />
87
+ <ClInclude Include="..\rp_stack.h" />
88
+ <ClInclude Include="..\rp_thread.h" />
89
+ <ClInclude Include="..\ruby_prof.h" />
90
+ <ClInclude Include="..\version.h" />
91
+ </ItemGroup>
92
+ <ItemGroup>
93
+ <ClCompile Include="..\rp_call_info.c" />
94
+ <ClCompile Include="..\rp_measure.c" />
95
+ <ClCompile Include="..\rp_measure_allocations.c" />
96
+ <ClCompile Include="..\rp_measure_cpu_time.c" />
97
+ <ClCompile Include="..\rp_measure_gc_runs.c" />
98
+ <ClCompile Include="..\rp_measure_gc_time.c" />
99
+ <ClCompile Include="..\rp_measure_memory.c" />
100
+ <ClCompile Include="..\rp_measure_process_time.c" />
101
+ <ClCompile Include="..\rp_measure_wall_time.c" />
102
+ <ClCompile Include="..\rp_method.c" />
103
+ <ClCompile Include="..\rp_stack.c" />
104
+ <ClCompile Include="..\rp_thread.c" />
105
+ <ClCompile Include="..\ruby_prof.c" />
106
+ </ItemGroup>
107
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
108
+ <ImportGroup Label="ExtensionTargets">
109
+ </ImportGroup>
110
+ </Project>
@@ -1,7 +1,7 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 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
- #define RUBY_PROF_VERSION "0.11.2" // for easy parsing from rake files
4
+ #define RUBY_PROF_VERSION "0.13.0" // as a string, for easy parsing from rake files
5
5
  #define RUBY_PROF_VERSION_MAJ 0
6
- #define RUBY_PROF_VERSION_MIN 11
7
- #define RUBY_PROF_VERSION_MIC 2
6
+ #define RUBY_PROF_VERSION_MIN 13
7
+ #define RUBY_PROF_VERSION_MIC 0
@@ -57,7 +57,7 @@ module RubyProf
57
57
  parent.children.delete(self)
58
58
  end
59
59
 
60
- # find a sepcific call in list of children. returns nil if not found.
60
+ # find a specific call in list of children. returns nil if not found.
61
61
  # note: there can't be more than one child with a given target method. in other words:
62
62
  # x.children.grep{|y|y.target==m}.size <= 1 for all method infos m and call infos x
63
63
  def find_call(other)
@@ -26,8 +26,10 @@ module RubyProf
26
26
  def visit(&block)
27
27
  @block = block
28
28
 
29
- self.thread.top_method.call_infos.each do |call_info|
30
- self.visit_call_info(call_info)
29
+ self.thread.top_methods.each do |method_info|
30
+ method_info.call_infos.each do |call_info|
31
+ self.visit_call_info(call_info)
32
+ end
31
33
  end
32
34
  end
33
35
 
@@ -73,19 +73,29 @@ module RubyProf
73
73
  end
74
74
 
75
75
  # call-seq:
76
- # exclude_threads= -> void
76
+ # exclude_threads -> exclude_threads
77
77
  #
78
- # Specifies what threads ruby-prof should exclude from profiling
78
+ # Returns threads ruby-prof should exclude from profiling
79
79
 
80
80
  def self.exclude_threads
81
81
  @exclude_threads ||= Array.new
82
82
  end
83
83
 
84
+ # call-seq:
85
+ # exclude_threads= -> void
86
+ #
87
+ # Specifies what threads ruby-prof should exclude from profiling
88
+
84
89
  def self.exclude_threads=(value)
85
90
  @exclude_threads = value
86
91
  end
87
92
 
88
93
  # Profiling
94
+ def self.start_script(script)
95
+ start
96
+ load script
97
+ end
98
+
89
99
  def self.start
90
100
  ensure_not_running!
91
101
  @profile = Profile.new(self.measure_mode, self.exclude_threads)
@@ -115,8 +125,8 @@ module RubyProf
115
125
 
116
126
  def self.stop
117
127
  ensure_running!
118
- disable_gc_stats_if_needed
119
128
  result = @profile.stop
129
+ disable_gc_stats_if_needed
120
130
  @profile = nil
121
131
  result
122
132
  end
@@ -142,13 +152,18 @@ private
142
152
 
143
153
  # for GC.allocated_size to work GC statistics should be enabled
144
154
  def self.enable_gc_stats_if_needed
145
- if self.measure_mode == RubyProf::MEMORY && GC.respond_to?(:enable_stats)
155
+ if measure_mode_requires_gc_stats_enabled?
146
156
  @gc_stat_was_enabled = GC.enable_stats
147
157
  end
148
158
  end
149
159
 
150
160
  def self.disable_gc_stats_if_needed(was_enabled=nil)
151
161
  was_enabled ||= defined?(@gc_stat_was_enabled) && @gc_stat_was_enabled
152
- GC.disable_stats if self.measure_mode == RubyProf::MEMORY && GC.respond_to?(:disable_stats) && !was_enabled
162
+ GC.disable_stats if measure_mode_requires_gc_stats_enabled? && !was_enabled
163
+ end
164
+
165
+ def self.measure_mode_requires_gc_stats_enabled?
166
+ GC.respond_to?(:enable_stats) &&
167
+ [RubyProf::MEMORY, RubyProf::GC_TIME, RubyProf::GC_RUNS].include?(measure_mode)
153
168
  end
154
- end
169
+ end
File without changes
File without changes
File without changes
@@ -14,7 +14,7 @@ module RubyProf
14
14
  elsif self.min_depth > other.min_depth
15
15
  -1
16
16
  else
17
- -1 * (self.full_name <=> other.full_name)
17
+ self.full_name <=> other.full_name
18
18
  end
19
19
  end
20
20
 
@@ -12,7 +12,8 @@ module RubyProf
12
12
 
13
13
  def print_header(thread)
14
14
  @output << "Thread ID: #{thread.id}\n"
15
- @output << "Total Time: #{thread.top_method.total_time}\n"
15
+ @output << "Fiber ID: #{thread.fiber_id}\n"
16
+ @output << "Total Time: #{thread.total_time}\n"
16
17
  @output << "Sort by: #{sort_method}\n"
17
18
  @output << "\n"
18
19
  end
@@ -37,4 +38,4 @@ module RubyProf
37
38
  end
38
39
  end
39
40
  end
40
- end
41
+ end
@@ -45,20 +45,23 @@ module RubyProf
45
45
  print_header
46
46
 
47
47
  @overall_threads_time = @result.threads.inject(0) do |val, thread|
48
- val += thread.top_method.total_time
48
+ val += thread.total_time
49
49
  end
50
50
 
51
51
  @result.threads.each do |thread|
52
- @current_thread_id = thread.id
53
- @overall_time = thread.top_method.total_time
54
- @output.print "<div class=\"thread\">Thread: #{thread.id} (#{"%4.2f%%" % ((@overall_time/@overall_threads_time)*100)} ~ #{@overall_time})</div>"
52
+ @current_thread_id = thread.fiber_id
53
+ @overall_time = thread.total_time
54
+ thread_info = "Thread: #{thread.id}"
55
+ thread_info << ", Fiber: #{thread.fiber_id}" unless thread.id == thread.fiber_id
56
+ thread_info << " (#{"%4.2f%%" % ((@overall_time/@overall_threads_time)*100)} ~ #{@overall_time})"
57
+ @output.print "<div class=\"thread\">#{thread_info}</div>"
55
58
  @output.print "<ul name=\"thread\">"
56
59
  thread.methods.each do |m|
57
60
  # $stderr.print m.dump
58
61
  next unless m.root?
59
62
  m.call_infos.each do |ci|
60
63
  next unless ci.root?
61
- print_stack ci, thread.top_method.total_time
64
+ print_stack ci, thread.total_time
62
65
  end
63
66
  end
64
67
  @output.print "</ul>"
@@ -195,14 +198,14 @@ module RubyProf
195
198
  @output.puts "<title>#{h title}</title>"
196
199
  print_css
197
200
  print_java_script
198
- @output.puts '</head><body>'
201
+ @output.puts '</head><body><div style="display: inline-block;">'
199
202
  print_title_bar
200
203
  print_commands
201
204
  print_help
202
205
  end
203
206
 
204
207
  def print_footer
205
- @output.puts '<div id="sentinel"></div></body></html>'
208
+ @output.puts '<div id="sentinel"></div></div></body></html>'
206
209
  end
207
210
 
208
211
  def print_css
@@ -79,7 +79,7 @@ module RubyProf
79
79
  end
80
80
 
81
81
  def print_thread(thread)
82
- total_time = thread.top_method.total_time
82
+ total_time = thread.total_time
83
83
  thread.methods.sort_by(&sort_method).reverse_each do |method|
84
84
  total_percentage = (method.total_time/total_time) * 100
85
85
 
@@ -96,7 +96,7 @@ module RubyProf
96
96
  thread.methods.each{|m| grouped[m.klass_name] ||= []; grouped[m.klass_name] << m}
97
97
  grouped.each do |cls, methods2|
98
98
  # Filter down to just seen methods
99
- big_methods, small_methods = methods2.partition{|m| @seen_methods.include? m}
99
+ big_methods = methods2.select{|m| @seen_methods.include? m}
100
100
 
101
101
  if !big_methods.empty?
102
102
  puts "subgraph cluster_#{cls.object_id} {"
@@ -28,14 +28,15 @@ module RubyProf
28
28
 
29
29
  def print_header(thread)
30
30
  @output << "Thread ID: %d\n" % thread.id
31
- @output << "Total: %0.6f\n" % thread.top_method.total_time
31
+ @output << "Fiber ID: %d\n" % thread.fiber_id unless thread.id == thread.fiber_id
32
+ @output << "Total: %0.6f\n" % thread.total_time
32
33
  @output << "Sort by: #{sort_method}\n"
33
34
  @output << "\n"
34
- @output << " %self total self wait child calls name\n"
35
+ @output << " %self total self wait child calls name\n"
35
36
  end
36
37
 
37
38
  def print_methods(thread)
38
- total_time = thread.top_method.total_time
39
+ total_time = thread.total_time
39
40
  methods = thread.methods.sort_by(&sort_method).reverse
40
41
 
41
42
  sum = 0
@@ -47,7 +48,7 @@ module RubyProf
47
48
  #self_time_called = method.called > 0 ? method.self_time/method.called : 0
48
49
  #total_time_called = method.called > 0? method.total_time/method.called : 0
49
50
 
50
- @output << "%6.2f %8.2f %8.2f %8.2f %8.2f %8d %s%s \n" % [
51
+ @output << "%6.2f %9.3f %9.3f %9.3f %9.3f %8d %s%s \n" % [
51
52
  method.self_time / total_time * 100, # %self
52
53
  method.total_time, # total
53
54
  method.self_time, # self
@@ -13,7 +13,7 @@ module RubyProf
13
13
  #
14
14
  class FlatPrinterWithLineNumbers < FlatPrinter
15
15
  def print_methods(thread)
16
- total_time = thread.top_method.total_time
16
+ total_time = thread.total_time
17
17
 
18
18
  methods = thread.methods.sort_by(&sort_method).reverse
19
19
  sum = 0
@@ -25,7 +25,7 @@ module RubyProf
25
25
  #self_time_called = method.called > 0 ? method.self_time/method.called : 0
26
26
  #total_time_called = method.called > 0? method.total_time/method.called : 0
27
27
 
28
- @output << "%6.2f %8.2f %8.2f %8.2f %8.2f %8d %s%s \n" % [
28
+ @output << "%6.2f %9.3f %9.3f %9.3f %9.3f %8d %s%s \n" % [
29
29
  method.self_time / total_time * 100, # %self
30
30
  method.total_time, # total
31
31
  method.self_time, # self