ruby-prof 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README +220 -220
  2. data/Rakefile +3 -3
  3. data/doc/created.rid +1 -1
  4. data/doc/files/LICENSE.html +0 -142
  5. data/doc/files/README.html +2 -2
  6. data/doc/files/examples/flat_txt.html +8 -16
  7. data/doc/files/examples/graph_txt.html +10 -18
  8. data/doc/files/ext/ruby_prof_c.html +1 -1
  9. data/doc/files/lib/ruby-prof/flat_printer_rb.html +1 -1
  10. data/doc/files/lib/ruby-prof/graph_html_printer_rb.html +1 -1
  11. data/doc/files/lib/ruby-prof/graph_printer_rb.html +1 -1
  12. data/examples/flat.txt +55 -57
  13. data/examples/graph.html +827 -827
  14. data/examples/graph.txt +170 -171
  15. data/ext/ruby_prof.c +35 -20
  16. data/lib/ruby-prof/flat_printer.rb +8 -9
  17. data/lib/ruby-prof/graph_html_printer.rb +3 -2
  18. data/lib/ruby-prof/graph_printer.rb +4 -5
  19. data/test/basic_test.rb +148 -141
  20. data/test/clock_mode_test.rb +72 -72
  21. data/test/duplicate_names_test.rb +37 -0
  22. data/test/module_test.rb +45 -45
  23. data/test/prime.rb +58 -58
  24. data/test/prime_test.rb +23 -23
  25. data/test/printers_test.rb +27 -27
  26. data/test/recursive_test.rb +55 -55
  27. data/test/test_helper.rb +45 -45
  28. data/test/test_suite.rb +10 -9
  29. data/test/thread_test.rb +32 -32
  30. data/test/timing_test.rb +90 -90
  31. metadata +3 -16
  32. data/doc/classes/RubyProf.html +0 -563
  33. data/doc/classes/RubyProf/CallInfo.html +0 -274
  34. data/doc/classes/RubyProf/FlatPrinter.html +0 -207
  35. data/doc/classes/RubyProf/GraphHtmlPrinter.html +0 -538
  36. data/doc/classes/RubyProf/GraphPrinter.html +0 -240
  37. data/doc/classes/RubyProf/MethodInfo.html +0 -556
  38. data/doc/classes/RubyProf/ProfileTask.html +0 -395
  39. data/doc/classes/RubyProf/Result.html +0 -234
  40. data/doc/fr_class_index.html +0 -34
  41. data/doc/fr_file_index.html +0 -39
  42. data/doc/fr_method_index.html +0 -67
  43. data/doc/index.html +0 -24
  44. data/test/test.rb +0 -3
@@ -168,8 +168,9 @@ module RubyProf
168
168
  <th>Name</th>
169
169
  </tr>
170
170
 
171
- <% methods = methods.values.sort.reverse %>
172
- <% for method in methods %>
171
+ <% methods.sort.reverse.each do |pair| %>
172
+ <% name = pair[0] %>
173
+ <% method = pair[1] %>
173
174
  <% method_total_percent = self.total_percent(method) %>
174
175
  <% next if method_total_percent < @min_percent %>
175
176
  <% method_self_percent = self.self_percent(method) %>
@@ -63,11 +63,10 @@ module RubyProf
63
63
 
64
64
  print_heading(thread_id)
65
65
 
66
- # Get methods and sort by time
67
- methods = methods.values.sort.reverse
68
-
69
66
  # Print each method
70
- methods.each do |method|
67
+ methods.sort.reverse.each do |pair|
68
+ name = pair[0]
69
+ method = pair[1]
71
70
  total_percentage = (method.total_time/total_time) * 100
72
71
  self_percentage = (method.self_time/total_time) * 100
73
72
 
@@ -84,7 +83,7 @@ module RubyProf
84
83
  @output << sprintf("%#{TIME_WIDTH}.2f", method.self_time)
85
84
  @output << sprintf("%#{TIME_WIDTH}.2f", method.children_time)
86
85
  @output << sprintf("%#{CALL_WIDTH}i", method.called)
87
- @output << sprintf(" %s", method.name)
86
+ @output << sprintf(" %s", name)
88
87
  @output << "\n"
89
88
 
90
89
  print_children(thread_id, method)
data/test/basic_test.rb CHANGED
@@ -1,141 +1,148 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'ruby-prof'
5
- require 'test_helper'
6
-
7
- class C1
8
- def C1.hello
9
- end
10
-
11
- def hello
12
- end
13
- end
14
-
15
- module M1
16
- def hello
17
- end
18
- end
19
-
20
- class C2
21
- include M1
22
- extend M1
23
- end
24
-
25
- class C3
26
- def hello
27
- end
28
- end
29
-
30
- module M4
31
- def hello
32
- end
33
- end
34
-
35
- module M5
36
- include M4
37
- def goodbye
38
- hello
39
- end
40
- end
41
-
42
- class C6
43
- include M5
44
- def test
45
- goodbye
46
- end
47
- end
48
-
49
- class BasicTest < Test::Unit::TestCase
50
- def test_double_profile
51
- RubyProf.start
52
- assert_raise(RuntimeError) do
53
- RubyProf.start
54
- end
55
-
56
- assert_raise(RuntimeError) do
57
- RubyProf.profile do
58
- puts 1
59
- end
60
- end
61
- RubyProf.stop
62
- end
63
-
64
-
65
- def test_no_block
66
- assert_raise(ArgumentError) do
67
- RubyProf.profile
68
- end
69
- end
70
-
71
- def test_class_and_instance_methods
72
- result = RubyProf.profile do
73
- C1.hello
74
- C1.new.hello
75
- end
76
-
77
- methods = result.threads.values.first
78
-
79
- # Length should be 6:
80
- # 1 top level,
81
- # 1 Class.new
82
- # 1 Class:Object allocate
83
- # 1 for Object.initialize
84
- # 1 for Class hello
85
- # 1 for Object hello
86
- assert_equal(6, methods.length)
87
-
88
- # Check class method
89
- method1 = methods['<Class::C1>#hello']
90
- assert_not_nil(method1)
91
-
92
- # Check instance method
93
- method1 = methods['C1#hello']
94
- assert_not_nil(method1)
95
- end
96
-
97
- def test_module_methods
98
- result = RubyProf.profile do
99
- C2.hello
100
- C2.new.hello
101
- end
102
-
103
- methods = result.threads.values.first
104
-
105
- # Length should be 5:
106
- # 1 top level,
107
- # 1 Class.new
108
- # 1 Class:Object allocate
109
- # 1 for Object.initialize
110
- # 1 for hello
111
- assert_equal(5, methods.length)
112
-
113
- # Check class method
114
- method1 = methods['M1#hello']
115
- assert_not_nil(method1)
116
- assert_equal(2, method1.called)
117
- end
118
-
119
- def test_singleton
120
- c3 = C3.new
121
-
122
- class << c3
123
- def hello
124
- end
125
- end
126
-
127
- result = RubyProf.profile do
128
- c3.hello
129
- end
130
-
131
- methods = result.threads.values.first
132
-
133
- # Length should be 2 - one for top level
134
- # and one for the singleton method.
135
- assert_equal(2, methods.length)
136
-
137
- # Check singleton method
138
- method1 = methods['<Object::C3>#hello']
139
- assert_not_nil(method1)
140
- end
141
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'test_helper'
6
+
7
+ class C1
8
+ def C1.hello
9
+ end
10
+
11
+ def hello
12
+ end
13
+ end
14
+
15
+ module M1
16
+ def hello
17
+ end
18
+ end
19
+
20
+ class C2
21
+ include M1
22
+ extend M1
23
+ end
24
+
25
+ class C3
26
+ def hello
27
+ end
28
+ end
29
+
30
+ module M4
31
+ def hello
32
+ end
33
+ end
34
+
35
+ module M5
36
+ include M4
37
+ def goodbye
38
+ hello
39
+ end
40
+ end
41
+
42
+ class C6
43
+ include M5
44
+ def test
45
+ goodbye
46
+ end
47
+ end
48
+
49
+ class BasicTest < Test::Unit::TestCase
50
+ def test_running
51
+ assert(!RubyProf.running?)
52
+ RubyProf.start
53
+ assert(RubyProf.running?)
54
+ RubyProf.stop
55
+ assert(!RubyProf.running?)
56
+ end
57
+
58
+ def test_double_profile
59
+ RubyProf.start
60
+ assert_raise(RuntimeError) do
61
+ RubyProf.start
62
+ end
63
+
64
+ assert_raise(RuntimeError) do
65
+ RubyProf.profile do
66
+ puts 1
67
+ end
68
+ end
69
+ RubyProf.stop
70
+ end
71
+
72
+ def test_no_block
73
+ assert_raise(ArgumentError) do
74
+ RubyProf.profile
75
+ end
76
+ end
77
+
78
+ def test_class_and_instance_methods
79
+ result = RubyProf.profile do
80
+ C1.hello
81
+ C1.new.hello
82
+ end
83
+
84
+ methods = result.threads.values.first
85
+
86
+ # Length should be 6:
87
+ # 1 top level,
88
+ # 1 Class.new
89
+ # 1 Class:Object allocate
90
+ # 1 for Object.initialize
91
+ # 1 for Class hello
92
+ # 1 for Object hello
93
+ assert_equal(6, methods.length)
94
+
95
+ # Check class method
96
+ method1 = methods['<Class::C1>#hello']
97
+ assert_not_nil(method1)
98
+
99
+ # Check instance method
100
+ method1 = methods['C1#hello']
101
+ assert_not_nil(method1)
102
+ end
103
+
104
+ def test_module_methods
105
+ result = RubyProf.profile do
106
+ C2.hello
107
+ C2.new.hello
108
+ end
109
+
110
+ methods = result.threads.values.first
111
+
112
+ # Length should be 5:
113
+ # 1 top level,
114
+ # 1 Class.new
115
+ # 1 Class:Object allocate
116
+ # 1 for Object.initialize
117
+ # 1 for hello
118
+ assert_equal(5, methods.length)
119
+
120
+ # Check class method
121
+ method1 = methods['M1#hello']
122
+ assert_not_nil(method1)
123
+ assert_equal(2, method1.called)
124
+ end
125
+
126
+ def test_singleton
127
+ c3 = C3.new
128
+
129
+ class << c3
130
+ def hello
131
+ end
132
+ end
133
+
134
+ result = RubyProf.profile do
135
+ c3.hello
136
+ end
137
+
138
+ methods = result.threads.values.first
139
+
140
+ # Length should be 2 - one for top level
141
+ # and one for the singleton method.
142
+ assert_equal(2, methods.length)
143
+
144
+ # Check singleton method
145
+ method1 = methods['<Object::C3>#hello']
146
+ assert_not_nil(method1)
147
+ end
148
+ end
@@ -1,73 +1,73 @@
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
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
73
  end