ruby-prof 1.5.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +13 -0
  3. data/ext/ruby_prof/rp_allocation.c +136 -81
  4. data/ext/ruby_prof/rp_allocation.h +8 -6
  5. data/ext/ruby_prof/rp_call_tree.c +8 -1
  6. data/ext/ruby_prof/rp_measurement.c +10 -3
  7. data/ext/ruby_prof/rp_method.c +51 -76
  8. data/ext/ruby_prof/rp_profile.c +62 -77
  9. data/ext/ruby_prof/rp_profile.h +1 -0
  10. data/ext/ruby_prof/rp_thread.c +14 -4
  11. data/ext/ruby_prof/vc/ruby_prof.vcxproj +1 -1
  12. data/lib/ruby-prof/compatibility.rb +14 -0
  13. data/lib/ruby-prof/printers/abstract_printer.rb +1 -1
  14. data/lib/ruby-prof/printers/call_tree_printer.rb +1 -1
  15. data/lib/ruby-prof/printers/multi_printer.rb +17 -17
  16. data/lib/ruby-prof/profile.rb +5 -5
  17. data/lib/ruby-prof/rack.rb +31 -21
  18. data/lib/ruby-prof/version.rb +1 -1
  19. data/test/abstract_printer_test.rb +1 -0
  20. data/test/alias_test.rb +6 -11
  21. data/test/call_tree_visitor_test.rb +1 -6
  22. data/test/call_trees_test.rb +2 -2
  23. data/test/{basic_test.rb → compatibility_test.rb} +8 -2
  24. data/test/duplicate_names_test.rb +1 -1
  25. data/test/dynamic_method_test.rb +1 -6
  26. data/test/enumerable_test.rb +1 -1
  27. data/test/exceptions_test.rb +2 -2
  28. data/test/exclude_methods_test.rb +3 -8
  29. data/test/exclude_threads_test.rb +4 -9
  30. data/test/fiber_test.rb +4 -9
  31. data/test/gc_test.rb +2 -1
  32. data/test/inverse_call_tree_test.rb +33 -34
  33. data/test/line_number_test.rb +1 -1
  34. data/test/marshal_test.rb +3 -3
  35. data/test/measure_allocations_test.rb +8 -17
  36. data/test/measure_memory_test.rb +3 -12
  37. data/test/measure_process_time_test.rb +29 -34
  38. data/test/measure_wall_time_test.rb +176 -181
  39. data/test/multi_printer_test.rb +0 -5
  40. data/test/no_method_class_test.rb +1 -1
  41. data/test/pause_resume_test.rb +12 -16
  42. data/test/printer_call_stack_test.rb +2 -2
  43. data/test/printer_call_tree_test.rb +2 -2
  44. data/test/printer_flat_test.rb +1 -1
  45. data/test/printer_graph_html_test.rb +2 -2
  46. data/test/printer_graph_test.rb +2 -2
  47. data/test/printers_test.rb +14 -20
  48. data/test/printing_recursive_graph_test.rb +2 -2
  49. data/test/recursive_test.rb +2 -7
  50. data/test/singleton_test.rb +1 -1
  51. data/test/stack_printer_test.rb +5 -8
  52. data/test/start_stop_test.rb +11 -14
  53. data/test/thread_test.rb +13 -15
  54. data/test/unique_call_path_test.rb +4 -4
  55. data/test/yarv_test.rb +3 -3
  56. metadata +4 -4
@@ -5,26 +5,22 @@ require File.expand_path('../test_helper', __FILE__)
5
5
  require_relative 'measure_times'
6
6
 
7
7
  class PauseResumeTest < TestCase
8
- def setup
9
- # Need to use wall time for this test due to the sleep calls
10
- RubyProf::measure_mode = RubyProf::WALL_TIME
11
- end
12
-
13
8
  def test_pause_resume
9
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
14
10
  # Measured
15
- RubyProf.start
11
+ profile.start
16
12
  RubyProf::C1.sleep_wait
17
13
 
18
14
  # Not measured
19
- RubyProf.pause
15
+ profile.pause
20
16
  sleep 1
21
17
  RubyProf::C1.sleep_wait
22
18
 
23
19
  # Measured
24
- RubyProf.resume
20
+ profile.resume
25
21
  RubyProf::C1.sleep_wait
26
22
 
