ruby-prof 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 0.9.2
2
+ =======================
3
+ Make graphviz work on 1.8.6
4
+ roll back some 1.9.2 optimizations until I can figure out what caused them.
5
+
1
6
  0.9.1
2
7
  =======================
3
8
  Add a graphviz output
@@ -1086,10 +1086,10 @@ prof_pop_threads()
1086
1086
  }
1087
1087
 
1088
1088
  #if RUBY_VERSION == 190
1089
- # error 1.9.0 not supported (ask for it if desired)
1089
+ # error 1.9.0 not supported (ask for it if you desire it to be supported)
1090
1090
  #endif
1091
1091
 
1092
- #if RUBY_VERSION == 191
1092
+ #if RUBY_VERSION >= 191
1093
1093
 
1094
1094
  /* Avoid bugs in 1.9.1 */
1095
1095
 
@@ -1160,7 +1160,7 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
1160
1160
  thread = rb_thread_current();
1161
1161
  thread_id = rb_obj_id(thread);
1162
1162
 
1163
- # if RUBY_VERSION == 191
1163
+ # if RUBY_VERSION >= 191
1164
1164
  /* ensure that new threads are hooked [sigh] (bug in core) */
1165
1165
  prof_remove_hook();
1166
1166
  prof_install_hook();
@@ -1194,7 +1194,7 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
1194
1194
  {
1195
1195
  frame->line = rb_sourceline();
1196
1196
 
1197
- # if RUBY_VERSION == 191
1197
+ # if RUBY_VERSION >= 191
1198
1198
  // disabled it causes
1199
1199
  // us to lose valuable frame information...maybe mid comes in wrong sometimes?
1200
1200
  // walk_up_until_right_frame(frame, thread_data, mid, klass, now);
@@ -1260,7 +1260,7 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
1260
1260
  {
1261
1261
  frame = pop_frame(thread_data, now);
1262
1262
 
1263
- # if RUBY_VERSION == 191
1263
+ # if RUBY_VERSION >= 191
1264
1264
  // we need to walk up the stack to find the right one [http://redmine.ruby-lang.org/issues/show/2610] (for now)
1265
1265
  // sometimes frames don't have line and source somehow [like blank]
1266
1266
  // if we hit one there's not much we can do...I guess...
@@ -1273,7 +1273,7 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
1273
1273
  }
1274
1274
  }
1275
1275
 
1276
- #if RUBY_VERSION == 191
1276
+ #if RUBY_VERSION >= 191
1277
1277
 
