ruby-prof 0.11.0.rc3-x86-mingw32 → 0.11.2-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,11 +42,13 @@ void method_key(prof_method_key_t* key, VALUE klass, ID mid);
42
42
  typedef struct
43
43
  {
44
44
  VALUE running;
45
+ VALUE paused;
45
46
  prof_measurer_t* measurer;
46
47
  VALUE threads;
47
48
  st_table* threads_tbl;
48
49
  st_table* exclude_threads_tbl;
49
50
  thread_data_t* last_thread_data;
51
+ double measurement_at_pause_resume;
50
52
  } prof_profile_t;
51
53
 
52
54
 
@@ -64,6 +64,8 @@
64
64
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
65
65
  <LinkIncremental>true</LinkIncremental>
66
66
  <OutDir>C:\MinGW\local\src\ruby-prof\lib\1.8</OutDir>
67
+ <TargetExt>.so</TargetExt>
68
+ <TargetName>ruby_prof</TargetName>
67
69
  </PropertyGroup>
68
70
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
69
71
  <LinkIncremental>false</LinkIncremental>
@@ -81,6 +83,7 @@
81
83
  <GenerateDebugInformation>true</GenerateDebugInformation>
82
84
  <AdditionalLibraryDirectories>C:\MinGW\local\ruby187vc\lib</AdditionalLibraryDirectories>
83
85
  <AdditionalDependencies>msvcr100-ruby18.lib;%(AdditionalDependencies)</AdditionalDependencies>
86
+ <ModuleDefinitionFile>ruby_prof.def</ModuleDefinitionFile>
84
87
  </Link>
85
88
  </ItemDefinitionGroup>
86
89
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -1,7 +1,7 @@
1
1
  /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
- #define RUBY_PROF_VERSION "0.11.0" // for easy parsing from rake files
4
+ #define RUBY_PROF_VERSION "0.11.2" // for easy parsing from rake files
5
5
  #define RUBY_PROF_VERSION_MAJ 0
6
6
  #define RUBY_PROF_VERSION_MIN 11
7
- #define RUBY_PROF_VERSION_MIC 0
7
+ #define RUBY_PROF_VERSION_MIC 2
Binary file
Binary file
@@ -18,7 +18,7 @@ module RubyProf
18
18
  def self.measure_cpu_time
19
19
  Measure::CpuTime.measure
20
20
  end
21
-
21
+
22
22
  def self.measure_gc_runs
23
23
  Measure::GcRuns.measure
24
24
  end
@@ -38,7 +38,7 @@ module RubyProf
38
38
  def self.measure_wall_time
39
39
  Measure::WallTime.measure
40
40
  end
41
-
41
+
42
42
  # call-seq:
43
43
  # measure_mode -> measure_mode
44
44
  #
@@ -51,11 +51,11 @@ module RubyProf
51
51
  # *RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter.
52
52
  # *RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter.
53
53
  # *RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.*/
54
-
54
+
55
55
  def self.measure_mode
56
56
  @measure_mode ||= RubyProf::WALL_TIME
57
57
  end
58
-
58
+
59
59
  # call-seq:
60
60
  # measure_mode=value -> void
61
61
  #
@@ -71,33 +71,31 @@ module RubyProf
71
71
  def self.measure_mode=(value)
72
72
  @measure_mode = value
73
73
  end
74
-
74
+
75
75
  # call-seq:
76
76
  # exclude_threads= -> void
77
77
  #
78
78
  # Specifies what threads ruby-prof should exclude from profiling
79
-
79
+
80
80
  def self.exclude_threads
81
81
  @exclude_threads ||= Array.new
82
82
  end
83
-
83
+
84
84
  def self.exclude_threads=(value)
85
85
  @exclude_threads = value
86
86
  end
87
-
87
+
88
88
  # Profiling
89
89
  def self.start
90
- if running?
91
- raise(RuntimeError, "RubyProf is already running");
92
- end
90
+ ensure_not_running!
93
91
  @profile = Profile.new(self.measure_mode, self.exclude_threads)