27
- result = RubyProf.stop
23
+ result = profile.stop
28
24
 
29
25
  # Length should be 3:
30
26
  # PauseResumeTest#test_pause_resume
@@ -59,7 +55,7 @@ class PauseResumeTest < TestCase
59
55
 
60
56
  # pause/resume in the same frame
61
57
  def test_pause_resume_1
62
- profile = RubyProf::Profile.new
58
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
63
59
 
64
60
  profile.start
65
61
  method_1a
@@ -79,7 +75,7 @@ class PauseResumeTest < TestCase
79
75
 
80
76
  # pause in parent frame, resume in child
81
77
  def test_pause_resume_2
82
- profile = RubyProf::Profile.new
78
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
83
79
 
84
80
  profile.start
85
81
  method_2a
@@ -96,7 +92,7 @@ class PauseResumeTest < TestCase
96
92
 
97
93
  # pause in child frame, resume in parent
98
94
  def test_pause_resume_3
99
- profile = RubyProf::Profile.new
95
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
100
96
 
101
97
  profile.start
102
98
  method_3a(profile)
@@ -120,7 +116,7 @@ class PauseResumeTest < TestCase
120
116
  end
121
117
 
122
118
  def test_pause_seq
123
- profile = RubyProf::Profile.new
119
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
124
120
  profile.start ; assert !profile.paused?
125
121
  profile.pause ; assert profile.paused?
126
122
  profile.resume; assert !profile.paused?
@@ -132,7 +128,7 @@ class PauseResumeTest < TestCase
132
128
  end
133
129
 
134
130
  def test_pause_block
135
- profile = RubyProf::Profile.new
131
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
136
132
  profile.start
137
133
  profile.pause
138
134
  assert profile.paused?
@@ -151,7 +147,7 @@ class PauseResumeTest < TestCase
151
147
  end
152
148
 
153
149
  def test_pause_block_with_error
154
- profile = RubyProf::Profile.new
150
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
155
151
  profile.start
156
152
  profile.pause
157
153
  assert profile.paused?
@@ -167,7 +163,7 @@ class PauseResumeTest < TestCase
167
163
  end
168
164
 
169
165
  def test_resume_when_not_paused
170
- profile = RubyProf::Profile.new
166
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
171
167
  profile.start ; assert !profile.paused?
172
168
  profile.resume; assert !profile.paused?
173
169
  profile.stop ; assert !profile.paused?
@@ -9,9 +9,9 @@ require_relative 'prime'
9
9
  # -- Tests ----
10
10
  class PrinterCallStackTest < TestCase
11
11
  def setup
12
+ super
12
13
  # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
13
- RubyProf::measure_mode = RubyProf::WALL_TIME
14
- @result = RubyProf.profile do
14
+ @result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
15
15
  run_primes(1000, 5000)
16
16
  end
17
17
  end
@@ -9,9 +9,9 @@ require_relative 'prime'
9
9
  # -- Tests ----
10
10
  class PrinterCallTreeTest < TestCase
11
11
  def setup
12
+ super
12
13
  # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
13
- RubyProf::measure_mode = RubyProf::WALL_TIME
14
- @result = RubyProf.profile do
14
+ @result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
15
15
  run_primes(1000, 5000)
16
16
  end
17
17
  end
@@ -10,7 +10,7 @@ require_relative 'prime'
10
10
  # -- Tests ----
11
11
  class PrinterFlatTest < TestCase
12
12
  def run_profile
13
- RubyProf.profile(:measure_mode => RubyProf::WALL_TIME) do
13
+ RubyProf::Profile.profile(:measure_mode => RubyProf::WALL_TIME) do
14
14
  run_primes(1000, 5000)
15
15
  end
16
16
  end
@@ -9,9 +9,9 @@ require_relative 'prime'
9
9
  # -- Tests ----
10
10
  class PrinterGraphHtmlTest < TestCase
11
11
  def setup
12
+ super
12
13
  # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
13
- RubyProf::measure_mode = RubyProf::WALL_TIME
14
- @result = RubyProf.profile do
14
+ @result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
15
15
  run_primes(1000, 5000)
16
16
  end
17
17
  end
@@ -9,9 +9,9 @@ require_relative 'prime'
9
9
  # -- Tests ----
10
10
  class PrinterGraphTest < TestCase
11
11
  def setup
12
+ super
12
13
  # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
