ruby-prof 0.5.0-mswin32 → 0.5.1-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+ require 'prime'
6
+ require 'test_helper'
7
+
8
+ class LineNumbers
9
+ def method1
10
+ a = 3
11
+ end
12
+
13
+ def method2
14
+ method1
15
+ end
16
+
17
+ def method3
18
+ sleep(1)
19
+ end
20
+ end
21
+
22
+ # -- Tests ----
23
+ class LineNumbersTest < Test::Unit::TestCase
24
+ def test_function_line_no
25
+ numbers = LineNumbers.new
26
+
27
+ result = RubyProf.profile do
28
+ numbers.method2
29
+ end
30
+
31
+ methods = result.threads.values.first.sort.reverse
32
+ assert_equal(3, methods.length)
33
+
34
+ method = methods[0]
35
+ assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
36
+ assert_equal(28, method.line)
37
+
38
+ method = methods[1]
39
+ assert_equal('LineNumbers#method1', method.full_name)
40
+ assert_equal(9, method.line)
41
+
42
+ method = methods[2]
43
+ assert_equal('LineNumbers#method2', method.full_name)
44
+ assert_equal(13, method.line)
45
+ end
46
+
47
+ def test_c_function
48
+ numbers = LineNumbers.new
49
+
50
+ result = RubyProf.profile do
51
+ numbers.method3
52
+ end
53
+
54
+ methods = result.threads.values.first.sort.reverse
55
+ assert_equal(3, methods.length)
56
+
57
+ method = methods[0]
58
+ assert_equal('LineNumbersTest#test_c_function', method.full_name)
59
+ assert_equal(51, method.line)
60
+
61
+ method = methods[1]
62
+ assert_equal('LineNumbers#method3', method.full_name)
63
+ assert_equal(17, method.line)
64
+
65
+ method = methods[2]
66
+ assert_equal('Kernel#sleep', method.full_name)
67
+ assert_equal(0, method.line)
68
+ end
69
+ end
data/test/module_test.rb CHANGED
@@ -7,7 +7,6 @@ require 'test_helper'
7
7
  # Need to use wall time for this test due to the sleep calls
8
8
  RubyProf::measure_mode = RubyProf::WALL_TIME
9
9
 
10
-
11
10
  module Foo
12
11
  def Foo::hello
13
12
  sleep(0.5)
@@ -44,10 +43,10 @@ class ModuleTest < Test::Unit::TestCase
44
43
  assert_equal('ModuleTest#test_nested_modules', method.full_name)
45
44
 
46
45
  method = methods[1]
47
- assert_equal('Bar#hello', method.full_name)
46
+ assert_equal('Kernel#sleep', method.full_name)
48
47
 
49
48
  method = methods[2]
50
- assert_equal('Kernel#sleep', method.full_name)
49
+ assert_equal('Bar#hello', method.full_name)
51
50
 
52
51
  method = methods[3]
53
52
  assert_equal('<Module::Bar>#hello', method.full_name)
data/test/prime.rb CHANGED
@@ -5,54 +5,56 @@
5
5
  # Source from http://people.cs.uchicago.edu/~bomb154/154/maclabs/profilers-lab/
6
6
 
7
7
  def make_random_array(length, maxnum)
8
- result = Array.new(length)
9
- result.each_index do |i|
10
- result[i] = rand(maxnum)
11
- end
12
-
13
- result
8
+ result = Array.new(length)
9
+ result.each_index do |i|
10
+ result[i] = rand(maxnum)
11
+ end
12
+
13
+ result
14
14
  end
15
15
 
16
16
  def is_prime(x)
17
- y = 2
18
- y.upto(x-1) do |i|
19
- return false if (x % i) == 0
20
- end
21
- true
17
+ y = 2
18
+ y.upto(x-1) do |i|
19
+ return false if (x % i) == 0
20
+ end
21
+ true
22
22
  end
23
23
 
24
24
  def find_primes(arr)
25
- result = arr.select do |value|
26
- is_prime(value)
27
- end
28
- result
25
+ result = arr.select do |value|
26
+ is_prime(value)
27
+ end
28
+ result
29
29
  end
30
30
 
31
31
  def find_largest(primes)
32
- largest = primes.first
32
+ largest = primes.first
33
33
 
