ruby-prof 0.15.9 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +27 -1
  3. data/README.rdoc +83 -31
  4. data/bin/ruby-prof +4 -4
  5. data/doc/LICENSE.html +1 -1
  6. data/doc/README_rdoc.html +92 -33
  7. data/doc/Rack.html +1 -1
  8. data/doc/Rack/RubyProf.html +17 -14
  9. data/doc/RubyProf.html +30 -29
  10. data/doc/RubyProf/AbstractPrinter.html +1 -1
  11. data/doc/RubyProf/AggregateCallInfo.html +1 -1
  12. data/doc/RubyProf/CallInfo.html +1 -1
  13. data/doc/RubyProf/CallInfoPrinter.html +1 -1
  14. data/doc/RubyProf/CallInfoVisitor.html +1 -1
  15. data/doc/RubyProf/CallStackPrinter.html +1 -1
  16. data/doc/RubyProf/CallTreePrinter.html +349 -67
  17. data/doc/RubyProf/Cmd.html +5 -5
  18. data/doc/RubyProf/DotPrinter.html +2 -2
  19. data/doc/RubyProf/FlatPrinter.html +1 -1
  20. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +1 -1
  21. data/doc/RubyProf/GraphHtmlPrinter.html +1 -1
  22. data/doc/RubyProf/GraphPrinter.html +1 -1
  23. data/doc/RubyProf/MethodInfo.html +2 -2
  24. data/doc/RubyProf/MultiPrinter.html +11 -9
  25. data/doc/RubyProf/Profile.html +94 -44
  26. data/doc/RubyProf/ProfileTask.html +1 -1
  27. data/doc/RubyProf/Thread.html +43 -1
  28. data/doc/created.rid +16 -16
  29. data/doc/examples/flat_txt.html +1 -1
  30. data/doc/examples/graph_html.html +1 -1
  31. data/doc/examples/graph_txt.html +3 -3
  32. data/doc/index.html +85 -30
  33. data/doc/js/navigation.js.gz +0 -0
  34. data/doc/js/search_index.js +1 -1
  35. data/doc/js/search_index.js.gz +0 -0
  36. data/doc/js/searcher.js +2 -2
  37. data/doc/js/searcher.js.gz +0 -0
  38. data/doc/table_of_contents.html +117 -68
  39. data/examples/cachegrind.out.1 +114 -0
  40. data/examples/cachegrind.out.1.32313213 +114 -0
  41. data/examples/graph.txt +1 -1
  42. data/ext/ruby_prof/extconf.rb +6 -2
  43. data/ext/ruby_prof/rp_measure_cpu_time.c +29 -31
  44. data/ext/ruby_prof/rp_method.c +1 -1
  45. data/ext/ruby_prof/rp_thread.c +57 -52
  46. data/ext/ruby_prof/ruby_prof.c +122 -66
  47. data/ext/ruby_prof/ruby_prof.h +2 -0
  48. data/lib/ruby-prof.rb +14 -13
  49. data/lib/ruby-prof/assets/call_stack_printer.js.html +1 -1
  50. data/lib/ruby-prof/compatibility.rb +9 -8
  51. data/lib/ruby-prof/method_info.rb +1 -1
  52. data/lib/ruby-prof/printers/call_tree_printer.rb +88 -50
  53. data/lib/ruby-prof/printers/dot_printer.rb +1 -1
  54. data/lib/ruby-prof/printers/multi_printer.rb +6 -4
  55. data/lib/ruby-prof/profile.rb +0 -1
  56. data/lib/ruby-prof/rack.rb +53 -16
  57. data/lib/ruby-prof/thread.rb +11 -0
  58. data/lib/ruby-prof/version.rb +1 -1
  59. data/test/exclude_threads_test.rb +2 -3
  60. data/test/fiber_test.rb +21 -7
  61. data/test/measure_cpu_time_test.rb +84 -24
  62. data/test/multi_printer_test.rb +5 -4
  63. data/test/pause_resume_test.rb +7 -7
  64. data/test/printers_test.rb +6 -4
  65. data/test/rack_test.rb +26 -1
  66. data/test/test_helper.rb +28 -3
  67. data/test/thread_test.rb +1 -0
  68. metadata +5 -3
@@ -63,6 +63,7 @@ class MultiPrinterTest < TestCase
63
63
  end
64
64
 
65
65
  private
66
+
66
67
  def print(result)
