ruby-prof 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/CHANGES +54 -1
  2. data/README +134 -7
  3. data/Rakefile +40 -58
  4. data/bin/ruby-prof +21 -6
  5. data/ext/extconf.rb +13 -0
  6. data/ext/measure_allocations.h +16 -1
  7. data/ext/measure_cpu_time.h +15 -3
  8. data/ext/measure_gc_runs.h +76 -0
  9. data/ext/measure_gc_time.h +57 -0
  10. data/ext/measure_memory.h +61 -2
  11. data/ext/measure_process_time.h +13 -2
  12. data/ext/measure_wall_time.h +12 -1
  13. data/ext/mingw/Rakefile +23 -0
  14. data/ext/mingw/build.rake +38 -0
  15. data/ext/ruby_prof.c +685 -633
  16. data/ext/ruby_prof.h +188 -0
  17. data/ext/vc/ruby_prof.sln +20 -0
  18. data/ext/vc/ruby_prof.vcproj +241 -0
  19. data/ext/version.h +4 -0
  20. data/lib/ruby-prof.rb +4 -0
  21. data/lib/ruby-prof/call_info.rb +47 -0
  22. data/lib/ruby-prof/call_tree_printer.rb +9 -1
  23. data/lib/ruby-prof/graph_html_printer.rb +6 -5
  24. data/lib/ruby-prof/graph_printer.rb +3 -2
  25. data/lib/ruby-prof/method_info.rb +85 -0
  26. data/lib/ruby-prof/task.rb +1 -2
  27. data/lib/ruby-prof/test.rb +148 -0
  28. data/rails/environment/profile.rb +24 -0
  29. data/rails/example/example_test.rb +9 -0
  30. data/rails/profile_test_helper.rb +21 -0
  31. data/test/basic_test.rb +173 -80
  32. data/test/duplicate_names_test.rb +2 -3
  33. data/test/exceptions_test.rb +15 -0
  34. data/test/exclude_threads_test.rb +54 -0
  35. data/test/line_number_test.rb +18 -14
  36. data/test/measurement_test.rb +121 -0
  37. data/test/module_test.rb +5 -8
  38. data/test/no_method_class_test.rb +4 -5
  39. data/test/prime.rb +3 -5
  40. data/test/prime_test.rb +1 -12
  41. data/test/printers_test.rb +10 -13
  42. data/test/profile_unit_test.rb +10 -12
  43. data/test/recursive_test.rb +202 -92
  44. data/test/singleton_test.rb +1 -2
  45. data/test/stack_test.rb +138 -0
  46. data/test/start_stop_test.rb +95 -0
  47. data/test/test_suite.rb +7 -3
  48. data/test/thread_test.rb +111 -87
  49. data/test/unique_call_path_test.rb +206 -0
  50. metadata +40 -42
  51. data/ext/extconf.rb.rej +0 -13
  52. data/lib/ruby-prof/call_tree_printer.rb.rej +0 -27
  53. data/lib/ruby-prof/profile_test_case.rb +0 -80
  54. data/rails_plugin/ruby-prof/init.rb +0 -8
  55. data/rails_plugin/ruby-prof/lib/profiling.rb +0 -57
  56. data/test/measure_mode_test.rb +0 -79
  57. data/test/prime1.rb +0 -17
  58. data/test/prime2.rb +0 -26
  59. data/test/prime3.rb +0 -17
  60. data/test/start_test.rb +0 -24
  61. data/test/test_helper.rb +0 -55
  62. data/test/timing_test.rb +0 -133
@@ -0,0 +1,188 @@
1
+ /*
2
+ * Copyright (C) 2008 Shugo Maeda <shugo@ruby-lang.org>
3
+ * Charlie Savage <cfis@savagexi.com>
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
+ * SUCH DAMAGE.
26
+ */
27
+
28
+ /* ruby-prof tracks the time spent executing every method in ruby programming.
29
+ The main players are:
30
+
31
+ prof_result_t - Its one field, values, contains the overall results
32
+ thread_data_t - Stores data about a single thread.
33
+ prof_stack_t - The method call stack in a particular thread
34
+ prof_method_t - Profiling information for each method
35
+ prof_call_info_t - Keeps track a method's callers and callees.
36
+
37
+ The final resulut is a hash table of thread_data_t, keyed on the thread
38
+ id. Each thread has an hash a table of prof_method_t, keyed on the
39
+ method id. A hash table is used for quick look up when doing a profile.
40
+ However, it is exposed to Ruby as an array.
41
+
42
+ Each prof_method_t has two hash tables, parent and children, of prof_call_info_t.
43
+ These objects keep track of a method's callers (who called the method) and its
44
+ callees (who the method called). These are keyed the method id, but once again,
45
+ are exposed to Ruby as arrays. Each prof_call_into_t maintains a pointer to the
46
+ caller or callee method, thereby making it easy to navigate through the call
47
+ hierarchy in ruby - which is very helpful for creating call graphs.
48
+ */
49
+
50
+ /* #define DEBUG */
51
+
52
+ #ifndef RUBY_PROF_H
53
+ #define RUBY_PROF_H
54
+
55
+ #include <stdio.h>
56
+
57
+ #include <ruby.h>
58
+
59
+ #ifndef RUBY_VM
60
+ #include <node.h>
61
+ #include <st.h>
62
+ typedef rb_event_t rb_event_flag_t;
63
+ #define rb_sourcefile() (node ? node->nd_file : 0)
64
+ #define rb_sourceline() (node ? nd_line(node) : 0)
65
+ #endif
66
+
67
+ #include "version.h"
68
+
69
+ /* ================ Constants =================*/
70
+ #define INITIAL_STACK_SIZE 8
71
+ #define INITIAL_CALL_INFOS_SIZE 2
72
+
73
+
74
+ /* ================ Measurement =================*/
75
+ #ifdef HAVE_LONG_LONG
76
+ typedef unsigned LONG_LONG prof_measure_t;
77
+ #else
78
+ typedef unsigned long prof_measure_t;
79
+ #endif
80
+
81
+ #include "measure_process_time.h"
82
+ #include "measure_wall_time.h"
83
+ #include "measure_cpu_time.h"
84
+ #include "measure_allocations.h"
85
+ #include "measure_memory.h"
86
+ #include "measure_gc_runs.h"
87
+ #include "measure_gc_time.h"
88
+
89
+ static prof_measure_t (*get_measurement)() = measure_process_time;
90
+ static double (*convert_measurement)(prof_measure_t) = convert_process_time;
91
+
92
+ /* ================ DataTypes =================*/
93
+ static VALUE mProf;
94
+ static VALUE cResult;
95
+ static VALUE cMethodInfo;
96
+ static VALUE cCallInfo;
97
+
98
+ /* Profiling information for each method. */
99
+ typedef struct {
100
+ VALUE klass; /* The method's class. */
101
+ ID mid; /* The method id. */
102
+ int depth; /* The recursion depth. */
103
+ int key; /* Cache calculated key */
104
+ } prof_method_key_t;
105
+
106
+ struct prof_call_infos_t;
107
+
108
+ /* Profiling information for each method. */
109
+ typedef struct {
110
+ prof_method_key_t *key; /* Method key */
111
+ const char *source_file; /* The method's source file */
112
+ int line; /* The method's line number. */
113
+ int active; /* Is this recursion depth. */
114
+ struct prof_call_infos_t *call_infos; /* Call info objects for this method */
115
+ VALUE object; /* Cahced ruby object */
116
+ } prof_method_t;
117
+
118
+ /* Callers and callee information for a method. */
119
+ typedef struct prof_call_info_t {
120
+ prof_method_t *target; /* Use target instead of method to avoid conflict with Ruby method */
121
+ struct prof_call_info_t *parent;
122
+ st_table *call_infos;
123
+ int called;
124
+ prof_measure_t total_time;
125
+ prof_measure_t self_time;
126
+ prof_measure_t wait_time;
127
+ int line;
128
+ VALUE object;
129
+ VALUE children;
130
+ } prof_call_info_t;
131
+
132
+ /* Array of call_info objects */
133
+ typedef struct prof_call_infos_t {
134
+ prof_call_info_t **start;
135
+ prof_call_info_t **end;
136
+ prof_call_info_t **ptr;
137
+ VALUE object;
138
+ } prof_call_infos_t;
139
+
140
+
141
+ /* Temporary object that maintains profiling information
142
+ for active methods - there is one per method.*/
143
+ typedef struct {
144
+ /* Caching prof_method_t values significantly
145
+ increases performance. */
146
+ prof_call_info_t *call_info;
147
+ prof_measure_t start_time;
148
+ prof_measure_t wait_time;
149
+ prof_measure_t child_time;
150
+ unsigned int line;
151
+ } prof_frame_t;
152
+
153
+ /* Current stack of active methods.*/
154
+ typedef struct {
155
+ prof_frame_t *start;
156
+ prof_frame_t *end;
157
+ prof_frame_t *ptr;
158
+ } prof_stack_t;
159
+
160
+ /* Profiling information for a thread. */
161
+ typedef struct {
162
+ VALUE thread_id; /* Thread id */
163
+ st_table* method_table; /* Methods called in the thread */
164
+ prof_stack_t* stack; /* Active methods */
165
+ prof_measure_t last_switch; /* Point of last context switch */
166
+ } thread_data_t;
167
+
168
+ typedef struct {
169
+ VALUE threads;
170
+ } prof_result_t;
171
+
172
+
173
+ /* ================ Variables =================*/
174
+ static int measure_mode;
175
+ static st_table *threads_tbl = NULL;
176
+ static st_table *exclude_threads_tbl = NULL;
177
+
178
+ /* TODO - If Ruby become multi-threaded this has to turn into
179
+ a separate stack since this isn't thread safe! */
180
+ static thread_data_t* last_thread_data = NULL;
181
+
182
+
183
+ /* Forward declarations */
184
+ static VALUE prof_call_infos_wrap(prof_call_infos_t *call_infos);
185
+ static VALUE prof_call_info_wrap(prof_call_info_t *call_info);
186
+ static VALUE prof_method_wrap(prof_method_t *result);
187
+
188
+ #endif
@@ -0,0 +1,20 @@
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 10.00
3
+ # Visual Studio 2008
4
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ruby_prof", "ruby_prof.vcproj", "{DDB3E992-BF4B-4413-B061-288E40AECAD3}"
5
+ EndProject
6
+ Global
7
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
8
+ Debug|Win32 = Debug|Win32
9
+ Release|Win32 = Release|Win32
10
+ EndGlobalSection
11
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
12
+ {DDB3E992-BF4B-4413-B061-288E40AECAD3}.Debug|Win32.ActiveCfg = Debug|Win32
13
+ {DDB3E992-BF4B-4413-B061-288E40AECAD3}.Debug|Win32.Build.0 = Debug|Win32
14
+ {DDB3E992-BF4B-4413-B061-288E40AECAD3}.Release|Win32.ActiveCfg = Release|Win32
15
+ {DDB3E992-BF4B-4413-B061-288E40AECAD3}.Release|Win32.Build.0 = Release|Win32
16
+ EndGlobalSection
17
+ GlobalSection(SolutionProperties) = preSolution
18
+ HideSolutionNode = FALSE
19
+ EndGlobalSection
20
+ EndGlobal
@@ -0,0 +1,241 @@
1
+ <?xml version="1.0" encoding="Windows-1252"?>
2
+ <VisualStudioProject
3
+ ProjectType="Visual C++"
4
+ Version="9.00"
5
+ Name="ruby_prof"
6
+ ProjectGUID="{DDB3E992-BF4B-4413-B061-288E40AECAD3}"
7
+ RootNamespace="rubyprof"
8
+ Keyword="Win32Proj"
9
+ TargetFrameworkVersion="131072"
10
+ >
11
+ <Platforms>
12
+ <Platform
13
+ Name="Win32"
14
+ />
15
+ </Platforms>
16
+ <ToolFiles>
17
+ </ToolFiles>
18
+ <Configurations>
19
+ <Configuration
20
+ Name="Debug|Win32"
21
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
22
+ IntermediateDirectory="$(ConfigurationName)"
23
+ ConfigurationType="2"
24
+ CharacterSet="1"
25
+ >
26
+ <Tool
27
+ Name="VCPreBuildEventTool"
28
+ />
29
+ <Tool
30
+ Name="VCCustomBuildTool"
31
+ />
32
+ <Tool
33
+ Name="VCXMLDataGeneratorTool"
34
+ />
35
+ <Tool
36
+ Name="VCWebServiceProxyGeneratorTool"
37
+ />
38
+ <Tool
39
+ Name="VCMIDLTool"
40
+ />
41
+ <Tool
42
+ Name="VCCLCompilerTool"
43
+ Optimization="0"
44
+ AdditionalIncludeDirectories="&quot;C:\Development\ruby\lib\ruby\1.8\i386-mswin32&quot;"
45
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;RUBYPROF_EXPORTS"
46
+ MinimalRebuild="true"
47
+ BasicRuntimeChecks="3"
48
+ RuntimeLibrary="3"
49
+ UsePrecompiledHeader="0"
50
+ BrowseInformation="0"
51
+ WarningLevel="3"
52
+ Detect64BitPortabilityProblems="true"
53
+ DebugInformationFormat="4"
54
+ />
55
+ <Tool
56
+ Name="VCManagedResourceCompilerTool"
57
+ />
58
+ <Tool
59
+ Name="VCResourceCompilerTool"
60
+ />
61
+ <Tool
62
+ Name="VCPreLinkEventTool"
63
+ />
64
+ <Tool
65
+ Name="VCLinkerTool"
66
+ AdditionalDependencies="msvcrt-ruby18.lib"
67
+ OutputFile="C:\Development\ruby\lib\ruby\gems\1.8\gems\ruby-prof-0.7.0-x86-mswin32-60\lib\$(ProjectName).so"
68
+ LinkIncremental="2"
69
+ AdditionalLibraryDirectories="C:\Development\ruby\lib"
70
+ GenerateDebugInformation="true"
71
+ SubSystem="2"
72
+ RandomizedBaseAddress="1"
73
+ DataExecutionPrevention="0"
74
+ TargetMachine="1"
75
+ />
76
+ <Tool
77
+ Name="VCALinkTool"
78
+ />
79
+ <Tool
80
+ Name="VCManifestTool"
81
+ />
82
+ <Tool
83
+ Name="VCXDCMakeTool"
84
+ />
85
+ <Tool
86
+ Name="VCBscMakeTool"
87
+ />
88
+ <Tool
89
+ Name="VCFxCopTool"
90
+ />
91
+ <Tool
92
+ Name="VCAppVerifierTool"
93
+ />
94
+ <Tool
95
+ Name="VCPostBuildEventTool"
96
+ />
97
+ </Configuration>
98
+ <Configuration
99
+ Name="Release|Win32"
100
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
101
+ IntermediateDirectory="$(ConfigurationName)"
102
+ ConfigurationType="2"
103
+ CharacterSet="1"
104
+ WholeProgramOptimization="1"
105
+ >
106
+ <Tool
107
+ Name="VCPreBuildEventTool"
108
+ />
109
+ <Tool
110
+ Name="VCCustomBuildTool"
111
+ />
112
+ <Tool
113
+ Name="VCXMLDataGeneratorTool"
114
+ />
115
+ <Tool
116
+ Name="VCWebServiceProxyGeneratorTool"
117
+ />
118
+ <Tool
119
+ Name="VCMIDLTool"
120
+ />
121
+ <Tool
122
+ Name="VCCLCompilerTool"
123
+ AdditionalIncludeDirectories="C:\Development\ruby\lib\ruby\1.8\i386-mswin32"
124
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;RUBYPROF_EXPORTS"
125
+ RuntimeLibrary="2"
126
+ UsePrecompiledHeader="0"
127
+ WarningLevel="3"
128
+ Detect64BitPortabilityProblems="true"
129
+ DebugInformationFormat="3"
130
+ />
131
+ <Tool
132
+ Name="VCManagedResourceCompilerTool"
133
+ />
134
+ <Tool
135
+ Name="VCResourceCompilerTool"
136
+ />
137
+ <Tool
138
+ Name="VCPreLinkEventTool"
139
+ />
140
+ <Tool
141
+ Name="VCLinkerTool"
142
+ AdditionalDependencies="msvcrt-ruby18.lib"
143
+ OutputFile="$(OutDir)\$(ProjectName).so"
144
+ LinkIncremental="1"
145
+ AdditionalLibraryDirectories="C:\Development\ruby\lib"
146
+ GenerateDebugInformation="true"
147
+ SubSystem="2"
148
+ OptimizeReferences="2"
149
+ EnableCOMDATFolding="2"
150
+ RandomizedBaseAddress="1"
151
+ DataExecutionPrevention="0"
152
+ TargetMachine="1"
153
+ />
154
+ <Tool
155
+ Name="VCALinkTool"
156
+ />
157
+ <Tool
158
+ Name="VCManifestTool"
159
+ />
160
+ <Tool
161
+ Name="VCXDCMakeTool"
162
+ />
163
+ <Tool
164
+ Name="VCBscMakeTool"
165
+ />
166
+ <Tool
167
+ Name="VCFxCopTool"
168
+ />
169
+ <Tool
170
+ Name="VCAppVerifierTool"
171
+ />
172
+ <Tool
173
+ Name="VCPostBuildEventTool"
174
+ />
175
+ </Configuration>
176
+ </Configurations>
177
+ <References>
178
+ </References>
179
+ <Files>
180
+ <Filter
181
+ Name="Source Files"
182
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
183
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
184
+ >
185
+ <File
186
+ RelativePath="..\ruby_prof.c"
187
+ >
188
+ </File>
189
+ </Filter>
190
+ <Filter
191
+ Name="Header Files"
192
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
193
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
194
+ >
195
+ <File
196
+ RelativePath="..\measure_allocations.h"
197
+ >
198
+ </File>
199
+ <File
200
+ RelativePath="..\measure_cpu_time.h"
201
+ >
202
+ </File>
203
+ <File
204
+ RelativePath="..\measure_gc_runs.h"
205
+ >
206
+ </File>
207
+ <File
208
+ RelativePath="..\measure_gc_time.h"
209
+ >
210
+ </File>
211
+ <File
212
+ RelativePath="..\measure_memory.h"
213
+ >
214
+ </File>
215
+ <File
216
+ RelativePath="..\measure_process_time.h"
217
+ >
218
+ </File>
219
+ <File
220
+ RelativePath="..\measure_wall_time.h"
221
+ >
222
+ </File>
223
+ <File
224
+ RelativePath="..\ruby_prof.h"
225
+ >
226
+ </File>
227
+ <File
228
+ RelativePath="..\version.h"
229
+ >
230
+ </File>
231
+ </Filter>
232
+ <Filter
233
+ Name="Resource Files"
234
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
235
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
236
+ >
237
+ </Filter>
238
+ </Files>
239
+ <Globals>
240
+ </Globals>
241
+ </VisualStudioProject>