ruby-prof 1.1.0-x64-mingw32 → 1.4.2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +48 -1
  3. data/Rakefile +2 -14
  4. data/bin/ruby-prof +100 -152
  5. data/ext/ruby_prof/extconf.rb +8 -28
  6. data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
  7. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  8. data/ext/ruby_prof/rp_allocation.c +67 -59
  9. data/ext/ruby_prof/rp_allocation.h +3 -3
  10. data/ext/ruby_prof/rp_call_tree.c +369 -0
  11. data/ext/ruby_prof/rp_call_tree.h +43 -0
  12. data/ext/ruby_prof/rp_call_trees.c +288 -0
  13. data/ext/ruby_prof/rp_call_trees.h +28 -0
  14. data/ext/ruby_prof/rp_measure_allocations.c +12 -14
  15. data/ext/ruby_prof/rp_measure_process_time.c +12 -14
  16. data/ext/ruby_prof/rp_measure_wall_time.c +17 -15
  17. data/ext/ruby_prof/rp_measurement.c +47 -40
  18. data/ext/ruby_prof/rp_measurement.h +7 -7
  19. data/ext/ruby_prof/rp_method.c +116 -255
  20. data/ext/ruby_prof/rp_method.h +31 -39
  21. data/ext/ruby_prof/rp_profile.c +316 -303
  22. data/ext/ruby_prof/rp_profile.h +1 -3
  23. data/ext/ruby_prof/rp_stack.c +122 -106
  24. data/ext/ruby_prof/rp_stack.h +17 -20
  25. data/ext/ruby_prof/rp_thread.c +136 -111
  26. data/ext/ruby_prof/rp_thread.h +12 -9
  27. data/ext/ruby_prof/ruby_prof.c +27 -23
  28. data/ext/ruby_prof/ruby_prof.h +9 -0
  29. data/ext/ruby_prof/vc/ruby_prof.sln +8 -0
  30. data/ext/ruby_prof/vc/ruby_prof.vcxproj +22 -7
  31. data/lib/2.7/ruby_prof.so +0 -0
  32. data/lib/ruby-prof.rb +5 -5
  33. data/lib/ruby-prof/assets/call_stack_printer.html.erb +4 -7
  34. data/lib/ruby-prof/assets/graph_printer.html.erb +5 -6
  35. data/lib/ruby-prof/{call_info.rb → call_tree.rb} +6 -6
  36. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  37. data/lib/ruby-prof/compatibility.rb +0 -10
  38. data/lib/ruby-prof/measurement.rb +5 -2
  39. data/lib/ruby-prof/method_info.rb +3 -15
  40. data/lib/ruby-prof/printers/abstract_printer.rb +12 -2
  41. data/lib/ruby-prof/printers/call_info_printer.rb +12 -10
  42. data/lib/ruby-prof/printers/call_stack_printer.rb +20 -22
  43. data/lib/ruby-prof/printers/call_tree_printer.rb +1 -1
  44. data/lib/ruby-prof/printers/dot_printer.rb +3 -3
  45. data/lib/ruby-prof/printers/flat_printer.rb +3 -2
  46. data/lib/ruby-prof/printers/graph_printer.rb +4 -5
  47. data/lib/ruby-prof/printers/multi_printer.rb +2 -2
  48. data/lib/ruby-prof/profile.rb +8 -4
  49. data/lib/ruby-prof/rack.rb +51 -127
  50. data/lib/ruby-prof/thread.rb +3 -18
  51. data/lib/ruby-prof/version.rb +1 -1
  52. data/ruby-prof.gemspec +7 -0
  53. data/test/alias_test.rb +42 -45
  54. data/test/basic_test.rb +0 -86
  55. data/test/{call_info_visitor_test.rb → call_tree_visitor_test.rb} +6 -5
  56. data/test/call_trees_test.rb +66 -0
  57. data/test/exclude_methods_test.rb +17 -12
  58. data/test/fiber_test.rb +95 -39
  59. data/test/gc_test.rb +36 -42
  60. data/test/inverse_call_tree_test.rb +175 -0
  61. data/test/line_number_test.rb +67 -70
  62. data/test/marshal_test.rb +7 -13
  63. data/test/measure_allocations_test.rb +224 -234
  64. data/test/measure_allocations_trace_test.rb +224 -234
  65. data/test/measure_memory_trace_test.rb +814 -469
  66. data/test/measure_process_time_test.rb +0 -64
  67. data/test/measure_times.rb +2 -0
  68. data/test/measure_wall_time_test.rb +34 -58
  69. data/test/pause_resume_test.rb +19 -10
  70. data/test/prime.rb +1 -3
  71. data/test/prime_script.rb +6 -0
  72. data/test/printer_call_stack_test.rb +0 -1
  73. data/test/printer_call_tree_test.rb +0 -1
  74. data/test/printer_flat_test.rb +61 -30
  75. data/test/printer_graph_html_test.rb +0 -1
  76. data/test/printer_graph_test.rb +3 -4
  77. data/test/printers_test.rb +2 -2
  78. data/test/printing_recursive_graph_test.rb +1 -1
  79. data/test/profile_test.rb +16 -0
  80. data/test/rack_test.rb +0 -64
  81. data/test/recursive_test.rb +50 -54
  82. data/test/start_stop_test.rb +19 -19
  83. data/test/test_helper.rb +6 -17
  84. data/test/thread_test.rb +11 -11
  85. data/test/unique_call_path_test.rb +25 -95
  86. metadata +22 -11
  87. data/ext/ruby_prof/rp_call_info.c +0 -271
  88. data/ext/ruby_prof/rp_call_info.h +0 -35
  89. data/lib/2.6.5/ruby_prof.so +0 -0
  90. data/lib/ruby-prof/call_info_visitor.rb +0 -38
  91. data/test/parser_timings.rb +0 -24