34
- # Intentionally use upto for example purposes
35
- # (upto is also called from is_prime)
36
- 0.upto(primes.length-1) do |i|
34
+ # Intentionally use upto for example purposes
35
+ # (upto is also called from is_prime)
36
+ 0.upto(primes.length-1) do |i|
37
37
  sleep(0.02)
38
38
  prime = primes[i]
39
- if prime > largest
40
- largest = prime
41
- end
42
- end
43
- largest
39
+ if prime > largest
40
+ largest = prime
41
+ end
42
+ end
43
+ largest
44
44
  end
45
45
 
46
46
  def run_primes
47
- length = 500
47
+ length = 500
48
48
  maxnum = 10000
49
49
 
50
50
  # Create random numbers
51
- random_array = make_random_array(length, maxnum)
52
-
53
- # Find the primes
51
+ random_array = make_random_array(length, maxnum)
52
+
53
+ # Find the primes
54
54
  primes = find_primes(random_array)
55
55
 
56
56
  # Find the largest primes
57
- largest = find_largest(primes)
57
+ largest = find_largest(primes)
58
58
  end
59
+
60
+ run_primes
@@ -93,7 +93,7 @@ class RecursiveTest < Test::Unit::TestCase
93
93
  assert_equal(3, method.children.length)
94
94
 
95
95
  method = methods[4]
96
- assert_equal('Fixnum#==', method.full_name)
96
+ assert_equal('Fixnum#-', method.full_name)
97
97
  assert_in_delta(0, method.total_time, 0.02)
98
98
  assert_in_delta(0, method.self_time, 0.02)
99
99
  assert_in_delta(0, method.wait_time, 0.02)
@@ -103,7 +103,7 @@ class RecursiveTest < Test::Unit::TestCase
103
103
  assert_equal(0, method.children.length)
104
104
 
105
105
  method = methods[5]
106
- assert_equal('Fixnum#-', method.full_name)
106
+ assert_equal('Fixnum#==', method.full_name)
107
107
  assert_in_delta(0, method.total_time, 0.02)
108
108
  assert_in_delta(0, method.self_time, 0.02)
109
109
  assert_in_delta(0, method.wait_time, 0.02)
data/test/test_suite.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'test/unit'
3
3
  require 'basic_test'
4
4
  require 'duplicate_names_test'
5
+ require 'line_number_test'
5
6
  require 'measure_mode_test'
6
7
  require 'module_test'
7
8
  require 'no_method_class_test'
data/test/thread_test.rb CHANGED
@@ -87,26 +87,25 @@ class ThreadTest < Test::Unit::TestCase
87
87
  assert_equal(1, method.parents.length)
88
88
  assert_equal(0, method.children.length)
89
89
 
90
-
91
90
  method = methods[3]
92
- assert_equal('Thread#initialize', method.full_name)
91
+ assert_equal('<Class::Thread>#new', method.full_name)
93
92
  assert_in_delta(0, method.total_time, 0.02)
94
93
  assert_in_delta(0, method.self_time, 0.02)
95
94
  assert_in_delta(0, method.wait_time, 0.02)
96
95
  assert_in_delta(0, method.children_time, 0.02)
97
96
  assert_equal(1, method.called)
98
97
  assert_equal(1, method.parents.length)
99
- assert_equal(0, method.children.length)
98
+ assert_equal(1, method.children.length)
100
99
 
101
100
  method = methods[4]
102
- assert_equal('<Class::Thread>#new', method.full_name)
101
+ assert_equal('Thread#initialize', method.full_name)
103
102
  assert_in_delta(0, method.total_time, 0.02)
104
103
  assert_in_delta(0, method.self_time, 0.02)
105
104
  assert_in_delta(0, method.wait_time, 0.02)
106
105
  assert_in_delta(0, method.children_time, 0.02)
107
106
  assert_equal(1, method.called)
108
107
  assert_equal(1, method.parents.length)
109
- assert_equal(1, method.children.length)
108
+ assert_equal(0, method.children.length)
110
109
  end
111
110
 
112
111
  def test_thread
@@ -121,11 +120,6 @@ class ThreadTest < Test::Unit::TestCase
121
120
  end
122
121
  end
123
122
 
124
- printer = RubyProf::GraphHtmlPrinter.new(result)
125
- File.open('c:/temp/test.html', 'w') do |file|
126
- printer.print(file)
127
- end
128
-
129
123
  result.threads.each do |thread_id, methods|
130
124
  STDOUT << "thread: " << thread_id << "\n"
131
125
  methods.each do |method|
data/test/timing_test.rb CHANGED
@@ -29,12 +29,14 @@ class TimingTest < Test::Unit::TestCase
29
29
  result = RubyProf.profile do
30
30
  method1
31
31
  end
32
+ print_results(result)
32
33
 
33
34
  assert_equal(1, result.threads.length)
34
35
 
35
36
  methods = result.threads.values.first
36
37
  assert_equal(3, methods.length)
37
38
 
39
+
38
40
  methods = methods.sort.reverse
39
41
 
40
42
  method = methods[0]
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ruby-prof
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.0
7
- date: 2007-07-09 00:05:23 -06:00
6
+ version: 0.5.1
7
+ date: 2007-07-18 10:34:52 -06:00
8
8
  summary: Fast Ruby profiler
9
9
  require_paths:
10
10
  - lib
@@ -43,12 +43,7 @@ files:
43
43
  - lib/ruby-prof/graph_html_printer.rb
44
44
  - lib/ruby-prof/graph_printer.rb
45
45
  - lib/ruby-prof/profile_test_case.rb
46
- - lib/ruby-prof/rails_plugin
47
46
  - lib/ruby-prof/task.rb
48
- - lib/ruby-prof/rails_plugin/ruby-prof
49
- - lib/ruby-prof/rails_plugin/ruby-prof/init.rb
50
- - lib/ruby-prof/rails_plugin/ruby-prof/lib
51
- - lib/ruby-prof/rails_plugin/ruby-prof/lib/profiling.rb
52
47
  - examples/flat.txt
53
48
  - examples/graph.html
54
49
  - examples/graph.txt
@@ -61,6 +56,7 @@ files:
61
56
  - test/basic_test.rb
62
57
  - test/duplicate_names_test.rb
63
58
  - test/gc.log
59
+ - test/line_number_test.rb
64
60
  - test/measure_mode_test.rb
65
61
  - test/module_test.rb
66
62
  - test/no_method_class_test.rb
@@ -1,6 +0,0 @@
1
- require 'profiling'
2
-
3
- ActionController::Base.class_eval do
4
- include ActionController::Profiling
5
- end
6
-
@@ -1,52 +0,0 @@
1
- require 'ruby-prof'
2
-
3
- module ActionController #:nodoc:
4
- # The ruby-prof module times the performance of actions and reports to the logger. If the Active Record
5
- # package has been included, a separate timing section for database calls will be added as well.
6
- module Profiling #:nodoc:
7
- def self.included(base)
8
- base.class_eval do
9
- alias_method_chain :perform_action, :profiling
10
- end
11
- end
12
-
13
- def perform_action_with_profiling
14
- if not logger or
15
- not logger.level == Logger::DEBUG
16
- perform_action_without_profiling
17
- else
18
- result = RubyProf.profile do
19
- perform_action_without_profiling
20
- end
21
-
22
- output = StringIO.new
23
- output << " [#{complete_request_uri rescue "unknown"}]"
24
- output << "\n\n"
25
-
26
- # Create a flat printer
27
- printer = RubyProf::FlatPrinter.new(result)
28
-
29
- # Skip anything less than 1% - which is a lot of
30
- # stuff in Rails. Don't print the source file
31
- # its too noisy.
32
- printer.print(output, {:min_percent => 1,
33
- :print_file => false})
34
- logger.info(output.string)
35
-
36
- ## Example for Graph html printer
37
- #printer = RubyProf::GraphHtmlPrinter.new(result)
38
- #File.open('c:/temp/request.html', 'w') do |file|
39
- #printer.print(file, {:min_percent => 1,
40
- #:print_file => true})
41
- #end
42
-
43
- ## Used for KCacheGrind visualizations
44
- #printer = RubyProf::CallTreePrinter.new(result)
45
- #File.open('c:/temp/callgrind.out', 'w') do |file|
46
- #printer.print(file, {:min_percent => 1,
47
- #:print_file => true})
48
- #end
49
- end
50
- end
51
- end
52
- end