1278
1278
  static inline void walk_up_until_right_frame(prof_frame_t *frame, thread_data_t* thread_data, ID mid, VALUE klass, prof_measure_t now) {
1279
1279
  // while it doesn't match, pop on up until we have found where we belong...
@@ -1613,6 +1613,11 @@ prof_resume(VALUE self)
1613
1613
  static VALUE
1614
1614
  prof_stop(VALUE self)
1615
1615
  {
1616
+ if (threads_tbl == NULL)
1617
+ {
1618
+ rb_raise(rb_eRuntimeError, "RubyProf.start was not yet called");
1619
+ }
1620
+
1616
1621
  VALUE result = Qnil;
1617
1622
 
1618
1623
  /* close trace file if open */
@@ -1660,7 +1665,7 @@ prof_profile(VALUE self)
1660
1665
  return prof_stop(self);
1661
1666
  }
1662
1667
 
1663
- /* Get arround annoying limitations in RDOC */
1668
+ /* Get around annoying limitations in RDOC */
1664
1669
 
1665
1670
  /* Document-method: measure_process_time
1666
1671
  call-seq:
@@ -1726,8 +1731,10 @@ Returns the total number of garbage collections.*/
1726
1731
  Returns the time spent doing garbage collections in microseconds.*/
1727
1732
 
1728
1733
 
1729
- #if defined(_WIN32)
1730
- __declspec(dllexport)
1734
+ #if RUBY_VERSION == 191 // accomodate for this: http://redmine.ruby-lang.org/issues/show/3748
1735
+ # if defined(_WIN32)
1736
+ __declspec(dllexport)
1737
+ # endif
1731
1738
  #endif
1732
1739
  void
1733
1740
 
@@ -1,4 +1,4 @@
1
- #define RUBY_PROF_VERSION "0.9.1" // for easy parsing from rake files
1
+ #define RUBY_PROF_VERSION "0.9.2" // for easy parsing from rake files
2
2
  #define RUBY_PROF_VERSION_MAJ 0
3
3
  #define RUBY_PROF_VERSION_MIN 9
4
- #define RUBY_PROF_VERSION_MIC 1
4
+ #define RUBY_PROF_VERSION_MIC 2
data/lib/ruby-prof.rb CHANGED
@@ -1,4 +1,5 @@
1
- # require the .so file
1
+ # require the .so file...
2
+
2
3
  me = File.dirname(__FILE__) + '/'
3
4
  begin
4
5
  # fat binaries
@@ -19,9 +20,8 @@ require "ruby-prof/call_tree_printer"
19
20
  require "ruby-prof/call_stack_printer"
20
21
  require "ruby-prof/multi_printer"
21
22
  require "ruby-prof/dot_printer"
22
- require "ruby-prof/symbol_to_proc" # for 1.8's benefit
23
+ require "ruby-prof/symbol_to_proc" # for 1.8's backward compatibility benefit
23
24
  require "ruby-prof/rack"
24
- #require "ruby-prof/result"
25
25
 
26
26
  module RubyProf
27
27
  # See if the user specified the clock mode via
@@ -113,9 +113,11 @@ module RubyProf
113
113
  end
114
114
 
115
115
  def print_classes(thread_id, methods)
116
- methods.group_by{|m| m.klass_name}.each do |cls, methods|
116
+ grouped = {}
117
+ methods.each{|m| grouped[m.klass_name] ||= []; grouped[m.klass_name] << m}
118
+ grouped.each do |cls, methods2|
117
119
  # Filter down to just seen methods
118
- big_methods, small_methods = methods.partition{|m| @seen_methods.include? m}
120
+ big_methods, small_methods = methods2.partition{|m| @seen_methods.include? m}
119
121
 
120
122
  if !big_methods.empty?
121
123
  puts "subgraph cluster_#{cls.object_id} {"
data/test/bad.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'tracer'
2
+ Tracer.on
3
+ a = [1,2,3]
4
+ a.each{|n|
5
+ p n
6
+ }
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'ruby-prof'
5
+
6
+ # test for http://redmine.ruby-lang.org/issues/show/3660 and others that show 1.9.1 not having correct return methods..
7
+
8
+ class SingletonTest < Test::Unit::TestCase
9
+ def test_singleton
10
+ result = RubyProf.profile do
11
+ a = [1,2,3]
12
+ a.each{ |n|
13
+ }
14
+ end
15
+ printer = RubyProf::FlatPrinter.new(result)
16
+ output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : ''
17
+ output = STDOUT
18
+ printer.print(output)
19
+ end
20
+ end
data/test/module_test.rb CHANGED
@@ -31,24 +31,14 @@ class ModuleTest < Test::Unit::TestCase
31
31
  hello
32
32
  end
33
33
 
34
- methods = result.threads.values.first.sort.reverse
34
+ methods = result.threads.values.first
35
35
 
36
36
  # Length should be 5
37
37
  assert_equal(5, methods.length)
38
38
 
39
- method = methods[0]
40
- assert_equal('ModuleTest#test_nested_modules', method.full_name)
41
-
42
- method = methods[1]
43
- assert_equal('Bar#hello', method.full_name)
44
-
45
- method = methods[2]
46
- assert_equal('Kernel#sleep', method.full_name)
47
-
48
- method = methods[3]
49
- assert_equal('<Module::Bar>#hello', method.full_name)
50
-
51
- method = methods[4]
52
- assert_equal('<Module::Foo>#hello', method.full_name)
39
+ # these methods should be in there... (hard to tell order though).
40
+ for name in ['ModuleTest#test_nested_modules','Bar#hello','Kernel#sleep','<Module::Bar>#hello','<Module::Foo>#hello']
41
+ assert methods.map(&:full_name).include? name
42
+ end
53
43
  end
54
44
  end
@@ -58,7 +58,7 @@ class MultiPrinterTest < Test::Unit::TestCase
58
58
  assert graph =~ re
59
59
  display_time = $1.to_f
60
60
  difference = (expected_time-display_time).abs
61
- assert_in_delta expected_time, display_time, 0.001
61
+ assert_in_delta expected_time, display_time, 0.005
62
62
  end
63
63
 
64
64
  private
@@ -2,19 +2,26 @@
2
2
  require 'test/unit'
3
3
  require 'ruby-prof'
4
4
  require 'prime'
5
+ require 'stringio'
6
+ require 'fileutils'
7
+ require 'rubygems'
5
8
 
6
9
  # -- Tests ----
7
10
  class PrintersTest < Test::Unit::TestCase
8
11
 
9
12
  def go
10
- run_primes(10000)
13
+ run_primes(1000)
11
14
  end
12
15
 
13
16
  def setup
14
- RubyProf::measure_mode = RubyProf::WALL_TIME # WALL_TIME so we can use sleep in our test
17
+ RubyProf::measure_mode = RubyProf::WALL_TIME # WALL_TIME so we can use sleep in our test and get same measurements on linux and doze
15
18
  @result = RubyProf.profile do
16
- run_primes(10000)
17
- go
19
+ begin
20
+ run_primes(1000)
21
+ go
22
+ rescue => e
23
+ p e
24
+ end
18
25
  end
19
26
 
20
27
  end
@@ -37,15 +44,25 @@ class PrintersTest < Test::Unit::TestCase
37
44
 
38
45
  printer = RubyProf::CallTreePrinter.new(@result)
39
46
  printer.print(output)
47
+ output_dir = 'examples2'
48
+
49
+ if ENV['SAVE_NEW_PRINTER_EXAMPLES']
50
+ output_dir = 'examples'
51
+ end
52
+ FileUtils.mkdir_p output_dir
40
53
 
41
54
  printer = RubyProf::DotPrinter.new(@result)
42
- File.open("examples/graph.dot", "w") {|f| printer.print(f)}
55
+ File.open("#{output_dir}/graph.dot", "w") {|f| printer.print(f)}
43
56
 
44
57
  printer = RubyProf::CallStackPrinter.new(@result)
45
- File.open("examples/stack.html", "w") {|f| printer.print(f, :application => "primes")}
58
+ File.open("#{output_dir}/stack.html", "w") {|f| printer.print(f, :application => "primes")}
46
59
 
47
60
  printer = RubyProf::MultiPrinter.new(@result)
48
- printer.print(:path => "examples", :profile => "multi", :application => "primes")
61
+ printer.print(:path => "#{output_dir}", :profile => "multi", :application => "primes")
62
+ for file in ['empty.png', 'graph.dot', 'minus.png', 'multi.flat.txt', 'multi.graph.html', 'multi.grind.dat', 'multi.stack.html', 'plus.png', 'stack.html']
63
+ existant_file = output_dir + '/' + file
64
+ assert File.size(existant_file) > 0
65
+ end
49
66
  end
50
67
  end
51
68
 
@@ -73,13 +90,19 @@ class PrintersTest < Test::Unit::TestCase
73
90
  assert_match(/called from/, output)
74
91
 
75
92
  # should combine common parents
76
- if RUBY_VERSION < '1.9'
77
- assert_equal(3, output.scan(/Object#is_prime/).length)
78
- else
79
- # 1.9
80
- assert_equal(2, output.scan(/Object#is_prime/).length)
81
- end
82
- assert_no_match(/\.\/test\/prime.rb/, output) # don't use relative paths
93
+ # lodo remove...
94
+ #if RUBY_VERSION < '1.9'
95
+ #require 'ruby-debug'
96
+ #debugger
97
+ #print output
98
+ assert_equal(3, output.scan(/Object#is_prime/).length) # failing this is prolly a 1.9.2 core bug
99
+ #else
100
+ # # 1.9
101
+ # require 'ruby-debug'
102
+ # debugger
103
+ # assert_equal(2, output.scan(/Object#is_prime/).length)
104
+ #end
105
+ assert_no_match(/\.\/test\/prime.rb/, output) # don't use relative paths
83
106
  end
84
107
 
85
108
  def test_graph_html_string
@@ -74,10 +74,10 @@ class RecursiveTest < Test::Unit::TestCase
74
74
  method = methods[2]
75
75
  assert_equal('Kernel#sleep', method.full_name)
76
76
  assert_equal(2, method.called)
77
- assert_in_delta(2, method.total_time, 0.01)
78
- assert_in_delta(2, method.self_time, 0.01)
79
- assert_in_delta(0, method.wait_time, 0.01)
80
- assert_in_delta(0, method.children_time, 0.01)
77
+ assert_in_delta(2, method.total_time, 0.05)
78
+ assert_in_delta(2, method.self_time, 0.05)
79
+ assert_in_delta(0, method.wait_time, 0.05)
80
+ assert_in_delta(0, method.children_time, 0.05)
81
81
 
82
82
  assert_equal(2, method.call_infos.length)
83
83
  call_info = method.call_infos[0]
@@ -22,6 +22,23 @@ class StartStopTest < Test::Unit::TestCase
22
22
  sleep(2)
23
23
  @result = RubyProf.stop
24
24
  end
25
+
26
+ def test_extra_stop_should_raise
27
+ RubyProf.start
28
+ assert_raise(RuntimeError) do
29
+ RubyProf.start
30
+ end
31
+
32
+ assert_raise(RuntimeError) do
33
+ RubyProf.profile {}
34
+ end
35
+
36
+ RubyProf.stop # ok
37
+ assert_raise(RuntimeError) do
38
+ RubyProf.stop
39
+ end
40
+ end
41
+
25
42
 
26
43
  def test_different_methods
27
44
  method1
@@ -56,10 +73,10 @@ class StartStopTest < Test::Unit::TestCase
56
73
  method = methods[1]
57
74
  assert_equal('StartStopTest#method2', method.full_name)
58
75
  assert_equal(1, method.called)
59
- assert_in_delta(2, method.total_time, 0.01)
76
+ assert_in_delta(2, method.total_time, 0.05)
60
77
  assert_in_delta(0, method.wait_time, 0.01)
61
78
  assert_in_delta(0, method.self_time, 0.01)
62
- assert_in_delta(2, method.children_time, 0.01)
79
+ assert_in_delta(2, method.children_time, 0.05)
63
80
  assert_equal(1, method.call_infos.length)
64
81
 
65
82
  call_info = method.call_infos[0]
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-prof
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 9
9
- - 1
10
- version: 0.9.1
8
+ - 2
9
+ version: 0.9.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-11 00:00:00 -06:00
17
+ date: 2010-08-26 00:00:00 -06:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -113,12 +110,13 @@ files:
113
110
  - lib/ruby-prof/task.rb
114
111
  - lib/ruby-prof/test.rb
115
112
  - lib/ruby-prof.rb
116
- - lib/ruby_prof.so
117
113
  - lib/unprof.rb
118
114
  - rails/environment/profile.rb
119
115
  - rails/example/example_test.rb
120
116
  - rails/profile_test_helper.rb
121
117
  - test/aggregate_test.rb
118
+ - test/bad.rb
119
+ - test/basic2_test.rb
122
120
  - test/basic_test.rb
123
121
  - test/current_failures_windows
124
122
  - test/do_nothing.rb
@@ -160,7 +158,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
158
  requirements:
161
159
  - - ">="
162
160
  - !ruby/object:Gem::Version
163
- hash: 63
164
161
  segments:
165
162
  - 1
166
163
  - 8
@@ -171,7 +168,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
168
  requirements:
172
169
  - - ">="
173
170
  - !ruby/object:Gem::Version
174
- hash: 3
175
171
  segments:
176
172
  - 0
177
173
  version: "0"
data/lib/ruby_prof.so DELETED
Binary file