ruby-prof 0.6.0-x86-mswin32-60 → 0.7.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) 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/mingw/ruby_prof.so +0 -0
  16. data/ext/ruby_prof.c +685 -633
  17. data/ext/ruby_prof.h +188 -0
  18. data/ext/vc/ruby_prof.sln +20 -0
  19. data/ext/vc/ruby_prof.vcproj +241 -0
  20. data/ext/version.h +4 -0
  21. data/lib/ruby-prof.rb +4 -0
  22. data/lib/ruby-prof/call_info.rb +47 -0
  23. data/lib/ruby-prof/call_tree_printer.rb +9 -1
  24. data/lib/ruby-prof/graph_html_printer.rb +6 -5
  25. data/lib/ruby-prof/graph_printer.rb +3 -2
  26. data/lib/ruby-prof/method_info.rb +85 -0
  27. data/lib/ruby-prof/task.rb +1 -2
  28. data/lib/ruby-prof/test.rb +148 -0
  29. data/rails/environment/profile.rb +24 -0
  30. data/rails/example/example_test.rb +9 -0
  31. data/rails/profile_test_helper.rb +21 -0
  32. data/test/basic_test.rb +173 -80
  33. data/test/duplicate_names_test.rb +2 -3
  34. data/test/exceptions_test.rb +15 -0
  35. data/test/exclude_threads_test.rb +54 -0
  36. data/test/line_number_test.rb +18 -14
  37. data/test/measurement_test.rb +121 -0
  38. data/test/module_test.rb +5 -8
  39. data/test/no_method_class_test.rb +4 -5
  40. data/test/prime.rb +3 -5
  41. data/test/prime_test.rb +1 -12
  42. data/test/printers_test.rb +10 -13
  43. data/test/profile_unit_test.rb +10 -12
  44. data/test/recursive_test.rb +202 -92
  45. data/test/singleton_test.rb +1 -2
  46. data/test/stack_test.rb +138 -0
  47. data/test/start_stop_test.rb +95 -0
  48. data/test/test_suite.rb +7 -3
  49. data/test/thread_test.rb +111 -87
  50. data/test/unique_call_path_test.rb +206 -0
  51. metadata +42 -44
  52. data/ext/extconf.rb.rej +0 -13
  53. data/lib/ruby-prof/call_tree_printer.rb.rej +0 -27
  54. data/lib/ruby-prof/profile_test_case.rb +0 -80
  55. data/lib/ruby_prof.so +0 -0
  56. data/rails_plugin/ruby-prof/init.rb +0 -8
  57. data/rails_plugin/ruby-prof/lib/profiling.rb +0 -57
  58. data/test/measure_mode_test.rb +0 -79
  59. data/test/prime1.rb +0 -17
  60. data/test/prime2.rb +0 -26
  61. data/test/prime3.rb +0 -17
  62. data/test/start_test.rb +0 -24
  63. data/test/test_helper.rb +0 -55
  64. data/test/timing_test.rb +0 -133
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'test/unit'
4
4
  require 'ruby-prof'
5
- require 'test_helper'
6
5
 
7
6
  class DuplicateNames < Test::Unit::TestCase
8
7
  def test_names
@@ -22,12 +21,12 @@ class DuplicateNames < Test::Unit::TestCase
22
21
  end
23
22
 
24
23
  # There should be 3 foo methods
25
- methods = result.threads.values.first
24
+ methods = result.threads.values.first.sort.reverse
26
25
 
27
26
  methods = methods.select do |method|
28
27
  method.full_name == 'DuplicateNames::Foo::Bar#foo'
29
28
  end
30
-
29
+
31
30
  assert_equal(3, methods.length)
32
31
  end
33
32
  end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'ruby-prof'
4
+
5
+ class ExceptionsTest < Test::Unit::TestCase
6
+ def test_profile
7
+ result = begin
8
+ RubyProf.profile do
9
+ raise(RuntimeError, 'Test error')
10
+ end
11
+ rescue => e
12
+ end
13
+ assert_not_nil(result)
14
+ end
15
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+
6
+
7
+ # -- Tests ----
8
+ class ExcludeThreadsTest < Test::Unit::TestCase
9
+ def test_exclude_threads
10
+
11
+ def thread1_proc
12
+ sleep(0.5)
13
+ sleep(2)
14
+ end
15
+
16
+ def thread2_proc
17
+ sleep(0.5)
18
+ sleep(2)
19
+ end
20
+
21
+ thread1 = Thread.new do
22
+ thread1_proc
23
+ end
24
+
25
+ thread2 = Thread.new do
26
+ thread2_proc
27
+ end
28
+
29
+ RubyProf::exclude_threads = [ thread2 ]
30
+
31
+ RubyProf.start
32
+
33
+ thread1.join
34
+ thread2.join
35
+
36
+ result = RubyProf.stop
37
+
38
+ RubyProf::exclude_threads = nil
39
+
40
+ assert_equal(2, result.threads.length)
41
+
42
+ output = Array.new
43
+ result.threads.each do | thread_id, methods |
44
+ methods.each do | m |
45
+ if m.full_name.index("ExcludeThreadsTest#thread") == 0
46
+ output.push(m.full_name)
47
+ end
48
+ end
49
+ end
50
+
51
+ assert_equal(1, output.length)
52
+ assert_equal("ExcludeThreadsTest#thread1_proc", output[0])
53
+ end
54
+ end
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'test/unit'
4
3
  require 'ruby-prof'