13
- RubyProf::measure_mode = RubyProf::WALL_TIME
14
- @result = RubyProf.profile do
14
+ @result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
15
15
  run_primes(1000, 5000)
16
16
  end
17
17
  end
@@ -10,9 +10,9 @@ require_relative 'prime'
10
10
  # -- Tests ----
11
11
  class PrintersTest < TestCase
12
12
  def setup
13
+ super
13
14
  # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
14
- RubyProf::measure_mode = RubyProf::WALL_TIME
15
- @result = RubyProf.profile do
15
+ @result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
16
16
  run_primes(1000, 5000)
17
17
  end
18
18
  end
@@ -24,7 +24,7 @@ class PrintersTest < TestCase
24
24
  printer.print(output)
25
25
 
26
26
  printer = RubyProf::CallTreePrinter.new(@result)
27
- printer.print()
27
+ printer.print(:path => Dir.tmpdir)
28
28
 
29
29
  printer = RubyProf::FlatPrinter.new(@result)
30
30
  printer.print(output)
@@ -37,25 +37,19 @@ class PrintersTest < TestCase
37
37
  end
38
38
 
39
39
  def test_print_to_files
40
- output_dir = 'tmp/examples2'
41
-
42
- if ENV['SAVE_NEW_PRINTER_EXAMPLES']
43
- output_dir = 'tmp/examples'
44
- end
45
- FileUtils.mkdir_p output_dir
46
-
47
40
  printer = RubyProf::DotPrinter.new(@result)
48
- File.open("#{output_dir}/graph.dot", "w") {|f| printer.print(f)}
41
+ File.open("#{Dir.tmpdir}/graph.dot", "w") {|f| printer.print(f)}
49
42
 
50
43
  printer = RubyProf::CallStackPrinter.new(@result)
