ruby-prof 0.6.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/CHANGES +116 -0
  2. data/LICENSE +23 -0
  3. data/README +307 -0
  4. data/Rakefile +141 -0
  5. data/bin/ruby-prof +192 -0
  6. data/examples/flat.txt +55 -0
  7. data/examples/graph.html +823 -0
  8. data/examples/graph.txt +170 -0
  9. data/ext/extconf.rb +21 -0
  10. data/ext/extconf.rb.rej +13 -0
  11. data/ext/measure_allocations.h +43 -0
  12. data/ext/measure_cpu_time.h +138 -0
  13. data/ext/measure_memory.h +42 -0
  14. data/ext/measure_process_time.h +41 -0
  15. data/ext/measure_wall_time.h +42 -0
  16. data/ext/ruby_prof.c +1628 -0
  17. data/lib/ruby-prof.rb +43 -0
  18. data/lib/ruby-prof/abstract_printer.rb +42 -0
  19. data/lib/ruby-prof/call_tree_printer.rb +76 -0
  20. data/lib/ruby-prof/call_tree_printer.rb.rej +27 -0
  21. data/lib/ruby-prof/flat_printer.rb +79 -0
  22. data/lib/ruby-prof/graph_html_printer.rb +255 -0
  23. data/lib/ruby-prof/graph_printer.rb +163 -0
  24. data/lib/ruby-prof/profile_test_case.rb +80 -0
  25. data/lib/ruby-prof/task.rb +147 -0
  26. data/lib/ruby_prof.so +0 -0
  27. data/lib/unprof.rb +8 -0
  28. data/rails_plugin/ruby-prof/init.rb +8 -0
  29. data/rails_plugin/ruby-prof/lib/profiling.rb +57 -0
  30. data/test/basic_test.rb +190 -0
  31. data/test/duplicate_names_test.rb +33 -0
  32. data/test/line_number_test.rb +69 -0
  33. data/test/measure_mode_test.rb +79 -0
  34. data/test/module_test.rb +57 -0
  35. data/test/no_method_class_test.rb +14 -0
  36. data/test/prime.rb +60 -0
  37. data/test/prime1.rb +17 -0
  38. data/test/prime2.rb +26 -0
  39. data/test/prime3.rb +17 -0
  40. data/test/prime_test.rb +24 -0
  41. data/test/printers_test.rb +74 -0
  42. data/test/profile_unit_test.rb +24 -0
  43. data/test/recursive_test.rb +144 -0
  44. data/test/singleton_test.rb +38 -0
  45. data/test/start_test.rb +24 -0
  46. data/test/test_helper.rb +55 -0
  47. data/test/test_suite.rb +19 -0
  48. data/test/thread_test.rb +135 -0
  49. data/test/timing_test.rb +133 -0
  50. metadata +116 -0