5
4
  require 'prime'
6
- require 'test_helper'
7
5
 
8
6
  class LineNumbers
9
7
  def method1
@@ -11,6 +9,7 @@ class LineNumbers
11
9
  end
12
10
 
13
11
  def method2
12
+ a = 3
14
13
  method1
15
14
  end
16
15
 
@@ -33,15 +32,15 @@ class LineNumbersTest < Test::Unit::TestCase
33
32
 
34
33
  method = methods[0]
35
34
  assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
36
- assert_equal(28, method.line)
35
+ assert_equal(27, method.line)
37
36
 
38
37
  method = methods[1]
39
- assert_equal('LineNumbers#method1', method.full_name)
40
- assert_equal(9, method.line)
38
+ assert_equal('LineNumbers#method2', method.full_name)
39
+ assert_equal(11, method.line)
41
40
 
42
41
  method = methods[2]
43
- assert_equal('LineNumbers#method2', method.full_name)
44
- assert_equal(13, method.line)
42
+ assert_equal('LineNumbers#method1', method.full_name)
43
+ assert_equal(7, method.line)
45
44
  end
46
45
 
47
46
  def test_c_function
@@ -51,19 +50,24 @@ class LineNumbersTest < Test::Unit::TestCase
51
50
  numbers.method3
52
51
  end
53
52
 
54
- methods = result.threads.values.first.sort.reverse
53
+ methods = result.threads.values.first.sort_by {|method| method.full_name}
55
54
  assert_equal(3, methods.length)
56
-
55
+
56
+ # Methods:
57
+ # LineNumbers#method3
58
+ # LineNumbersTest#test_c_function
59
+ # Kernel#sleep
60
+
57
61
  method = methods[0]
58
- assert_equal('LineNumbersTest#test_c_function', method.full_name)
59
- assert_equal(51, method.line)
62
+ assert_equal('Kernel#sleep', method.full_name)
63
+ assert_equal(0, method.line)
60
64
 
61
65
  method = methods[1]
62
66
  assert_equal('LineNumbers#method3', method.full_name)
63
- assert_equal(17, method.line)
67
+ assert_equal(16, method.line)
64
68
 
65
69
  method = methods[2]
66
- assert_equal('Kernel#sleep', method.full_name)
67
- assert_equal(0, method.line)
70
+ assert_equal('LineNumbersTest#test_c_function', method.full_name)
71
+ assert_equal(50, method.line)
68
72
  end