51
- File.open("#{output_dir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
52
-
53
- # printer = RubyProf::MultiPrinter.new(@result)
54
- # printer.print(:path => "#{output_dir}", :profile => "multi", :application => "primes")
55
- # for file in ['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html']
56
- # existant_file = output_dir + '/' + file
57
- # assert File.size(existant_file) > 0
58
- # end
44
+ File.open("#{Dir.tmpdir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
45
+
46
+ printer = RubyProf::MultiPrinter.new(@result)
47
+ printer.print(:path => Dir.tmpdir, :profile => "multi", :application => "primes")
48
+
49
+ ['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html'].each do |file_name|
50
+ file_path = File.join(Dir.tmpdir, file_name)
51
+ refute(File.empty?(file_path))
52
+ end
59
53
  end
60
54
 
61
55
  def test_refuses_io_objects
@@ -124,7 +118,7 @@ class PrintersTest < TestCase
124
118
  end
125
119
 
126
120
  def test_all_with_small_percentiles
127
- result = RubyProf.profile do
121
+ result = RubyProf::Profile.profile do
128
122
  sleep 2
129
123
  do_nothing
130
124
  end
@@ -63,9 +63,9 @@ Sort by:
63
63
 
64
64
  class PrintingRecursiveGraphTest < TestCase
65
65
  def setup
66
+ super
66
67
  # WALL_TIME so we can use sleep in our test and get same measurements on linux and windows
67
- RubyProf::measure_mode = RubyProf::WALL_TIME
68
- @result = RubyProf.profile do
68
+ @result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
69
69
  PRGT.run
70
70
  end
71
71
  end
@@ -33,15 +33,10 @@ end
33
33
 
34
34
  # -- Tests ----
35
35
  class RecursiveTest < TestCase
36
- def setup
37
- # Need to use wall time for this test due to the sleep calls
38
- RubyProf::measure_mode = RubyProf::WALL_TIME
39
- end
40
-
41
36
  include SimpleRecursion
42
37
 
43
38
  def test_simple
44
- result = RubyProf.profile do
39
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
45
40
  simple(1)
46
41
  end
47
42
 
@@ -201,7 +196,7 @@ class RecursiveTest < TestCase
201
196
  end
202
197
 
203
198
  def test_cycle
204
- result = RubyProf.profile do
199
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
205
200
  render
206
201
  end
207
202
 
@@ -26,7 +26,7 @@ end
26
26
 
27
27
  class SingletonTest < TestCase
28
28
  def test_singleton
29
- result = RubyProf.profile do
29
+ result = RubyProf::Profile.profile do
30
30
  a = A.new
31
31
  a << :first_thing
32
32
  assert_equal(1, a.as.size)
@@ -27,16 +27,12 @@ class STPT
27
27
  end
28
28
 
29
29
  class StackPrinterTest < TestCase
30
- def setup
31
- # Need to use wall time for this test due to the sleep calls
32
- RubyProf::measure_mode = RubyProf::WALL_TIME
33
- end
34
-
35
30
  def test_stack_can_be_printed
36
31
  start_time = Time.now
37
- RubyProf.start
38
- 5.times{STPT.new.a}
39
- result = RubyProf.stop
32
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
33
+ 5.times{STPT.new.a}
34
+ end
35
+
40
36
  end_time = Time.now
41
37
  expected_time = end_time - start_time
42
38
 
@@ -50,6 +46,7 @@ class StackPrinterTest < TestCase
50
46
  end
51
47
 
52
48
  private
49
+
53
50
  def print(result)
54
51
  test = caller.first =~ /in `(.*)'/ ? $1 : "test"
55
52
  testfile_name = "#{Dir.tmpdir}/ruby_prof_#{test}.html"
@@ -5,37 +5,34 @@ require File.expand_path('../test_helper', __FILE__)
5
5
 
6
6
  class StartStopTest < TestCase
7
7
  def setup
8
+ super
8
9
  # Need to use wall time for this test due to the sleep calls
9
- RubyProf::measure_mode = RubyProf::WALL_TIME
10
+ @profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
10
11
  end
11
12
 
12
13
  def method1
13
- RubyProf.start
14
- method2
14
+ @profile.start
15
+ method2
15
16
  end
16
17
 
17
18
  def method2
18
- method3
19
+ method3
19
20
  end
20
21
 
21
22
  def method3
22
23
  sleep(2)
23
- @result = RubyProf.stop
24
+ @result = @profile.stop
24
25
  end
25
26
 
26
27
  def test_extra_stop_should_raise
27
- RubyProf.start
28
+ @profile.start
28
29
  assert_raises(RuntimeError) do
29
- RubyProf.start
30
+ @profile.start
30
31
  end
31
32
 
33
+ @profile.stop # ok
32
34
  assert_raises(RuntimeError) do
33
- RubyProf.profile {}
34
- end
35
-
36
- RubyProf.stop # ok
37
- assert_raises(RuntimeError) do
38
- RubyProf.stop
35
+ @profile.stop
39
36
  end
40
37
  end
41
38
 
@@ -43,7 +40,7 @@ class StartStopTest < TestCase
43
40
  method1
44
41
 
45
42
  # Ruby prof should be stopped
46
- assert_equal(false, RubyProf.running?)
43
+ assert_equal(false, @profile.running?)
47
44
 
48
45
  methods = @result.threads.first.methods.sort.reverse
49
46
  assert_equal(4, methods.length)
data/test/thread_test.rb CHANGED
@@ -8,11 +8,6 @@ require_relative './call_tree_builder'
8
8
 
9
9
  # -- Tests ----
10
10
  class ThreadTest < TestCase
11
- def setup
12
- # Need to use wall time for this test due to the sleep calls
13
- RubyProf::measure_mode = RubyProf::WALL_TIME
14
- end
15
-
16
11
  def test_initialize
17
12
  method_info = RubyProf::MethodInfo.new(Array, :size)
18
13
  call_tree = RubyProf::CallTree.new(method_info)
@@ -39,24 +34,25 @@ class ThreadTest < TestCase
39
34
  end
40
35
 
41
36
  def test_thread_count
42
- RubyProf.start
37
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
38
+ thread = Thread.new do
39
+ sleep(1)
40
+ end
43
41
 
44
- thread = Thread.new do
45
- sleep(1)
42
+ thread.join
46
43
  end
47
-
48
- thread.join
49
- result = RubyProf.stop
50
44
  assert_equal(2, result.threads.length)
51
45
  end
52
46
 
53
47
  def test_thread_identity
54
- RubyProf.start
48
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
49
+ profile.start
50
+
55
51
  sleep_thread = Thread.new do
56
52
  sleep(1)
57
53
  end
58
54
  sleep_thread.join
59
- result = RubyProf.stop
55
+ result = profile.stop
60
56
 
61
57
  thread_ids = result.threads.map {|thread| thread.id}.sort
62
58
  threads = [Thread.current, sleep_thread]
@@ -73,7 +69,9 @@ class ThreadTest < TestCase
73
69
  end
74
70
 
75
71
  def test_thread_timings
76
- RubyProf.start
72
+ profile = RubyProf::Profile.new(measure_mode: RubyProf::WALL_TIME)
73
+ profile.start
74
+
77
75
  thread = Thread.new do
78
76
  sleep 0
79
77
  # force it to hit thread.join, below, first
@@ -83,7 +81,7 @@ class ThreadTest < TestCase
83
81
  sleep(1)
84
82
  end
85
83
  thread.join
86
- result = RubyProf.stop
84
+ result = profile.stop
87
85
 
88
86
  # Check background thread
89
87
  assert_equal(2, result.threads.length)
@@ -30,7 +30,7 @@ class UniqueCallPathTest < TestCase
30
30
  def test_root
31
31
  unique_call_path = UniqueCallPath.new
32
32
 
33
- result = RubyProf.profile do
33
+ result = RubyProf::Profile.profile do
34
34
  unique_call_path.method_a(1)
35
35
  end
36
36
 
@@ -41,7 +41,7 @@ class UniqueCallPathTest < TestCase
41
41
  def test_root_children
42
42
  unique_call_path = UniqueCallPath.new
43
43
 
44
- result = RubyProf.profile do
44
+ result = RubyProf::Profile.profile do
45
45
  unique_call_path.method_a(1)
46
46
  unique_call_path.method_k(2)
47
47
  end
@@ -59,7 +59,7 @@ class UniqueCallPathTest < TestCase
59
59
  def test_children_of
60
60
  unique_call_path = UniqueCallPath.new
61
61
 
62
- result = RubyProf.profile do
62
+ result = RubyProf::Profile.profile do
63
63
  unique_call_path.method_a(1)
64
64
  unique_call_path.method_k(2)
65
65
  end
@@ -92,7 +92,7 @@ class UniqueCallPathTest < TestCase
92
92
  def test_unique_path
93
93
  unique_call_path = UniqueCallPath.new
94
94
 
95
- result = RubyProf.profile do
95
+ result = RubyProf::Profile.profile do
96
96
  unique_call_path.method_a(1)
97
97
  unique_call_path.method_k(1)
98
98
  end
data/test/yarv_test.rb CHANGED
@@ -6,13 +6,13 @@ require File.expand_path('../test_helper', __FILE__)
6
6
  # tests for bugs reported by users
7
7
  class YarvTest < TestCase
8
8
  def setup
9
- RubyProf::measure_mode = RubyProf::WALL_TIME
9
+ super
10
10
  define_methods
11
11
  end
12
12
 
13
13
  def test_array_push_unoptimized
14
14
  a = nil
15
- result = RubyProf.profile do
15
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
16
16
  a = self.array_push_unoptimized
17
17
  end
18
18
  assert_equal 2, a.length
@@ -21,7 +21,7 @@ class YarvTest < TestCase
21
21
 
22
22
  def test_array_push_optimized
23
23
  a = nil
24
- result = RubyProf.profile do
24
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
25
25
  a = self.array_push_optimized
26
26
  end
27
27
  assert_equal(2, a.length)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -112,11 +112,11 @@ files:
112
112
  - ruby-prof.gemspec
113
113
  - test/abstract_printer_test.rb
114
114
  - test/alias_test.rb
115
- - test/basic_test.rb
116
115
  - test/call_tree_builder.rb
117
116
  - test/call_tree_test.rb
118
117
  - test/call_tree_visitor_test.rb
119
118
  - test/call_trees_test.rb
119
+ - test/compatibility_test.rb
120
120
  - test/duplicate_names_test.rb
121
121
  - test/dynamic_method_test.rb
122
122
  - test/enumerable_test.rb
@@ -166,7 +166,7 @@ metadata:
166
166
  bug_tracker_uri: https://github.com/ruby-prof/ruby-prof/issues
167
167
  changelog_uri: https://github.com/ruby-prof/ruby-prof/blob/master/CHANGES
168
168
  documentation_uri: https://ruby-prof.github.io/
169
- source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.5.0
169
+ source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v1.6.1
170
170
  post_install_message:
171
171
  rdoc_options: []
172
172
  require_paths: