Permalink
Browse files

Merge branch 'master' of https://github.com/rdp/ruby-prof

  • Loading branch information...
2 parents d1e431f + 8858a6d commit 47fe7850ee72480698cbc97a0344a5ca74f667a8 @rdp rdp committed May 10, 2011
Showing with 23 additions and 11 deletions.
  1. +7 −5 ext/ruby_prof/ruby_prof.c
  2. +14 −4 test/measurement_test.rb
  3. +1 −1 test/stack_printer_test.rb
  4. +1 −1 test/thread_test.rb
View
@@ -1078,10 +1078,8 @@ pop_frames(st_data_t key, st_data_t value, st_data_t now_arg)
}
static void
-prof_pop_threads()
+prof_pop_threads(prof_measure_t now)
{
- /* Get current measurement */
- prof_measure_t now = get_measurement();
st_foreach(threads_tbl, pop_frames, (st_data_t) &now);
}
@@ -1613,6 +1611,10 @@ prof_resume(VALUE self)
static VALUE
prof_stop(VALUE self)
{
+ /* get 'now' before prof emove hook because it calls GC.disable_stats
+ which makes the call within prof_pop_threads of now return 0, which is wrong
+ */
+ prof_measure_t now = get_measurement();
if (threads_tbl == NULL)
{
rb_raise(rb_eRuntimeError, "RubyProf.start was not yet called");
@@ -1626,10 +1628,10 @@ prof_stop(VALUE self)
fclose(trace_file);
trace_file = NULL;
}
-
+
prof_remove_hook();
- prof_pop_threads();
+ prof_pop_threads(now);
/* Create the result */
result = prof_result_new();
View
@@ -4,10 +4,12 @@
class MeasurementTest < Test::Unit::TestCase
def setup
+ # also done in C these days...
GC.enable_stats if GC.respond_to?(:enable_stats)
end
def teardown
+ # also done in C for normal runs...
GC.disable_stats if GC.respond_to?(:disable_stats)
end
@@ -69,6 +71,13 @@ def test_allocations
end
end
+ def memory_test_helper
+ result = RubyProf.profile {Array.new}
+ total = result.threads.values.first.inject(0) { |sum, m| sum + m.total_time }
+ assert(total < 1_000_000, 'Total should not have subtract overflow error')
+ total
+ end
+
if RubyProf::MEMORY
def test_memory_mode
RubyProf::measure_mode = RubyProf::MEMORY
@@ -81,11 +90,8 @@ def test_memory
u = RubyProf.measure_memory
assert(u >= t, [t, u].inspect)
-
RubyProf::measure_mode = RubyProf::MEMORY
- result = RubyProf.profile {Array.new}
- total = result.threads.values.first.inject(0) { |sum, m| sum + m.total_time }
-
+ total = memory_test_helper
assert(total > 0, 'Should measure more than zero kilobytes of memory usage')
assert_not_equal(0, total % 1, 'Should not truncate fractional kilobyte measurements')
end
@@ -105,6 +111,8 @@ def test_gc_runs
u = RubyProf.measure_gc_runs
assert u > t, [t, u].inspect
+ RubyProf::measure_mode = RubyProf::GC_RUNS
+ memory_test_helper
end
end
@@ -117,6 +125,8 @@ def test_gc_time
u = RubyProf.measure_gc_time
assert u > t, [t, u].inspect
+ RubyProf::measure_mode = RubyProf::GC_TIME
+ memory_test_helper
end
end
end
@@ -46,7 +46,7 @@ def test_stack_can_be_printed
assert file_contents =~ /Thread: (\d+) \(100\.00% ~ ([.0-9]+)\)/
actual_time = $2.to_f
difference = (expected_time-actual_time).abs
- assert difference < 0.01 # less than 1 ms
+ assert_in_delta(expected_time, actual_time, 0.01)
end
def test_method_elimination
View
@@ -155,7 +155,7 @@ def test_thread_back_and_forth
a.join
b.join
end
- assert result.threads.values.flatten.sort[-1].total_time < 10 # 10s
+ assert result.threads.values.flatten.sort[-1].total_time < 10 # 10s. Amazingly, this can fail in OS X at times. Amazing.
end
def test_thread

0 comments on commit 47fe785

Please sign in to comment.