69
73
  end
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'ruby-prof'
4
+
5
+ class MeasurementTest < Test::Unit::TestCase
6
+ def setup
7
+ GC.enable_stats if GC.respond_to?(:enable_stats)
8
+ end
9
+
10
+ def teardown
11
+ GC.disable_stats if GC.respond_to?(:disable_stats)
12
+ end
13
+
14
+ def test_process_time_mode
15
+ RubyProf::measure_mode = RubyProf::PROCESS_TIME
16
+ assert_equal(RubyProf::PROCESS_TIME, RubyProf::measure_mode)
17
+ end
18
+
19
+ def test_process_time
20
+ t = RubyProf.measure_process_time
21
+ assert_kind_of(Float, t)
22
+
23
+ u = RubyProf.measure_process_time
24
+ assert(u >= t, [t, u].inspect)
25
+ end
26
+
27
+ def test_wall_time_mode
28
+ RubyProf::measure_mode = RubyProf::WALL_TIME
29
+ assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
30
+ end
31
+
32
+ def test_wall_time
33
+ t = RubyProf.measure_wall_time
34
+ assert_kind_of Float, t
35
+
36
+ u = RubyProf.measure_wall_time
37
+ assert u >= t, [t, u].inspect
38
+ end
39
+
40
+ if RubyProf::CPU_TIME
41
+ def test_cpu_time_mode
42
+ RubyProf::measure_mode = RubyProf::CPU_TIME
43
+ assert_equal(RubyProf::CPU_TIME, RubyProf::measure_mode)
44
+ end
45
+
46
+ def test_cpu_time
47
+ RubyProf.cpu_frequency = 2.33e9
48
+
49
+ t = RubyProf.measure_cpu_time
50
+ assert_kind_of Float, t
51
+
52
+ u = RubyProf.measure_cpu_time
53
+ assert u > t, [t, u].inspect
54
+ end
55
+ end
56
+
57
+ if RubyProf::ALLOCATIONS
58
+ def test_allocations_mode
59
+ RubyProf::measure_mode = RubyProf::ALLOCATIONS
60
+ assert_equal(RubyProf::ALLOCATIONS, RubyProf::measure_mode)
61
+ end
62
+
63
+ def test_allocations
64
+ t = RubyProf.measure_allocations
65
+ assert_kind_of Integer, t
66
+
67
+ u = RubyProf.measure_allocations
68
+ assert u > t, [t, u].inspect
69
+ end
70
+ end
71
+
72
+ if RubyProf::MEMORY
73
+ def test_memory_mode
74
+ RubyProf::measure_mode = RubyProf::MEMORY
75
+ assert_equal(RubyProf::MEMORY, RubyProf::measure_mode)
76
+ end
77
+
78
+ def test_memory
79
+ t = RubyProf.measure_memory
80
+ assert_kind_of Integer, t
81
+
82
+ u = RubyProf.measure_memory
83
+ assert(u >= t, [t, u].inspect)
84
+
85
+ result = RubyProf.profile {Array.new}
86
+ total = result.threads.values.first.methods.inject(0) { |sum, m| sum + m.total_time }
87
+
88
+ assert(total > 0, 'Should measure more than zero kilobytes of memory usage')
89
+ assert_not_equal(0, total % 1, 'Should not truncate fractional kilobyte measurements')
90
+ end
91
+ end
92
+
93
+ if RubyProf::GC_RUNS
94
+ def test_gc_runs_mode
95
+ RubyProf::measure_mode = RubyProf::GC_RUNS
96
+ assert_equal(RubyProf::GC_RUNS, RubyProf::measure_mode)
97
+ end
98
+
99
+ def test_gc_runs
100
+ t = RubyProf.measure_gc_runs
101
+ assert_kind_of Integer, t
102
+
103
+ GC.start
104
+
105
+ u = RubyProf.measure_gc_runs
106
+ assert u > t, [t, u].inspect
107
+ end
108
+ end
109
+
110
+ if RubyProf::GC_TIME
111
+ def test_gc_time
112
+ t = RubyProf.measure_gc_time
113
+ assert_kind_of Integer, t
114
+
115
+ GC.start
116
+
117
+ u = RubyProf.measure_gc_time
118
+ assert u > t, [t, u].inspect
119
+ end
120
+ end
121
+ end
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'test/unit'
4
3
  require 'ruby-prof'
5
- require 'test_helper'
6
4
 
7
5
  # Need to use wall time for this test due to the sleep calls
8
6
  RubyProf::measure_mode = RubyProf::WALL_TIME
@@ -33,20 +31,19 @@ class ModuleTest < Test::Unit::TestCase
33
31
  hello
34
32
  end
35
33
 
36
- methods = result.threads.values.first
37
- methods = methods.sort.reverse
34
+ methods = result.threads.values.first.sort.reverse
38
35
 
39
- # Length should be 4
36
+ # Length should be 5
40
37
  assert_equal(5, methods.length)
41
38
 
42
39
  method = methods[0]
43
40
  assert_equal('ModuleTest#test_nested_modules', method.full_name)
44
41
 
45
42
  method = methods[1]
46
- assert_equal('Kernel#sleep', method.full_name)
47
-
48
- method = methods[2]
49
43
  assert_equal('Bar#hello', method.full_name)
44
+
45
+ method = methods[2]
46
+ assert_equal('Kernel#sleep', method.full_name)
50
47
 
51
48
  method = methods[3]
52
49
  assert_equal('<Module::Bar>#hello', method.full_name)
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'ruby-prof'
4
3
 
5
4
  # Make sure this works with no class or method
@@ -7,8 +6,8 @@ result = RubyProf.profile do
7
6
  sleep 1
8
7
  end
9
8
 
10
- method = result.threads.values.first.sort.last
11
-
12
- if method.full_name != 'Global#[No method]'
13
- raise(RuntimeError, "Wrong method name. Expected: Global#[No method]. Actual: #{method.full_name}")
9
+ methods = result.threads.values.first
10
+ global_method = methods.sort_by {|method| method.full_name}.first
11
+ if global_method.full_name != 'Global#[No method]'
12
+ raise(RuntimeError, "Wrong method name. Expected: Global#[No method]. Actual: #{global_method.full_name}")
14
13
  end