@@ -0,0 +1,55 @@
1
+ def print_results(result)
2
+ printer = RubyProf::FlatPrinter.new(result)
3
+ printer.print(STDOUT)
4
+
5
+ STDOUT << "\n" * 2
6
+
7
+ printer = RubyProf::GraphPrinter.new(result)
8
+ printer.print(STDOUT)
9
+ end
10
+
11
+ def check_parent_times(method)
12
+ return if method.parents.length == 0
13
+
14
+ parents_self_time = method.parents.inject(0) do |sum, call_info|
15
+ sum + call_info.self_time
16
+ end
17
+
18
+ assert_in_delta(method.self_time, parents_self_time, 0.01,
19
+ "Invalid parent times for method #{method.full_name}")
20
+
21
+ parents_wait_time = method.parents.inject(0) do |sum, call_info|
22
+ sum + call_info.wait_time
23
+ end
24
+
25
+ assert_in_delta(method.wait_time, parents_wait_time, 0.01, method.full_name)
26
+
27
+ parents_children_time = method.parents.inject(0) do |sum, call_info|
28
+ sum + call_info.children_time
29
+ end
30
+
31
+ assert_in_delta(method.children_time, parents_children_time, 0.01,
32
+ "Invalid child times for method #{method.full_name}")
33
+ end
34
+
35
+ def check_parent_calls(method)
36
+ return if method.parents.length == 0
37
+
38
+ parent_calls = method.parents.inject(0) do |sum, call_info|
39
+ sum + call_info.called
40
+ end
41
+
42
+ assert_equal(method.called, parent_calls,
43
+ "Invalid parent calls for method #{method.full_name}")
44
+ end
45
+
46
+ def check_child_times(method)
47
+ return if method.children.length == 0
48
+
49
+ children_total_time = method.children.inject(0) do |sum, call_info|
50
+ sum + call_info.total_time
51
+ end
52
+
53
+ assert_in_delta(method.children_time, children_total_time, 0.01,
54
+ "Invalid child time for method #{method.full_name}")
55
+ end
@@ -0,0 +1,19 @@
1
+ # file ts_dbaccess.rb
2
+ require 'test/unit'
3
+ require 'basic_test'
4
+ require 'duplicate_names_test'
5
+ require 'line_number_test'
6
+ require 'measure_mode_test'
7
+ require 'module_test'
8
+ require 'no_method_class_test'
9
+ require 'prime_test'
10
+ require 'printers_test'
11
+ require 'recursive_test'
12
+ require 'singleton_test'
13
+ require 'thread_test'
14
+ require 'timing_test'
15
+
16
+ # Can't use this one here cause it breaks
17
+ # the rest of the unit tets (Ruby Prof gets
18
+ # started twice).
19
+ #require 'profile_unit_test'
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'timeout'
6
+ require 'test_helper'
7
+
8
+ # Need to use wall time for this test due to the sleep calls
9
+ RubyProf::measure_mode = RubyProf::WALL_TIME
10
+
11
+ # -- Tests ----
12
+ class ThreadTest < Test::Unit::TestCase
13
+ def test_thread_timings
14
+ RubyProf.start
15
+
16
+ sleep(2)
17
+
18
+ thread = Thread.new do
19
+ sleep(0.5)
20
+ sleep(2)
21
+ end
22
+
23
+ thread.join
24
+
25
+ result = RubyProf.stop
26
+
27
+ values = result.threads.values.sort do |value1, value2|
28
+ value1.length <=> value2.length
29
+ end
30
+
31
+ # Check background thread
32
+ methods = values.first.sort.reverse
33
+ assert_equal(2, methods.length)
34
+
35
+ method = methods[0]
36
+ assert_equal('ThreadTest#test_thread_timings', method.full_name)
37
+ assert_in_delta(2.5, method.total_time, 0.02)
38
+ assert_in_delta(0, method.self_time, 0.02)
39
+ assert_in_delta(0.5, method.wait_time, 0.02)
40
+ assert_in_delta(2.0, method.children_time, 0.02)
41
+ assert_equal(0, method.called)
42
+ assert_equal(0, method.parents.length)
43
+ assert_equal(1, method.children.length)
44
+
45
+ method = methods[1]
46
+ assert_equal('Kernel#sleep', method.full_name)
47
+ assert_in_delta(2.5, method.total_time, 0.02)
48
+ assert_in_delta(2.0, method.self_time, 0.02)
49
+ assert_in_delta(0.5, method.wait_time, 0.02)
50
+ assert_in_delta(0, method.children_time, 0.02)
51
+ assert_equal(2, method.called)
52
+ assert_equal(1, method.parents.length)
53
+ assert_equal(0, method.children.length)
54
+
55
+ # Check foreground thread
56
+ methods = values.last.sort.reverse
57
+ assert_equal(5, methods.length)
58
+ methods = methods.sort.reverse
59
+
60
+ method = methods[0]
61
+ assert_equal('ThreadTest#test_thread_timings', method.full_name)
62
+ assert_in_delta(4.5, method.total_time, 0.02)
63
+ assert_in_delta(0, method.self_time, 0.02)
64
+ assert_in_delta(2.0, method.wait_time, 0.02)
65
+ assert_in_delta(2.5, method.children_time, 0.02)
66
+ assert_equal(0, method.called)
67
+ assert_equal(0, method.parents.length)
68
+ assert_equal(3, method.children.length)
69
+
70
+ method = methods[1]
71
+ assert_equal('Thread#join', method.full_name)
72
+ assert_in_delta(2.5, method.total_time, 0.02)
73
+ assert_in_delta(0.5, method.self_time, 0.02)
74
+ assert_in_delta(2.0, method.wait_time, 0.02)
75
+ assert_in_delta(0, method.children_time, 0.02)
76
+ assert_equal(1, method.called)
77
+ assert_equal(1, method.parents.length)
78
+ assert_equal(0, method.children.length)
79
+
80
+ method = methods[2]
81
+ assert_equal('Kernel#sleep', method.full_name)
82
+ assert_in_delta(2, method.total_time, 0.02)
83
+ assert_in_delta(2.0, method.self_time, 0.02)
84
+ assert_in_delta(0, method.wait_time, 0.02)
85
+ assert_in_delta(0, method.children_time, 0.02)
86
+ assert_equal(1, method.called)
87
+ assert_equal(1, method.parents.length)
88
+ assert_equal(0, method.children.length)
89
+
90
+ method = methods[3]
91
+ assert_equal('<Class::Thread>#new', method.full_name)
92
+ assert_in_delta(0, method.total_time, 0.02)
93
+ assert_in_delta(0, method.self_time, 0.02)
94
+ assert_in_delta(0, method.wait_time, 0.02)
95
+ assert_in_delta(0, method.children_time, 0.02)
96
+ assert_equal(1, method.called)
97
+ assert_equal(1, method.parents.length)
98
+ assert_equal(1, method.children.length)
99
+
100
+ method = methods[4]
101
+ assert_equal('Thread#initialize', method.full_name)
102
+ assert_in_delta(0, method.total_time, 0.02)
103
+ assert_in_delta(0, method.self_time, 0.02)
104
+ assert_in_delta(0, method.wait_time, 0.02)
105
+ assert_in_delta(0, method.children_time, 0.02)
106
+ assert_equal(1, method.called)
107
+ assert_equal(1, method.parents.length)
108
+ assert_equal(0, method.children.length)
109
+ end
110
+
111
+ def test_thread
112
+ result = RubyProf.profile do
113
+ begin
114
+ status = Timeout::timeout(2) do
115
+ while true
116
+ next
117
+ end
118
+ end
119
+ rescue Timeout::Error
120
+ end
121
+ end
122
+
123
+ printer = RubyProf::GraphPrinter.new(result)
124
+ printer.print
125
+
126
+ result.threads.each do |thread_id, methods|
127
+ STDOUT << "thread: " << thread_id << "\n"
128
+ methods.each do |method|
129
+ check_parent_times(method)
130
+ check_parent_calls(method)
131
+ check_child_times(method)
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'test_helper'
6
+
7
+ # Need to use wall time for this test due to the sleep calls
8
+ RubyProf::measure_mode = RubyProf::WALL_TIME
9
+
10
+ def method1
11
+ sleep(1)
12
+ end
13
+
14
+ def method2
15
+ sleep(2)
16
+ method1
17
+ end
18
+
19
+ def method3
20
+ sleep(3)
21
+ method2
22
+ method1
23
+ end
24
+
25
+
26
+ class TimingTest < Test::Unit::TestCase
27
+
28
+ def test_basic
29
+ result = RubyProf.profile do
30
+ method1
31
+ end
32
+ print_results(result)
33
+
34
+ assert_equal(1, result.threads.length)
35
+
36
+ methods = result.threads.values.first
37
+ assert_equal(3, methods.length)
38
+
39
+
40
+ methods = methods.sort.reverse
41
+
42
+ method = methods[0]
43
+ assert_equal('TimingTest#test_basic', method.full_name)
44
+ assert_in_delta(1, method.total_time, 0.02)
45
+ assert_in_delta(0, method.self_time, 0.02)
46
+ assert_in_delta(0, method.wait_time, 0.02)
47
+ assert_in_delta(1, method.children_time, 0.02)
48
+ assert_equal(0, method.called)
49
+ assert_equal(0, method.parents.length)
50
+ assert_equal(1, method.children.length)
51
+
52
+ method = methods[1]
53
+ assert_equal('Object#method1', method.full_name)
54
+ assert_in_delta(1, method.total_time, 0.02)
55
+ assert_in_delta(0, method.self_time, 0.02)
56
+ assert_in_delta(0, method.wait_time, 0.02)
57
+ assert_equal(1, method.called)
58
+ assert_equal(1, method.parents.length)
59
+ assert_equal(1, method.children.length)
60
+
61
+ method = methods[2]
62
+ assert_equal('Kernel#sleep', method.full_name)
63
+ assert_in_delta(1, method.total_time, 0.02)
64
+ assert_in_delta(1, method.self_time, 0.02)
65
+ assert_in_delta(0, method.wait_time, 0.02)
66
+ assert_in_delta(0, method.children_time, 0.02)
67
+ assert_equal(1, method.called)
68
+ assert_equal(1, method.parents.length)
69
+ assert_equal(0, method.children.length)
70
+ end
71
+
72
+ def test_timings
73
+ result = RubyProf.profile do
74
+ method3
75
+ end
76
+
77
+ assert_equal(1, result.threads.length)
78
+ methods = result.threads.values.first
79
+ assert_equal(5, methods.length)
80
+
81
+ methods = methods.sort.reverse
82
+
83
+ method = methods[0]
84
+ assert_equal('TimingTest#test_timings', method.full_name)
85
+ assert_in_delta(7, method.total_time, 0.02)
86
+ assert_in_delta(0, method.self_time, 0.02)
87
+ assert_in_delta(0, method.wait_time, 0.02)
88
+ assert_in_delta(7, method.children_time, 0.02)
89
+ assert_equal(0, method.called)
90
+ assert_equal(0, method.parents.length)
91
+ assert_equal(1, method.children.length)
92
+
93
+ method = methods[1]
94
+ assert_equal('Object#method3', method.full_name)
95
+ assert_in_delta(7, method.total_time, 0.02)
96
+ assert_in_delta(0, method.self_time, 0.02)
97
+ assert_in_delta(0, method.wait_time, 0.02)
98
+ assert_in_delta(7, method.children_time, 0.02)
99
+ assert_equal(1, method.called)
100
+ assert_equal(1, method.parents.length)
101
+ assert_equal(3, method.children.length)
102
+
103
+ method = methods[2]
104
+ assert_equal('Kernel#sleep', method.full_name)
105
+ assert_in_delta(7, method.total_time, 0.02)
106
+ assert_in_delta(7, method.self_time, 0.02)
107
+ assert_in_delta(0, method.wait_time, 0.02)
108
+ assert_in_delta(0, method.children_time, 0.02)
109
+ assert_equal(4, method.called)
110
+ assert_equal(3, method.parents.length)
111
+ assert_equal(0, method.children.length)
112
+
113
+ method = methods[3]
114
+ assert_equal('Object#method2', method.full_name)
115
+ assert_in_delta(3, method.total_time, 0.02)
116
+ assert_in_delta(0, method.self_time, 0.02)
117
+ assert_in_delta(0, method.wait_time, 0.02)
118
+ assert_in_delta(3, method.children_time, 0.02)
119
+ assert_equal(1, method.called)
120
+ assert_equal(1, method.parents.length)
121
+ assert_equal(2, method.children.length)
122
+
123
+ method = methods[4]
124
+ assert_equal('Object#method1', method.full_name)
125
+ assert_in_delta(2, method.total_time, 0.02)
126
+ assert_in_delta(0, method.self_time, 0.02)
127
+ assert_in_delta(0, method.wait_time, 0.02)
128
+ assert_in_delta(2, method.children_time, 0.02)
129
+ assert_equal(2, method.called)
130
+ assert_equal(2, method.parents.length)
131
+ assert_equal(1, method.children.length)
132
+ end
133
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-prof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: x86-mswin32-60
6
+ authors:
7
+ - Shugo Maeda and Charlie Savage
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-02-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ruby-prof is a fast code profiler for Ruby. It is a C extension and therefore is many times faster than the standard Ruby profiler. It supports both flat and graph profiles. For each method, graph profiles show how long the method ran, which methods called it and which methods it called. RubyProf generate both text and html and can output it to standard out or to a file.
17
+ email: shugo@ruby-lang.org and cfis@savagexi.com
18
+ executables:
19
+ - ruby-prof
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - bin/ruby-prof
24
+ - ext/ruby_prof.c
25
+ - examples/flat.txt
26
+ - examples/graph.txt
27
+ - examples/graph.html
28
+ - README
29
+ - LICENSE
30
+ files:
31
+ - Rakefile
32
+ - README
33
+ - LICENSE
34
+ - CHANGES
35
+ - bin/ruby-prof
36
+ - lib/ruby-prof
37
+ - lib/ruby-prof.rb
38
+ - lib/unprof.rb
39
+ - lib/ruby-prof/abstract_printer.rb
40
+ - lib/ruby-prof/call_tree_printer.rb
41
+ - lib/ruby-prof/call_tree_printer.rb.rej
42
+ - lib/ruby-prof/flat_printer.rb
43
+ - lib/ruby-prof/graph_html_printer.rb
44
+ - lib/ruby-prof/graph_printer.rb
45
+ - lib/ruby-prof/profile_test_case.rb
46
+ - lib/ruby-prof/task.rb
47
+ - rails_plugin/ruby-prof
48
+ - rails_plugin/ruby-prof/init.rb
49
+ - rails_plugin/ruby-prof/lib
50
+ - rails_plugin/ruby-prof/lib/profiling.rb
51
+ - examples/flat.txt
52
+ - examples/graph.html
53
+ - examples/graph.txt
54
+ - ext/extconf.rb
55
+ - ext/extconf.rb.rej
56
+ - ext/measure_allocations.h
57
+ - ext/measure_cpu_time.h
58
+ - ext/measure_memory.h
59
+ - ext/measure_process_time.h
60
+ - ext/measure_wall_time.h
61
+ - ext/ruby_prof.c
62
+ - test/basic_test.rb
63
+ - test/duplicate_names_test.rb
64
+ - test/line_number_test.rb
65
+ - test/measure_mode_test.rb
66
+ - test/module_test.rb
67
+ - test/no_method_class_test.rb
68
+ - test/prime.rb
69
+ - test/prime1.rb
70
+ - test/prime2.rb
71
+ - test/prime3.rb
72
+ - test/prime_test.rb
73
+ - test/printers_test.rb
74
+ - test/profile_unit_test.rb
75
+ - test/recursive_test.rb
76
+ - test/singleton_test.rb
77
+ - test/start_test.rb
78
+ - test/test_helper.rb
79
+ - test/test_suite.rb
80
+ - test/thread_test.rb
81
+ - test/timing_test.rb
82
+ - lib/ruby_prof.so
83
+ has_rdoc: true
84
+ homepage: http://rubyforge.org/projects/ruby-prof/
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --title
88
+ - ruby-prof
89
+ - --inline-source
90
+ - --line-numbers
91
+ - --main
92
+ - README
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 1.8.4
100
+ version:
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ requirements: []
108
+
109
+ rubyforge_project: ruby-prof
110
+ rubygems_version: 1.0.1
111
+ signing_key:
112
+ specification_version: 2
113
+ summary: Fast Ruby profiler
114
+ test_files:
115
+ - test/test_helper.rb
116
+ - test/test_suite.rb