67
68
  test = caller.first =~ /in `(.*)'/ ? $1 : "test"
68
69
  path = RubyProf.tmpdir
@@ -73,10 +74,10 @@ class MultiPrinterTest < TestCase
73
74
  if RUBY_PLATFORM =~ /darwin/ && ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT']=="1"
74
75
  system("open '#{printer.stack_profile}'")
75
76
  end
76
- if GC.respond_to?(:dump_file_and_line_info)
77
- GC.start
78
- GC.dump_file_and_line_info("heap.dump")
79
- end
77
+ # if GC.respond_to?(:dump_file_and_line_info)
78
+ # GC.start
79
+ # GC.dump_file_and_line_info("heap.dump")
80
+ # end
80
81
  [File.read(printer.stack_profile), File.read(printer.graph_profile)]
81
82
  end
82
83
  end
@@ -58,7 +58,7 @@ class PauseResumeTest < TestCase
58
58
 
59
59
  # pause/resume in the same frame
60
60
  def test_pause_resume_1
61
- profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
61
+ profile = RubyProf::Profile.new
62
62
 
63
63
  profile.start
64
64
  method_1a
@@ -78,7 +78,7 @@ class PauseResumeTest < TestCase
78
78
 
79
79
  # pause in parent frame, resume in child
80
80
  def test_pause_resume_2
81
- profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
81
+ profile = RubyProf::Profile.new
82
82
 
83
83
  profile.start
84
84
  method_2a
@@ -95,7 +95,7 @@ class PauseResumeTest < TestCase
95
95
 
96
96
  # pause in child frame, resume in parent
97
97
  def test_pause_resume_3
98
- profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
98
+ profile = RubyProf::Profile.new
99
99
 
100
100
  profile.start
101
101
  method_3a(profile)
@@ -111,7 +111,7 @@ class PauseResumeTest < TestCase
111
111
  def method_3b; sleep 0.4 end
112
112
 
113
113
  def test_pause_seq
114
- profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
114
+ profile = RubyProf::Profile.new
115
115
  profile.start ; assert !profile.paused?
116
116
  profile.pause ; assert profile.paused?
117
117
  profile.resume; assert !profile.paused?
@@ -123,7 +123,7 @@ class PauseResumeTest < TestCase
123
123
  end
124
124
 
125
125
  def test_pause_block
126
- profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
126
+ profile = RubyProf::Profile.new
127
127
  profile.start
128
128
  profile.pause
129
129
  assert profile.paused?
@@ -142,7 +142,7 @@ class PauseResumeTest < TestCase
142
142
  end
143
143
 
144
144
  def test_pause_block_with_error
145
- profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
145
+ profile = RubyProf::Profile.new
146
146
  profile.start
147
147
  profile.pause
148
148
  assert profile.paused?
@@ -158,7 +158,7 @@ class PauseResumeTest < TestCase
158
158
  end
159
159
 
160
160
  def test_resume_when_not_paused
161
- profile = RubyProf::Profile.new(RubyProf::WALL_TIME,[])
161
+ profile = RubyProf::Profile.new
162
162
  profile.start ; assert !profile.paused?
163
163
  profile.resume; assert !profile.paused?
164
164
  profile.stop ; assert !profile.paused?
@@ -23,7 +23,7 @@ class PrintersTest < TestCase
23
23
  printer.print(output)
24
24
 
25
25
  printer = RubyProf::CallTreePrinter.new(@result)
26
- printer.print(output)
26
+ printer.print()
27
27
 
28
28
  printer = RubyProf::FlatPrinter.new(@result)
29
29
  printer.print(output)
@@ -56,7 +56,7 @@ class PrintersTest < TestCase
56
56
 
57
57
  printer = RubyProf::MultiPrinter.new(@result)
58
58
  printer.print(:path => "#{output_dir}", :profile => "multi", :application => "primes")
59
- for file in ['graph.dot', 'multi.flat.txt', 'multi.graph.html', 'multi.grind.dat', 'multi.stack.html', 'stack.html']
59
+ for file in ['graph.dot', 'multi.flat.txt', 'multi.graph.html', "multi.callgrind.out.#{$$}", 'multi.stack.html', 'stack.html']
60
60
  existant_file = output_dir + '/' + file
61
61
  assert File.size(existant_file) > 0
62
62
  end
@@ -115,9 +115,11 @@ class PrintersTest < TestCase
115
115
  end
116
116
 
117
117
  def test_call_tree_string
118
- output = ''
119
118
  printer = RubyProf::CallTreePrinter.new(@result)
120
- printer.print(output)
119
+ printer.print(:profile => "lolcat", :path => RubyProf.tmpdir)
120
+ main_output_file_name = File.join(RubyProf.tmpdir, "lolcat.callgrind.out.#{$$}")
121
+ assert(File.exist?(main_output_file_name))
122
+ output = File.read(main_output_file_name)
121
123
  assert_match(/fn=Object#find_primes/i, output)
122
124
  assert_match(/events: wall_time/i, output)
123
125
  refute_match(/d\d\d\d\d\d/, output) # old bug looked [in error] like Object::run_primes(d5833116)
@@ -11,9 +11,15 @@ end
11
11
  module Rack
12
12
  class Request
13
13
  def initialize(env)
14
+ if env == :fake_env
15
+ @env = {}
16
+ else
17
+ @env = env
18
+ end
14
19
  end
20
+
15
21
  def path
16
- '/path/to/resource.json'
22
+ @env[:path] || '/path/to/resource.json'
17
23
  end
18
24
  end
19
25
  end
@@ -54,6 +60,25 @@ class RackTest < TestCase
54
60
  end
55
61
  end
56
62
 
63
+ def test_only_paths
64
+ path = Dir.mktmpdir
65
+
66
+ adapter = Rack::RubyProf.new(FakeRackApp.new, :path => path, :only_paths => [%r{\.json$}])
67
+
68
+ adapter.call({path: '/path/to/resource.json'})
69
+
70
+ %w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
71
+ file_path = ::File.join(path, "path-to-resource.json-#{base_name}")
72
+ assert(File.exist?(file_path))
73
+ end
74
+
75
+ adapter.call({path: '/path/to/resource.html'})
76
+ %w(flat.txt graph.txt graph.html call_stack.html).each do |base_name|
77
+ file_path = ::File.join(path, "path-to-resource.html-#{base_name}")
78
+ assert(!File.exist?(file_path))
79
+ end
80
+ end
81
+
57
82
  def test_allows_lazy_filename_setting
58
83
  path = Dir.mktmpdir
59
84
 
@@ -28,9 +28,22 @@ require 'ruby-prof'
28
28
  require 'minitest/autorun'
29
29
 
30
30
  class TestCase < Minitest::Test
31
+ # I know this sucks, but ...
31
32
  def assert_nothing_raised(*)
32
33
  yield
33
34
  end
35
+
36
+ def before_setup
37
+ # make sure to exclude all threads except the one running the test
38
+ # minitest allocates a thread pool and they would otherwise show
39
+ # up in the profile data, breaking tests randomly
40
+ RubyProf.exclude_threads = Thread.list.select{|t| t != Thread.current}
41
+ end
42
+
43
+ def after_teardown
44
+ # reset exclude threads after testing
45
+ RubyProf.exclude_threads = nil
46
+ end
34
47
  end
35
48
 
36
49
  require File.expand_path('../prime', __FILE__)
@@ -85,22 +98,34 @@ module RubyProf
85
98
  end
86
99
 
87
100
  class C7
88
- def self.hello
101
+ def self.busy_wait
89
102
  t = Time.now.to_f
90
103
  while Time.now.to_f - t < 0.1; end
91
104
  end
92
105
 
93
- def hello
106
+ def self.sleep_wait
107
+ sleep 0.1
108
+ end
109
+
110
+ def busy_wait
94
111
  t = Time.now.to_f
95
112
  while Time.now.to_f - t < 0.2; end
96
113
  end
114
+
115
+ def sleep_wait
116
+ sleep 0.2
117
+ end
97
118
  end
98
119
 
99
120
  module M7
100
- def hello
121
+ def busy_wait
101
122
  t = Time.now.to_f
102
123
  while Time.now.to_f - t < 0.3; end
103
124
  end
125
+
126
+ def sleep_wait
127
+ sleep 0.3
128
+ end
104
129
  end
105
130
 
106
131
  class C8
@@ -171,6 +171,7 @@ class ThreadTest < TestCase
171
171
  assert(timings[-1].total_time < seconds)
172
172
  end
173
173
 
174
+ # useless test: what does it test?
174
175
  def test_thread
175
176
  RubyProf.profile do
176
177
  begin
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: 0.15.9
4
+ version: 0.16.0
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: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2016-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -144,6 +144,8 @@ files:
144
144
  - doc/js/searcher.js
145
145
  - doc/js/searcher.js.gz
146
146
  - doc/table_of_contents.html
147
+ - examples/cachegrind.out.1
148
+ - examples/cachegrind.out.1.32313213
147
149
  - examples/flat.txt
148
150
  - examples/graph.dot
149
151
  - examples/graph.html
@@ -261,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
263
  version: '0'
262
264
  requirements: []
263
265
  rubyforge_project:
264
- rubygems_version: 2.4.8
266
+ rubygems_version: 2.6.4
265
267
  signing_key:
266
268
  specification_version: 4
267
269
  summary: Fast Ruby profiler