@@ -1,6 +1,6 @@
1
1
  # A silly little test program that finds prime numbers. It
2
2
  # is intentionally badly designed to show off the use
3
- # or ruby-prof.
3
+ # of ruby-prof.
4
4
  #
5
5
  # Source from http://people.cs.uchicago.edu/~bomb154/154/maclabs/profilers-lab/
6
6
 
@@ -44,7 +44,7 @@ def find_largest(primes)
44
44
  end
45
45
 
46
46
  def run_primes
47
- length = 500
47
+ length = 10
48
48
  maxnum = 10000
49
49
 
50
50
  # Create random numbers
@@ -55,6 +55,4 @@ def run_primes
55
55
 
56
56
  # Find the largest primes
57
57
  largest = find_largest(primes)
58
- end
59
-
60
- run_primes
58
+ end
@@ -1,24 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'test/unit'
4
3
  require 'ruby-prof'
5
4
  require 'prime'
6
- require 'test_helper'
7
-
8
5
 
9
6
  # -- Tests ----
10
- class PrimeTest < Test::Unit::TestCase
7
+ class PrimeTest< Test::Unit::TestCase
11
8
  def test_consistency
12
9
  result = RubyProf.profile do
13
10
  run_primes
14
11
  end
15
-
16
- result.threads.values.each do |methods|
17
- methods.each do |method|
18
- check_parent_times(method)
19
- check_parent_calls(method)
20
- check_child_times(method)
21
- end
22
- end
23
12
  end
24
13
  end
@@ -2,13 +2,11 @@
2
2
  require 'test/unit'
3
3
  require 'ruby-prof'
4
4
  require 'prime'
5
- require 'test_helper'
6
-
7
5
 
8
6
  # -- Tests ----
9
7
  class PrintersTest < Test::Unit::TestCase
10
-
11
8
  def setup
9
+ RubyProf::measure_mode = RubyProf::PROCESS_TIME
12
10
  @result = RubyProf.profile do
13
11
  run_primes
14
12
  end
@@ -31,18 +29,18 @@ class PrintersTest < Test::Unit::TestCase
31
29
  assert(true)
32
30
  end
33
31
 
34
- def test_flatprinter_duckfriendliness
32
+ def test_flat_string
35
33
  output = ''
36
34
 
37
35
  printer = RubyProf::FlatPrinter.new(@result)
38
- assert_nothing_raised { printer.print( output ) }
36
+ assert_nothing_raised { printer.print(output) }
39
37
 
40
- assert_match( /Thread ID: \d+/i, output )
41
- assert_match( /Total: \d+\.\d+/i, output )
42
- assert_match( /Object#run_primes/i, output )
38
+ assert_match(/Thread ID: -?\d+/i, output)
39
+ assert_match(/Total: \d+\.\d+/i, output)
40
+ assert_match(/Object#run_primes/i, output)
43
41
  end
44
42
 
45
- def test_graphhtmlprinter_duckfriendliness
43
+ def test_graph_html_string
46
44
  output = ''
47
45
  printer = RubyProf::GraphHtmlPrinter.new(@result)
48
46
  assert_nothing_raised { printer.print(output) }
@@ -52,17 +50,17 @@ class PrintersTest < Test::Unit::TestCase
52
50
  assert_match( /Object#run_primes/i, output )
53
51
  end
54
52
 
55
- def test_graphprinter_duckfriendliness
53
+ def test_graph_string
56
54
  output = ''
57
55
  printer = RubyProf::GraphPrinter.new(@result)
58
56
  assert_nothing_raised { printer.print(output) }
59
57
 
60
- assert_match( /Thread ID: \d+/i, output )
58
+ assert_match( /Thread ID: -?\d+/i, output )
61
59
  assert_match( /Total Time: \d+\.\d+/i, output )
62
60
  assert_match( /Object#run_primes/i, output )
63
61
  end
64
62
 
65
- def test_calltreeprinter_duckfriendliness
63
+ def test_call_tree_string
66
64
  output = ''
67
65
  printer = RubyProf::CallTreePrinter.new(@result)
68
66
  assert_nothing_raised { printer.print(output) }
@@ -70,5 +68,4 @@ class PrintersTest < Test::Unit::TestCase
70
68
  assert_match(/fn=Object::find_primes/i, output)
71
69
  assert_match(/events: process_time/i, output)
72
70
  end
73
-
74
71
  end