jeremy-ruby-prof 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGES +158 -0
  2. data/LICENSE +23 -0
  3. data/README +416 -0
  4. data/Rakefile +141 -0
  5. data/bin/ruby-prof +196 -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 +24 -0
  10. data/ext/measure_allocations.h +58 -0
  11. data/ext/measure_cpu_time.h +149 -0
  12. data/ext/measure_memory.h +104 -0
  13. data/ext/measure_process_time.h +52 -0
  14. data/ext/measure_wall_time.h +53 -0
  15. data/ext/ruby_prof.c +1680 -0
  16. data/lib/ruby-prof.rb +45 -0
  17. data/lib/ruby-prof/abstract_printer.rb +42 -0
  18. data/lib/ruby-prof/call_tree_printer.rb +76 -0
  19. data/lib/ruby-prof/flat_printer.rb +76 -0
  20. data/lib/ruby-prof/graph_html_printer.rb +255 -0
  21. data/lib/ruby-prof/graph_printer.rb +163 -0
  22. data/lib/ruby-prof/profile_test.rb +147 -0
  23. data/lib/ruby-prof/task.rb +147 -0
  24. data/lib/unprof.rb +8 -0
  25. data/test/basic_test.rb +190 -0
  26. data/test/duplicate_names_test.rb +33 -0
  27. data/test/exceptions_test.rb +19 -0
  28. data/test/line_number_test.rb +69 -0
  29. data/test/measure_mode_test.rb +91 -0
  30. data/test/measurement_test.rb +61 -0
  31. data/test/module_test.rb +57 -0
  32. data/test/no_method_class_test.rb +14 -0
  33. data/test/prime.rb +60 -0
  34. data/test/prime1.rb +17 -0
  35. data/test/prime2.rb +26 -0
  36. data/test/prime3.rb +17 -0
  37. data/test/prime_test.rb +24 -0
  38. data/test/printers_test.rb +74 -0
  39. data/test/profile_unit_test.rb +24 -0
  40. data/test/recursive_test.rb +144 -0
  41. data/test/singleton_test.rb +38 -0
  42. data/test/start_test.rb +24 -0
  43. data/test/test_helper.rb +55 -0
  44. data/test/test_suite.rb +20 -0
  45. data/test/thread_test.rb +135 -0
  46. data/test/timing_test.rb +133 -0
  47. metadata +112 -0
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'timeout'
6
+
7
+ # -- Test for bug [#5657]
8
+ # http://rubyforge.org/tracker/index.php?func=detail&aid=5657&group_id=1814&atid=7060
9
+
10
+
11
+ class A
12
+ attr_accessor :as
13
+ def initialize
14
+ @as = []
15
+ class << @as
16
+ def <<(an_a)
17
+ super
18
+ end
19
+ end
20
+ end
21
+
22
+ def <<(an_a)
23
+ @as << an_a
24
+ end
25
+ end
26
+
27
+ class SingletonTest < Test::Unit::TestCase
28
+ def test_singleton
29
+ result = RubyProf.profile do
30
+ a = A.new
31
+ a << :first_thing
32
+ assert_equal(1, a.as.size)
33
+ end
34
+ printer = RubyProf::FlatPrinter.new(result)
35
+ printer.print(STDOUT)
36
+ end
37
+ end
38
+
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+
6
+
7
+ def start
8
+ RubyProf.start
9
+ end
10
+
11
+ def wait_around
12
+ sleep(2)
13
+ end
14
+
15
+ def stop
16
+ RubyProf.stop
17
+ end
18
+
19
+ start
20
+ wait_around
21
+ result = stop
22
+
23
+ printer = RubyProf::FlatPrinter.new(result)
24
+ printer.print(STDOUT)
@@ -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,20 @@
1
+ # file ts_dbaccess.rb
2
+ require 'test/unit'
3
+ require 'basic_test'
4
+ require 'exceptions_test'
5
+ require 'duplicate_names_test'
6
+ require 'line_number_test'
7
+ require 'measure_mode_test'
8
+ require 'module_test'
9
+ require 'no_method_class_test'
10
+ require 'prime_test'
11
+ require 'printers_test'
12
+ require 'recursive_test'
13
+ require 'singleton_test'
14
+ require 'thread_test'
15
+ require 'timing_test'
16
+
17
+ # Can't use this one here cause it breaks
18
+ # the rest of the unit tets (Ruby Prof gets
19
+ # started twice).
20
+ #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,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jeremy-ruby-prof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
5
+ platform: ruby
6
+ authors:
7
+ - Shugo Maeda
8
+ - Charlie Savage
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-06-18 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ 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.
18
+ email: shugo@ruby-lang.org and cfis@savagexi.com
19
+ executables:
20
+ - ruby-prof
21
+ extensions:
22
+ - ext/extconf.rb
23
+ extra_rdoc_files:
24
+ - bin/ruby-prof
25
+ - ext/ruby_prof.c
26
+ - examples/flat.txt
27
+ - examples/graph.txt
28
+ - examples/graph.html
29
+ - README
30
+ - LICENSE
31
+ files:
32
+ - Rakefile
33
+ - README
34
+ - LICENSE
35
+ - CHANGES
36
+ - bin/ruby-prof
37
+ - lib/unprof.rb
38
+ - lib/ruby-prof.rb
39
+ - lib/ruby-prof
40
+ - lib/ruby-prof/graph_printer.rb
41
+ - lib/ruby-prof/profile_test.rb
42
+ - lib/ruby-prof/abstract_printer.rb
43
+ - lib/ruby-prof/task.rb
44
+ - lib/ruby-prof/call_tree_printer.rb
45
+ - lib/ruby-prof/graph_html_printer.rb
46
+ - lib/ruby-prof/flat_printer.rb
47
+ - examples/graph.txt
48
+ - examples/flat.txt
49
+ - examples/graph.html
50
+ - ext/measure_allocations.h
51
+ - ext/measure_memory.h
52
+ - ext/ruby_prof.c
53
+ - ext/extconf.rb
54
+ - ext/measure_wall_time.h
55
+ - ext/measure_process_time.h
56
+ - ext/measure_cpu_time.h
57
+ - test/start_test.rb
58
+ - test/line_number_test.rb
59
+ - test/duplicate_names_test.rb
60
+ - test/recursive_test.rb
61
+ - test/measure_mode_test.rb
62
+ - test/thread_test.rb
63
+ - test/measurement_test.rb
64
+ - test/basic_test.rb
65
+ - test/timing_test.rb
66
+ - test/no_method_class_test.rb
67
+ - test/exceptions_test.rb
68
+ - test/printers_test.rb
69
+ - test/prime.rb
70
+ - test/singleton_test.rb
71
+ - test/test_helper.rb
72
+ - test/module_test.rb
73
+ - test/prime1.rb
74
+ - test/prime2.rb
75
+ - test/prime3.rb
76
+ - test/test_suite.rb
77
+ - test/profile_unit_test.rb
78
+ - test/prime_test.rb
79
+ has_rdoc: true
80
+ homepage: http://rubyforge.org/projects/ruby-prof/
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --title
84
+ - ruby-prof
85
+ - --inline-source
86
+ - --line-numbers
87
+ - --main
88
+ - README
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 1.8.4
96
+ version:
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ version:
103
+ requirements: []
104
+
105
+ rubyforge_project: ruby-prof
106
+ rubygems_version: 1.0.1
107
+ signing_key:
108
+ specification_version: 2
109
+ summary: Fast Ruby profiler
110
+ test_files:
111
+ - test/test_helper.rb
112
+ - test/test_suite.rb