@@ -8,14 +8,14 @@
8
8
  #include "rp_stack.h"
9
9
 
10
10
  /* Profiling information for a thread. */
11
- typedef struct
11
+ typedef struct thread_data_t
12
12
  {
13
13
  // Runtime
14
14
  VALUE object; /* Cache to wrapped object */
15
15
  VALUE fiber; /* Fiber */
16
16
  prof_stack_t* stack; /* Stack of frames */
17
17
  bool trace; /* Are we tracking this thread */
18
-
18
+ prof_call_tree_t* call_tree; /* The root of the call tree*/
19
19
  VALUE thread_id; /* Thread id */
20
20
  VALUE fiber_id; /* Fiber id */
21
21
  VALUE methods; /* Array of RubyProf::MethodInfo */
@@ -23,13 +23,16 @@ typedef struct
23
23
  } thread_data_t;
24
24
 
25
25
  void rp_init_thread(void);
26
- st_table * threads_table_create(void);
27
- thread_data_t *threads_table_lookup(void *profile, VALUE fiber);
28
- thread_data_t* threads_table_insert(void *profile, VALUE fiber);
29
- void switch_thread(void *profile, thread_data_t *thread_data, double measurement);
30
- void threads_table_free(st_table *table);
31
- VALUE prof_thread_wrap(thread_data_t *thread);
32
- void prof_thread_mark(void *data);
26
+ st_table* threads_table_create(void);
27
+ thread_data_t* threads_table_lookup(void* profile, VALUE fiber);
28
+ thread_data_t* threads_table_insert(void* profile, VALUE fiber);
29
+ void threads_table_free(st_table* table);
30
+
31
+ thread_data_t* prof_get_thread(VALUE self);
32
+ VALUE prof_thread_wrap(thread_data_t* thread);
33
+ void prof_thread_mark(void* data);
34
+
35
+ void switch_thread(void* profile, thread_data_t* thread_data, double measurement);
33
36
  int pause_thread(st_data_t key, st_data_t value, st_data_t data);
34
37
  int unpause_thread(st_data_t key, st_data_t value, st_data_t data);
35
38
 
@@ -1,34 +1,36 @@
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
- /* ruby-prof tracks the time spent executing every method in ruby programming.
5
- The main players are:
6
-
7
- profile_t - This represents 1 profile.
8
- thread_data_t - Stores data about a single thread.
9
- prof_stack_t - The method call stack in a particular thread
10
- prof_method_t - Profiling information about each method
11
- prof_call_info_t - Keeps track a method's callers and callees.
12
-
13
- The final result is an instance of a profile object which has a hash table of
14
- thread_data_t, keyed on the thread id. Each thread in turn has a hash table
15
- of prof_method_t, keyed on the method id. A hash table is used for quick
16
- look up when doing a profile. However, it is exposed to Ruby as an array.
17
-
18
- Each prof_method_t has two hash tables, parent and children, of prof_call_info_t.
19
- These objects keep track of a method's callers (who called the method) and its
20
- callees (who the method called). These are keyed the method id, but once again,
21
- are exposed to Ruby as arrays. Each prof_call_into_t maintains a pointer to the
22
- caller or callee method, thereby making it easy to navigate through the call
23
- hierarchy in ruby - which is very helpful for creating call graphs.
24
- */
4
+ /* ruby-prof tracks the time spent executing every method in ruby programming.
5
+ The main players are:
6
+
7
+ profile_t - This represents 1 profile.
8
+ thread_data_t - Stores data about a single thread.
9
+ prof_stack_t - The method call stack in a particular thread
10
+ prof_method_t - Profiling information about each method
11
+ prof_call_tree_t - Keeps track a method's callers and callees.
12
+
13
+ The final result is an instance of a profile object which has a hash table of
14
+ thread_data_t, keyed on the thread id. Each thread in turn has a hash table
15
+ of prof_method_t, keyed on the method id. A hash table is used for quick
16
+ look up when doing a profile. However, it is exposed to Ruby as an array.
17
+
18
+ Each prof_method_t has two hash tables, parent and children, of prof_call_tree_t.
19
+ These objects keep track of a method's callers (who called the method) and its
20
+ callees (who the method called). These are keyed the method id, but once again,
21
+ are exposed to Ruby as arrays. Each prof_call_into_t maintains a pointer to the
22
+ caller or callee method, thereby making it easy to navigate through the call
23
+ hierarchy in ruby - which is very helpful for creating call graphs.
24
+ */
25
25
 
26
26
  #include "ruby_prof.h"
27
27
 
28
28
  #include "rp_allocation.h"
29
29
  #include "rp_measurement.h"
30
30
  #include "rp_method.h"
31
- #include "rp_call_info.h"
31
+ #include "rp_call_tree.h"
32
+ #include "rp_aggregate_call_tree.h"
33
+ #include "rp_call_trees.h"
32
34
  #include "rp_profile.h"
33
35
  #include "rp_stack.h"
34
36
  #include "rp_thread.h"
@@ -40,7 +42,9 @@ void Init_ruby_prof()
40
42
  mProf = rb_define_module("RubyProf");
41
43
 
42
44
  rp_init_allocation();
43
- rp_init_call_info();
45
+ rp_init_call_tree();
46
+ rp_init_aggregate_call_tree();
47
+ rp_init_call_trees();
44
48
  rp_init_measure();
45
49
  rp_init_method_info();
46
50
  rp_init_profile();
@@ -9,6 +9,15 @@
9
9
  #include <stdio.h>
10
10
  #include <stdbool.h>
11
11
 
12
+ #ifndef rb_st_lookup
13
+ #define rb_st_foreach st_foreach
14
+ #define rb_st_free_table st_free_table
15
+ #define rb_st_init_numtable st_init_numtable
16
+ #define rb_st_insert st_insert
17
+ #define rb_st_lookup st_lookup
18
+ #endif
19
+
20
+
12
21
  extern VALUE mProf;
13
22
 
14
23
  // This method is not exposed in Ruby header files - at least not as of Ruby 2.6.3 :(
@@ -7,16 +7,24 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ruby_prof", "ruby_prof.vcxp
7
7
  EndProject
8
8
  Global
9
9
  GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
+ Debug|ARM = Debug|ARM
11
+ Debug|ARM64 = Debug|ARM64
10
12
  Debug|x64 = Debug|x64
11
13
  Debug|x86 = Debug|x86
14
+ Release|ARM = Release|ARM
15
+ Release|ARM64 = Release|ARM64
12
16
  Release|x64 = Release|x64
13
17
  Release|x86 = Release|x86
14
18
  EndGlobalSection
15
19
  GlobalSection(ProjectConfigurationPlatforms) = postSolution
20
+ {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Debug|ARM.ActiveCfg = Debug|Win32
21
+ {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Debug|ARM64.ActiveCfg = Debug|Win32
16
22
  {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Debug|x64.ActiveCfg = Debug|x64
17
23
  {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Debug|x64.Build.0 = Debug|x64
18
24
  {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Debug|x86.ActiveCfg = Debug|Win32
19
25
  {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Debug|x86.Build.0 = Debug|Win32
26
+ {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Release|ARM.ActiveCfg = Release|Win32
27
+ {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Release|ARM64.ActiveCfg = Release|Win32
20
28
  {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Release|x64.ActiveCfg = Release|x64
21
29
  {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Release|x64.Build.0 = Release|x64
22
30
  {6B4978F4-3B5F-4D38-81A8-069EC28CC069}.Release|x86.ActiveCfg = Release|Win32
@@ -64,7 +64,7 @@
64
64
  </PropertyGroup>
65
65
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66
66
  <TargetExt>.so</TargetExt>
67
- <OutDir>..\</OutDir>
67
+ <OutDir>..\..\..\lib\</OutDir>
68
68
  </PropertyGroup>
69
69
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
70
70
  <ClCompile>
@@ -102,30 +102,45 @@
102
102
  </ItemDefinitionGroup>
103
103
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104
104
  <ClCompile>
105
- <AdditionalIncludeDirectories>C:\msys64\usr\local\ruby-2.6.5vc\include\ruby-2.6.0\x64-mswin64_140;C:\msys64\usr\local\ruby-2.6.5vc\include\ruby-2.6.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
105
+ <AdditionalIncludeDirectories>C:\msys64\usr\local\ruby-2.7.2vc\include\ruby-2.7.0\x64-mswin64_140;C:\msys64\usr\local\ruby-2.7.2vc\include\ruby-2.7.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
106
106
  <Optimization>Disabled</Optimization>
107
107
  <PreprocessorDefinitions>HAVE_RB_TRACEARG_CALLEE_ID;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108
+ <WarningLevel>Level3</WarningLevel>
109
+ </ClCompile>
110
+ <Link>
111
+ <AdditionalLibraryDirectories>C:\msys64\usr\local\ruby-2.7.2vc\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
112
+ <AdditionalDependencies>x64-vcruntime140-ruby270.lib;%(AdditionalDependencies)</AdditionalDependencies>
113
+ <ModuleDefinitionFile>ruby_prof.def</ModuleDefinitionFile>
114
+ <SubSystem>Console</SubSystem>
115
+ </Link>
116
+ </ItemDefinitionGroup>
117
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
118
+ <ClCompile>
119
+ <AdditionalIncludeDirectories>C:\msys64\usr\local\ruby-2.7.1vc\include\ruby-2.7.0\x64-mswin64_140;C:\msys64\usr\local\ruby-2.7.1vc\include\ruby-2.7.0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
108
120
  </ClCompile>
109
121
  <Link>
110
- <AdditionalLibraryDirectories>C:\msys64\usr\local\ruby-2.6.5vc\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
111
- <AdditionalDependencies>x64-vcruntime140-ruby260.lib;%(AdditionalDependencies)</AdditionalDependencies>
122
+ <AdditionalLibraryDirectories>C:\msys64\usr\local\ruby-2.7.1vc\lib</AdditionalLibraryDirectories>
123
+ <AdditionalDependencies>x64-vcruntime140-ruby270.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>
112
124
  <ModuleDefinitionFile>ruby_prof.def</ModuleDefinitionFile>
113
125
  </Link>
114
126
  </ItemDefinitionGroup>
115
127
  <ItemGroup>
128
+ <ClInclude Include="..\rp_aggregate_call_tree.h" />
116
129
  <ClInclude Include="..\rp_allocation.h" />
117
- <ClInclude Include="..\rp_call_info.h" />
130
+ <ClInclude Include="..\rp_call_tree.h" />
131
+ <ClInclude Include="..\rp_call_trees.h" />
118
132
  <ClInclude Include="..\rp_measurement.h" />
119
133
  <ClInclude Include="..\rp_method.h" />
120
134
  <ClInclude Include="..\rp_profile.h" />
121
135
  <ClInclude Include="..\rp_stack.h" />
122
136
  <ClInclude Include="..\rp_thread.h" />
123
137
  <ClInclude Include="..\ruby_prof.h" />
124
- <ClInclude Include="..\version.h" />
125
138
  </ItemGroup>
126
139
  <ItemGroup>
140
+ <ClCompile Include="..\rp_aggregate_call_tree.c" />
127
141
  <ClCompile Include="..\rp_allocation.c" />
128
- <ClCompile Include="..\rp_call_info.c" />
142
+ <ClCompile Include="..\rp_call_tree.c" />
143
+ <ClCompile Include="..\rp_call_trees.c" />
129
144
  <ClCompile Include="..\rp_measurement.c" />
130
145
  <ClCompile Include="..\rp_measure_allocations.c" />
131
146
  <ClCompile Include="..\rp_measure_memory.c" />
Binary file
@@ -1,15 +1,16 @@
1
1
  # encoding: utf-8
2
+ require 'rubygems/version'
2
3
 
3
4
  # Load the C-based binding.
4
5
  begin
5
- RUBY_VERSION =~ /(\d+\.\d+\.\d+)/
6
- require "#{$1}/ruby_prof.so"
6
+ version = Gem::Version.new(RUBY_VERSION)
7
+ require "#{version.segments[0..1].join('.')}/ruby_prof.so"
7
8
  rescue LoadError
8
9
  require "ruby_prof.so"
9
10
  end
10
11
 
11
12
  require 'ruby-prof/version'
12
- require 'ruby-prof/call_info'
13
+ require 'ruby-prof/call_tree'
13
14
  require 'ruby-prof/compatibility'
14
15
  require 'ruby-prof/measurement'
15
16
  require 'ruby-prof/method_info'
@@ -18,8 +19,7 @@ require 'ruby-prof/rack'
18
19
  require 'ruby-prof/thread'
19
20
 
20
21
  module RubyProf
21
- autoload :CallInfoVisitor, 'ruby-prof/call_info_visitor'
22
-
22
+ autoload :CallTreeVisitor, 'ruby-prof/call_tree_visitor'
23
23
  autoload :AbstractPrinter, 'ruby-prof/printers/abstract_printer'
24
24
  autoload :CallInfoPrinter, 'ruby-prof/printers/call_info_printer'
25
25
  autoload :CallStackPrinter, 'ruby-prof/printers/call_stack_printer'
@@ -697,13 +697,10 @@
697
697
  <div class="thread">
698
698
  <span>Thread: <%= thread.id %>, Fiber: <%= thread.fiber_id %> (<%= thread_info %>)</span>
699
699
  <ul name="thread">
700
- <% call_infos = thread.root_methods.map(&:callers).flatten %>
701
- <% call_infos.each do |call_info| %>
702
- <% visited = Set.new
703
- output = StringIO.new('')
704
- print_stack(output, visited, call_info, call_info.total_time) %>
705
- <%= output.string %>
706
- <% end %>
700
+ <% visited = Set.new
701
+ output = StringIO.new('')
702
+ print_stack(output, visited, thread.call_tree, thread.call_tree.total_time) %>
703
+ <%= output.string %>
707
704
  </ul>
708
705
  </div>
709
706
  <% end %>
@@ -217,8 +217,7 @@
217
217
  self_percentage = (method.self_time/total_time) * 100 %>
218
218
 
219
219
  <!-- Parents -->
220
- <% for caller in method.callers.sort
221
- next if method.root?
220
+ <% for caller in method.call_trees.callers.sort
222
221
  next if min_time && caller.total_time < min_time %>
223
222
  <tr>
224
223
  <td>&nbsp;</td>
@@ -228,12 +227,12 @@
228
227
  <td><%= sprintf("%.2f", caller.wait_time) %></td>
229
228
  <td><%= sprintf("%.2f", caller.children_time) %></td>
230
229
  <td><%= "#{caller.called}/#{method.called}" %></td>
231
- <td class="method_name"><%= create_link(thread, total_time, caller.parent) %></td>
230
+ <td class="method_name"><%= create_link(thread, total_time, caller.parent.target) %></td>
232
231
  <% if @result.track_allocations? %>
233
232
  <td>-</td>
234
233
  <% end %>
235
- <td><%= if caller.parent.source_file
236
- file_link(caller.parent.source_file, caller.line)
234
+ <td><%= if caller.parent.target.source_file
235
+ file_link(caller.parent.target.source_file, caller.line)
237
236
  end %></td>
238
237
  </tr>
239
238
  <% end %>
@@ -293,7 +292,7 @@
293
292
  <% end %>
294
293
 
295
294
  <!-- Children -->
296
- <% for callee in method.callees.sort_by(&:total_time).reverse
295
+ <% for callee in method.call_trees.callees.sort_by(&:total_time).reverse
297
296
  next if min_time && callee.total_time < min_time %>
298
297
  <tr>
299
298
  <td>&nbsp;</td>
@@ -1,11 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module RubyProf
4
- # The CallInfo class is used to track the relationships between methods. It is a helper class used by
4
+ # The CallTree class is used to track the relationships between methods. It is a helper class used by
5
5
  # RubyProf::MethodInfo to keep track of which methods called a given method and which methods a given
6
- # method called. Each CallInfo has a parent and target method. You cannot create a CallInfo object directly,
6
+ # method called. Each CallTree has a parent and target method. You cannot create a CallTree object directly,
7
7
  # they are generated while running a profile.
8
- class CallInfo
8
+ class CallTree
9
9
  # The number of times the parent method called the target method
10
10
  def called
11
11
  self.measurement.called
@@ -31,7 +31,7 @@ module RubyProf
31
31
  self.total_time - self.self_time - self.wait_time
32
32
  end
33
33
 
34
- # Compares two CallInfo instances. The comparison is based on the CallInfo#parent, CallInfo#target,
34
+ # Compares two CallTree instances. The comparison is based on the CallTree#parent, CallTree#target,
35
35
  # and total time.
36
36
  def <=>(other)
37
37
  if self.target == other.target && self.parent == other.parent
@@ -47,11 +47,11 @@ module RubyProf
47
47
 
48
48
  # :nodoc:
49
49
  def to_s
50
- "#{parent ? parent.full_name : '<nil>'} - #{target.full_name}"
50
+ "<#{self.class.name} - #{self.target.full_name}>"
51
51
  end
52
52
 
53
53
  def inspect
54
- super + "(#{self.to_s})"
54
+ self.to_s
55
55
  end
56
56
  end
57
57
  end
@@ -0,0 +1,36 @@
1
+ module RubyProf
2
+ # The call info visitor class does a depth-first traversal across a
3
+ # list of call infos. At each call_tree node, the visitor executes
4
+ # the block provided in the #visit method. The block is passed two
5
+ # parameters, the event and the call_tree instance. Event will be
6
+ # either :enter or :exit.
7
+ #
8
+ # visitor = RubyProf::CallTreeVisitor.new(result.threads.first.call_tree)
9
+ #
10
+ # method_names = Array.new
11
+ #
12
+ # visitor.visit do |call_tree, event|
13
+ # method_names << call_tree.target.full_name if event == :enter
14
+ # end
15
+ #
16
+ # puts method_names
17
+ class CallTreeVisitor
18
+ def initialize(call_tree)
19
+ @call_tree = call_tree
20
+ end
21
+
22
+ def visit(&block)
23
+ visit_call_tree(@call_tree, &block)
24
+ end
25
+
26
+ private
27
+
28
+ def visit_call_tree(call_tree, &block)
29
+ yield call_tree, :enter
30
+ call_tree.children.each do |child|
31
+ visit_call_tree(child, &block)
32
+ end
33
+ yield call_tree, :exit
34
+ end
35
+ end
36
+ end
@@ -81,16 +81,6 @@ module RubyProf
81
81
  Profile.profile(options, &block)
82
82
  end
83
83
 
84
- # :nodoc:
85
- def self.measure_mode_string
86
- case measure_mode
87
- when WALL_TIME then "wall_time"
88
- when PROCESS_TIME then "process_time"
89
- when ALLOCATIONS then "allocations"
90
- when MEMORY then "memory"
91
- end
92
- end
93
-
94
84
  # :nodoc:
95
85
  def self.start_script(script)
96
86
  start
@@ -1,8 +1,11 @@
1
1
  module RubyProf
2
2
  # The Measurement class is a helper class used by RubyProf::MethodInfo to store information about the method.
3
- # You cannot create a CallInfo object directly, they are generated while running a profile.
3
+ # You cannot create a CallTree object directly, they are generated while running a profile.
4
4
  class Measurement
5
- # :nodoc:
5
+ def children_time
6
+ self.total_time - self.self_time - self.wait_time
7
+ end
8
+
6
9
  def to_s
7
10
  "c: #{called}, tt: #{total_time}, st: #{self_time}"
8
11
  end
@@ -52,14 +52,9 @@ module RubyProf
52
52
  self.total_time - self.self_time - self.wait_time
53
53
  end
54
54
 
55
- # The min call depth of this method
56
- def min_depth
57
- @min_depth ||= callers.map(&:depth).min
58
- end
59
-
60
55
  # :enddoc:
61
56
  def <=>(other)
62
- if other == nil
57
+ if other.nil?
63
58
  -1
64
59
  elsif self.full_name == other.full_name
65
60
  0
@@ -67,9 +62,9 @@ module RubyProf
67
62
  -1
68
63
  elsif self.total_time > other.total_time
69
64
  1
70
- elsif self.min_depth < other.min_depth
65
+ elsif self.call_trees.min_depth < other.call_trees.min_depth
71
66
  1
72
- elsif self.min_depth > other.min_depth
67
+ elsif self.call_trees.min_depth > other.call_trees.min_depth
73
68
  -1
74
69
  else
75
70
  self.full_name <=> other.full_name
@@ -79,12 +74,5 @@ module RubyProf
79
74
  def to_s
80
75
  "#{self.full_name} (c: #{self.called}, tt: #{self.total_time}, st: #{self.self_time}, wt: #{wait_time}, ct: #{self.children_time})"
81
76
  end
82
-
83
- # Remove method from the call graph. should not be called directly.
84
- def eliminate!
85
- # $stderr.puts "eliminating #{self}"
86
- callers.each{ |call_info| call_info.eliminate! }
87
- callers.clear
88
- end
89
77
  end
90
78
  end