92
+ enable_gc_stats_if_needed
94
93
  @profile.start
95
94
  end
96
95
 
97
96
  def self.pause
98
- unless running?
99
- raise(RuntimeError, "RubyProf.start was not yet called");
100
- end
97
+ ensure_running!
98
+ disable_gc_stats_if_needed
101
99
  @profile.pause
102
100
  end
103
101
 
@@ -110,25 +108,47 @@ module RubyProf
110
108
  end
111
109
 
112
110
  def self.resume
113
- unless running?
114
- raise(RuntimeError, "RubyProf.start was not yet called");
115
- end
111
+ ensure_running!
112
+ enable_gc_stats_if_needed
116
113
  @profile.resume
117
114
  end
118
115
 
119
116
  def self.stop
120
- unless running?
121
- raise(RuntimeError, "RubyProf.start was not yet called");
122
- end
117
+ ensure_running!
118
+ disable_gc_stats_if_needed
123
119
  result = @profile.stop
124
120
  @profile = nil
125
121
  result
126
122
  end
127
123
 
124
+ # Profile a block
128
125
  def self.profile(&block)
129
- if running?
130
- raise(RuntimeError, "RubyProf is already running");
126
+ ensure_not_running!
127
+ gc_stat_was_enabled = enable_gc_stats_if_needed
128
+ res = Profile.profile(self.measure_mode, self.exclude_threads, &block)
129
+ disable_gc_stats_if_needed(gc_stat_was_enabled)
130
+ res
131
+ end
132
+
133
+
134
+ private
135
+ def self.ensure_running!
136
+ raise(RuntimeError, "RubyProf.start was not yet called") unless running?
137
+ end
138
+
139
+ def self.ensure_not_running!
140
+ raise(RuntimeError, "RubyProf is already running") if running?
141
+ end
142
+
143
+ # for GC.allocated_size to work GC statistics should be enabled
144
+ def self.enable_gc_stats_if_needed
145
+ if self.measure_mode == RubyProf::MEMORY && GC.respond_to?(:enable_stats)
146
+ @gc_stat_was_enabled = GC.enable_stats
131
147
  end
132
- Profile.profile(self.measure_mode, self.exclude_threads, &block)
148
+ end
149
+
150
+ def self.disable_gc_stats_if_needed(was_enabled=nil)
151
+ was_enabled ||= defined?(@gc_stat_was_enabled) && @gc_stat_was_enabled
152
+ GC.disable_stats if self.measure_mode == RubyProf::MEMORY && GC.respond_to?(:disable_stats) && !was_enabled
133
153
  end
134
154
  end
@@ -62,7 +62,7 @@ module RubyProf
62
62
 
63
63
  def print_footer(thread)
64
64
  @output << "\n"
65
- @output << "* in front of method name means it is recursively called\n"
65
+ @output << "* indicates recursively called methods\n"
66
66
  end
67
67
  end
68
68
  end
@@ -235,7 +235,7 @@ module RubyProf
235
235
  </tbody>
236
236
  <tfoot>
237
237
  <tr>
238
- <td colspan="9">* in front of method name means it is recursively called</td>
238
+ <td colspan="9">* indicates recursively called methods</td>
239
239
  </tr>
240
240
  </tfoot>
241
241
  </table>
@@ -109,7 +109,7 @@ module RubyProf
109
109
 
110
110
  def print_footer(thread)
111
111
  @output << "\n"
112
- @output << "* in front of method name means it is recursively called\n"
112
+ @output << "* indicates recursively called methods\n"
113
113
  end
114
114
  end
115
115
  end
@@ -6,8 +6,7 @@ version_header = File.read(File.expand_path('../ext/ruby_prof/version.h', __FILE
6
6
  match = version_header.match(/RUBY_PROF_VERSION\s*"([^"]+)"/)
7
7
  raise(RuntimeError, "Could not determine RUBY_PROF_VERSION") if not match
8
8
 
9
- # For now make this an rc1
10
- RUBY_PROF_VERSION = "#{match[1]}.rc3"
9
+ RUBY_PROF_VERSION = "#{match[1]}"
11
10
 
12
11
  Gem::Specification.new do |spec|
13
12
  spec.name = "ruby-prof"
@@ -39,4 +39,58 @@ class BasicTest < Test::Unit::TestCase
39
39
 
40
40
  RubyProf.stop
41
41
  end
42
- end
42
+
43
+ def test_pause_seq
44
+ p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
45
+ p.start ; assert !p.paused?
46
+ p.pause ; assert p.paused?
47
+ p.resume; assert !p.paused?
48
+ p.pause ; assert p.paused?
49
+ p.pause ; assert p.paused?
50
+ p.resume; assert !p.paused?
51
+ p.resume; assert !p.paused?
52
+ p.stop ; assert !p.paused?
53
+ end
54
+
55
+ def test_pause_block
56
+ p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
57
+ p.start
58
+ p.pause
59
+ assert p.paused?
60
+
61
+ times_block_invoked = 0
62
+ retval= p.resume{
63
+ times_block_invoked += 1
64
+ 120 + times_block_invoked
65
+ }
66
+ assert_equal 1, times_block_invoked
67
+ assert p.paused?
68
+
69
+ assert_equal 121, retval, "resume() should return the result of the given block."
70
+
71
+ p.stop
72
+ end
73
+
74
+ def test_pause_block_with_error
75
+ p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
76
+ p.start
77
+ p.pause
78
+ assert p.paused?
79
+
80
+ begin
81
+ p.resume{ raise }
82
+ flunk 'Exception expected.'
83
+ rescue
84
+ assert p.paused?
85
+ end
86
+
87
+ p.stop
88
+ end
89
+
90
+ def test_resume_when_not_paused
91
+ p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
92
+ p.start ; assert !p.paused?
93
+ p.resume; assert !p.paused?
94
+ p.stop ; assert !p.paused?
95
+ end
96
+ end
@@ -5,11 +5,9 @@ require File.expand_path('../test_helper', __FILE__)
5
5
 
6
6
  class LineNumbers
7
7
  def method1
8
- 3
9
8
  end
10
9
 
11
10
  def method2
12
- 3
13
11
  method1
14
12
  end
15
13
 
@@ -32,11 +30,11 @@ class LineNumbersTest < Test::Unit::TestCase
32
30
 
33
31
  method = methods[0]
34
32
  assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
35
- assert_equal(27, method.line)
33
+ assert_equal(25, method.line)
36
34
 
37
35
  method = methods[1]
38
36
  assert_equal('LineNumbers#method2', method.full_name)
39
- assert_equal(11, method.line)
37
+ assert_equal(10, method.line)
40
38
 
41
39
  method = methods[2]
42
40
  assert_equal('LineNumbers#method1', method.full_name)
@@ -64,10 +62,10 @@ class LineNumbersTest < Test::Unit::TestCase
64
62
 
65
63
  method = methods[1]
66
64
  assert_equal('LineNumbers#method3', method.full_name)
67
- assert_equal(16, method.line)
65
+ assert_equal(14, method.line)
68
66
 
69
67
  method = methods[2]
70
68
  assert_equal('LineNumbersTest#test_c_function', method.full_name)
71
- assert_equal(50, method.line)
69
+ assert_equal(48, method.line)
72
70
  end
73
71
  end
@@ -23,9 +23,6 @@ class MeasureCpuTimeTest < Test::Unit::TestCase
23
23
  RubyProf::C1.hello
24
24
  end
25
25
 
26
- printer = RubyProf::FlatPrinter.new(result)
27
- printer.print
28
-
29
26
  # Length should be 3:
30
27
  # MeasureCpuTimeTest#test_class_methods
31
28
  # <Class::RubyProf::C1>#hello
@@ -57,7 +57,6 @@ class MultiPrinterTest < Test::Unit::TestCase
57
57
  \s*</table>')
58
58
  assert graph =~ re
59
59
  display_time = $1.to_f
60
- difference = (expected_time-display_time).abs
61
60
  assert_in_delta expected_time, display_time, 0.005
62
61
  end
63
62
 
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class PauseResumeTest < Test::Unit::TestCase
7
+
8
+ # pause/resume in the same frame
9
+ def test_pause_resume_1
10
+ p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
11
+
12
+ p.start
13
+ method_1a
14
+
15
+ p.pause
16
+ method_1b
17
+
18
+ p.resume
19
+ method_1c
20
+
21
+ r= p.stop
22
+ assert_in_delta(0.6, r.threads[0].methods.select{|m| m.full_name =~ /test_pause_resume_1$/}[0].total_time, 0.05)
23
+ end
24
+ def method_1a; sleep 0.2 end
25
+ def method_1b; sleep 1 end
26
+ def method_1c; sleep 0.4 end
27
+
28
+ # pause in parent frame, resume in child
29
+ def test_pause_resume_2
30
+ p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
31
+
32
+ p.start
33
+ method_2a
34
+
35
+ p.pause
36
+ sleep 0.5
37
+ method_2b(p)
38
+
39
+ r= p.stop
40
+ assert_in_delta(0.6, r.threads[0].methods.select{|m| m.full_name =~ /test_pause_resume_2$/}[0].total_time, 0.05)
41
+ end
42
+ def method_2a; sleep 0.2 end
43
+ def method_2b(p); sleep 0.5; p.resume; sleep 0.4 end
44
+
45
+ # pause in child frame, resume in parent
46
+ def test_pause_resume_3
47
+ p= RubyProf::Profile.new(RubyProf::WALL_TIME,[])
48
+
49
+ p.start
50
+ method_3a(p)
51
+
52
+ sleep 0.5
53
+ p.resume
54
+ method_3b
55
+
56
+ r= p.stop
57
+ assert_in_delta(0.6, r.threads[0].methods.select{|m| m.full_name =~ /test_pause_resume_3$/}[0].total_time, 0.05)
58
+ end
59
+ def method_3a(p); sleep 0.2; p.pause; sleep 0.5 end
60
+ def method_3b; sleep 0.4 end
61
+ end
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class PauseTest < Test::Unit::TestCase
7
+ def setup
8
+ # Need to use wall time for this test due to the sleep calls
9
+ RubyProf::measure_mode = RubyProf::WALL_TIME
10
+ end
11
+
12
+ def test_pause_resume
13
+ RubyProf.start
14
+ # Measured
15
+ RubyProf::C1.hello
16
+ RubyProf.pause
17
+
18
+ # Not measured
19
+ RubyProf::C1.hello
20
+
21
+ RubyProf.resume
22
+ # Measured
23
+ RubyProf::C1.hello
24
+ result = RubyProf.stop
25
+
26
+ printer = RubyProf::FlatPrinter.new(result)
27
+ printer.print
28
+
29
+ # Length should be 3:
30
+ # PauseTest#test_pause_resume
31
+ # <Class::RubyProf::C1>#hello
32
+ # Kernel#sleep
33
+
34
+ methods = result.threads.first.methods.sort.reverse
35
+ assert_equal(3, methods.length)
36
+
37
+ # Check the names
38
+ assert_equal('PauseTest#test_pause_resume', methods[0].full_name)
39
+ assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
40
+ assert_equal('Kernel#sleep', methods[2].full_name)
41
+
42
+ # Check times
43
+ assert_in_delta(0.1, methods[0].total_time, 0.01)
44
+ assert_in_delta(0, methods[0].wait_time, 0.01)
45
+ assert_in_delta(0, methods[0].self_time, 0.01)
46
+
47
+ assert_in_delta(0.1, methods[1].total_time, 0.01)
48
+ assert_in_delta(0, methods[1].wait_time, 0.01)
49
+ assert_in_delta(0, methods[1].self_time, 0.01)
50
+
51
+ assert_in_delta(0.1, methods[2].total_time, 0.01)
52
+ assert_in_delta(0, methods[2].wait_time, 0.01)
53
+ assert_in_delta(0.1, methods[2].self_time, 0.01)
54
+
55
+ end
56
+
57
+ end