ruby-prof 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGES +30 -0
  2. data/README +65 -25
  3. data/Rakefile +33 -32
  4. data/bin/ruby-prof +100 -83
  5. data/examples/graph.html +65 -69
  6. data/ext/measure_allocations.h +43 -0
  7. data/ext/measure_cpu_time.h +138 -0
  8. data/ext/measure_process_time.h +41 -0
  9. data/ext/measure_wall_time.h +42 -0
  10. data/ext/ruby_prof.c +737 -653
  11. data/lib/ruby-prof.rb +41 -38
  12. data/lib/ruby-prof/abstract_printer.rb +42 -0
  13. data/lib/ruby-prof/call_tree_printer.rb +69 -0
  14. data/lib/ruby-prof/flat_printer.rb +78 -75
  15. data/lib/ruby-prof/graph_html_printer.rb +241 -228
  16. data/lib/ruby-prof/graph_printer.rb +160 -141
  17. data/lib/ruby-prof/profile_test_case.rb +80 -0
  18. data/lib/ruby-prof/rails_plugin/ruby-prof/init.rb +6 -0
  19. data/lib/ruby-prof/rails_plugin/ruby-prof/lib/profiling.rb +52 -0
  20. data/lib/ruby-prof/task.rb +147 -0
  21. data/test/basic_test.rb +65 -35
  22. data/test/duplicate_names_test.rb +20 -24
  23. data/test/gc.log +5 -0
  24. data/test/measure_mode_test.rb +79 -0
  25. data/test/module_test.rb +31 -18
  26. data/test/no_method_class_test.rb +14 -0
  27. data/test/prime1.rb +17 -0
  28. data/test/prime2.rb +26 -0
  29. data/test/prime3.rb +17 -0
  30. data/test/prime_test.rb +10 -10
  31. data/test/printers_test.rb +14 -12
  32. data/test/profile_unit_test.rb +24 -0
  33. data/test/recursive_test.rb +105 -17
  34. data/test/singleton_test.rb +38 -0
  35. data/test/start_test.rb +24 -0
  36. data/test/test_helper.rb +33 -29
  37. data/test/test_suite.rb +10 -2
  38. data/test/thread_test.rb +123 -17
  39. data/test/timing_test.rb +70 -29
  40. metadata +28 -30
  41. data/doc/created.rid +0 -1
  42. data/doc/files/LICENSE.html +0 -0
  43. data/doc/files/README.html +0 -376
  44. data/doc/files/bin/ruby-prof.html +0 -143
  45. data/doc/files/examples/flat_txt.html +0 -179
  46. data/doc/files/examples/graph_html.html +0 -948
  47. data/doc/files/examples/graph_txt.html +0 -297
  48. data/doc/files/ext/ruby_prof_c.html +0 -101
  49. data/doc/files/lib/ruby-prof/flat_printer_rb.html +0 -101
  50. data/doc/files/lib/ruby-prof/graph_html_printer_rb.html +0 -108
  51. data/doc/files/lib/ruby-prof/graph_printer_rb.html +0 -101
  52. data/doc/files/lib/ruby-prof/profiletask_rb.html +0 -109
  53. data/doc/files/lib/ruby-prof_rb.html +0 -111
  54. data/doc/files/lib/unprof_rb.html +0 -108
  55. data/doc/rdoc-style.css +0 -208
  56. data/lib/ruby-prof/profiletask.rb +0 -150
  57. data/test/clock_mode_test.rb +0 -73
@@ -1,208 +0,0 @@
1
-
2
- body {
3
- font-family: Verdana,Arial,Helvetica,sans-serif;
4
- font-size: 90%;
5
- margin: 0;
6
- margin-left: 40px;
7
- padding: 0;
8
- background: white;
9
- }
10
-
11
- h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
- h1 { font-size: 150%; }
13
- h2,h3,h4 { margin-top: 1em; }
14
-
15
- a { background: #eef; color: #039; text-decoration: none; }
16
- a:hover { background: #039; color: #eef; }
17
-
18
- /* Override the base stylesheet's Anchor inside a table cell */
19
- td > a {
20
- background: transparent;
21
- color: #039;
22
- text-decoration: none;
23
- }
24
-
25
- /* and inside a section title */
26
- .section-title > a {
27
- background: transparent;
28
- color: #eee;
29
- text-decoration: none;
30
- }
31
-
32
- /* === Structural elements =================================== */
33
-
34
- div#index {
35
- margin: 0;
36
- margin-left: -40px;
37
- padding: 0;
38
- font-size: 90%;
39
- }
40
-
41
-
42
- div#index a {
43
- margin-left: 0.7em;
44
- }
45
-
46
- div#index .section-bar {
47
- margin-left: 0px;
48
- padding-left: 0.7em;
49
- background: #ccc;
50
- font-size: small;
51
- }
52
-
53
-
54
- div#classHeader, div#fileHeader {
55
- width: auto;
56
- color: white;
57
- padding: 0.5em 1.5em 0.5em 1.5em;
58
- margin: 0;
59
- margin-left: -40px;
60
- border-bottom: 3px solid #006;
61
- }
62
-
63
- div#classHeader a, div#fileHeader a {
64
- background: inherit;
65
- color: white;
66
- }
67
-
68
- div#classHeader td, div#fileHeader td {
69
- background: inherit;
70
- color: white;
71
- }
72
-
73
-
74
- div#fileHeader {
75
- background: #057;
76
- }
77
-
78
- div#classHeader {
79
- background: #048;
80
- }
81
-
82
-
83
- .class-name-in-header {
84
- font-size: 180%;
85
- font-weight: bold;
86
- }
87
-
88
-
89
- div#bodyContent {
90
- padding: 0 1.5em 0 1.5em;
91
- }
92
-
93
- div#description {
94
- padding: 0.5em 1.5em;
95
- background: #efefef;
96
- border: 1px dotted #999;
97
- }
98
-
99
- div#description h1,h2,h3,h4,h5,h6 {
100
- color: #125;;
101
- background: transparent;
102
- }
103
-
104
- div#validator-badges {
105
- text-align: center;
106
- }
107
- div#validator-badges img { border: 0; }
108
-
109
- div#copyright {
110
- color: #333;
111
- background: #efefef;
112
- font: 0.75em sans-serif;
113
- margin-top: 5em;
114
- margin-bottom: 0;
115
- padding: 0.5em 2em;
116
- }
117
-
118
-
119
- /* === Classes =================================== */
120
-
121
- table.header-table {
122
- color: white;
123
- font-size: small;
124
- }
125
-
126
- .type-note {
127
- font-size: small;
128
- color: #DEDEDE;
129
- }
130
-
131
- .xxsection-bar {
132
- background: #eee;
133
- color: #333;
134
- padding: 3px;
135
- }
136
-
137
- .section-bar {
138
- color: #333;
139
- border-bottom: 1px solid #999;
140
- margin-left: -20px;
141
- }
142
-
143
-
144
- .section-title {
145
- background: #79a;
146
- color: #eee;
147
- padding: 3px;
148
- margin-top: 2em;
149
- margin-left: -30px;
150
- border: 1px solid #999;
151
- }
152
-
153
- .top-aligned-row { vertical-align: top }
154
- .bottom-aligned-row { vertical-align: bottom }
155
-
156
- /* --- Context section classes ----------------------- */
157
-
158
- .context-row { }
159
- .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
- .context-item-value { font-size: small; color: #448; }
161
- .context-item-desc { color: #333; padding-left: 2em; }
162
-
163
- /* --- Method classes -------------------------- */
164
- .method-detail {
165
- background: #efefef;
166
- padding: 0;
167
- margin-top: 0.5em;
168
- margin-bottom: 1em;
169
- border: 1px dotted #ccc;
170
- }
171
- .method-heading {
172
- color: black;
173
- background: #ccc;
174
- border-bottom: 1px solid #666;
175
- padding: 0.2em 0.5em 0 0.5em;
176
- }
177
- .method-signature { color: black; background: inherit; }
178
- .method-name { font-weight: bold; }
179
- .method-args { font-style: italic; }
180
- .method-description { padding: 0 0.5em 0 0.5em; }
181
-
182
- /* --- Source code sections -------------------- */
183
-
184
- a.source-toggle { font-size: 90%; }
185
- div.method-source-code {
186
- background: #262626;
187
- color: #ffdead;
188
- margin: 1em;
189
- padding: 0.5em;
190
- border: 1px dashed #999;
191
- overflow: hidden;
192
- }
193
-
194
- div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
-
196
- /* --- Ruby keyword styles --------------------- */
197
-
198
- .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
-
200
- .ruby-constant { color: #7fffd4; background: transparent; }
201
- .ruby-keyword { color: #00ffff; background: transparent; }
202
- .ruby-ivar { color: #eedd82; background: transparent; }
203
- .ruby-operator { color: #00ffee; background: transparent; }
204
- .ruby-identifier { color: #ffdead; background: transparent; }
205
- .ruby-node { color: #ffa07a; background: transparent; }
206
- .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
- .ruby-regexp { color: #ffa07a; background: transparent; }
208
- .ruby-value { color: #7fffd4; background: transparent; }
@@ -1,150 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rake'
4
- require 'rake/tasklib'
5
-
6
- module RubyProf
7
-
8
- # Create a profile task. All of the options provided by
9
- # the Rake:TestTask are supported except the loader
10
- # which is set to ruby-prof. For detailed information
11
- # please refer to the Rake:TestTask documentation.
12
- #
13
- # ruby-prof specific options include:
14
- #
15
- # output_dir - For each file specified an output
16
- # file with profile information will be
17
- # written to the output directory.
18
- # By default, the output directory is
19
- # called "profile" and is created underneath
20
- # the current working directory.
21
- #
22
- # printer - Specifies the output printer. Valid values include
23
- # :flat, :graph, and :graph_html.
24
- #
25
- # min_percent - Methods that take less than the specified percent
26
- # will not be written out.
27
- #
28
- # Example:
29
- #
30
- # require 'ruby-prof/task'
31
- #
32
- # ruby-prof::RubyProfTask.new do |t|
33
- # t.test_files = FileList['test/test*.rb']
34
- # t.output_dir = "c:/temp"
35
- # t.printer = :graph
36
- # t.min_percent = 10
37
- # end
38
- #
39
- # If the task is invoked with a "test=filename" command line option,
40
- # then the list of test files will be overridden to include only the
41
- # filename specified on the command line. This provides an easy way
42
- # to run just one test.
43
- #
44
- # If rake is invoked with a "options=options" command line option,
45
- # then the given options are passed to ruby-prof.
46
- #
47
- # If rake is invoked with a "ruby-profPATH=path/to/ruby-prof" command line option,
48
- # then the given ruby-prof executable will be used; otherwise the one in your
49
- # PATH will be used.
50
- #
51
- # Examples:
52
- #
53
- # rake ruby-prof # profiles all unit tests
54
- # rake ruby-prof TEST=just_one_file.rb # profiles one unit test
55
- # rake ruby-prof PATTERN=*.rb # profiles all files
56
-
57
- class ProfileTask < Rake::TestTask
58
- attr_writer :output_dir
59
- attr_writer :min_percent
60
- attr_writer :printer
61
-
62
- def initialize(name=:profile)
63
- @name = name
64
- @libs = ["lib"]
65
- @pattern = nil
66
- @options = Array.new
67
- @test_files = nil
68
- @verbose = false
69
- @warning = false
70
- @loader = :ruby_prof
71
- @ruby_opts = []
72
- @output_dir = File.join(Dir.getwd, "profile")
73
- @printer = :graph
74
- @min_percent = 0
75
- yield self if block_given?
76
- @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
77
- define
78
- end
79
-
80
- # Create the tasks defined by this task lib.
81
- def define
82
- create_output_directory
83
-
84
- lib_path = @libs.join(File::PATH_SEPARATOR)
85
- desc "Profile" + (@name==:profile ? "" : " for #{@name}")
86
-
87
- task @name do
88
- @ruby_opts.unshift( "-I#{lib_path}" )
89
- @ruby_opts.unshift( "-w" ) if @warning
90
- @ruby_opts.push("-S ruby-prof")
91
- @ruby_opts.push("--printer #{@printer}")
92
- @ruby_opts.push("--min_percent #{@min_percent}")
93
-
94
- file_list.each do |file_path|
95
- run_script(file_path)
96
- end
97
- end
98
- self
99
- end
100
-
101
- # Run script
102
- def run_script(script_path)
103
- run_code = ''
104
- RakeFileUtils.verbose(@verbose) do
105
- file_name = File.basename(script_path, File.extname(script_path))
106
- case @printer
107
- when :flat, :graph
108
- file_name += ".txt"
109
- when :graph_html
110
- file_name += ".html"
111
- else
112
- file_name += ".txt"
113
- end
114
-
115
- output_file_path = File.join(output_directory, file_name)
116
-
117
- command_line = @ruby_opts.join(" ") +
118
- " --file=" + output_file_path +
119
- " " + script_path
120
-
121
- puts "ruby " + command_line
122
- # We have to catch the exeption to continue on. However,
123
- # the error message will have been output to STDERR
124
- # already by the time we get here so we don't have to
125
- # do that again
126
- begin
127
- ruby command_line
128
- rescue
129
- end
130
- puts ""
131
- puts ""
132
- end
133
- end
134
-
135
- def output_directory
136
- File.expand_path(@output_dir)
137
- end
138
-
139
- def create_output_directory
140
- if not File.exist?(output_directory)
141
- Dir.mkdir(output_directory)
142
- end
143
- end
144
-
145
- def option_list # :nodoc:
146
- ENV['TESTOPTS'] || @options.join(" ") || ""
147
- end
148
- end
149
- end
150
-
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'ruby-prof'
5
- require 'test_helper'
6
- require 'prime'
7
-
8
-
9
- # -- Tests ----
10
- class ClockModeTest < Test::Unit::TestCase
11
- def test_clock
12
- return
13
- RubyProf::clock_mode = RubyProf::PROCESS_TIME
14
- assert_equal(RubyProf::PROCESS_TIME, RubyProf::clock_mode)
15
- result = RubyProf.profile do
16
- run_primes
17
- end
18
-
19
- print_results(result)
20
-
21
- result.threads.values.each do |methods|
22
- methods.values.each do |method|
23
- check_parent_times(method)
24
- check_parent_calls(method)
25
- check_child_times(method)
26
- end
27
- end
28
- end
29
-
30
- def test_gettimeofday
31
- return
32
- RubyProf::clock_mode = RubyProf::WALL_TIME
33
- assert_equal(RubyProf::WALL_TIME, RubyProf::clock_mode)
34
- result = RubyProf.profile do
35
- run_primes
36
- end
37
-
38
- print_results(result)
39
-
40
- result.threads.values.each do |methods|
41
- methods.values.each do |method|
42
- check_parent_times(method)
43
- check_parent_calls(method)
44
- check_child_times(method)
45
- end
46
- end
47
- end
48
-
49
- def test_cpu
50
- #return
51
- RubyProf::clock_mode = RubyProf::CPU_TIME
52
- assert_equal(RubyProf::CPU, RubyProf::clock_mode)
53
- result = RubyProf.profile do
54
- run_primes
55
- end
56
-
57
- print_results(result)
58
-
59
- result.threads.values.each do |methods|
60
- methods.values.each do |method|
61
- check_parent_times(method)
62
- check_parent_calls(method)
63
- check_child_times(method)
64
- end
65
- end
66
- end
67
-
68
- def test_invalid
69
- assert_raise(ArgumentError) do
70
- RubyProf::clock_mode = 7777
71
- end
72
- end
73
- end