Permalink
Browse files

fix REE GC stats for the uppermost method, I think at least

  • Loading branch information...
rdp committed May 10, 2011
1 parent 386acd3 commit 18f7bbc30e521db2243a0fcbf395d6a02072cd1e
Showing with 14 additions and 24 deletions.
  1. +7 −5 ext/ruby_prof/ruby_prof.c
  2. +7 −19 test/measurement_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
@@ -72,9 +74,8 @@ def test_allocations
def memory_test_helper
result = RubyProf.profile {Array.new}
total = result.threads.values.first.inject(0) { |sum, m| sum + m.total_time }
-
- assert(total > 0, 'Should measure more than zero kilobytes of memory usage')
- assert_not_equal(0, total % 1, 'Should not truncate fractional kilobyte measurements')
+ assert(total < 1_000_000, 'Total should not have subtract overflow error')
+ total
end
if RubyProf::MEMORY
@@ -90,23 +91,10 @@ def test_memory
u = RubyProf.measure_memory
assert(u >= t, [t, u].inspect)
RubyProf::measure_mode = RubyProf::MEMORY
- memory_test_helper
- end
- end
-
- def memory_test_helper
- t = RubyProf.measure_memory
- assert_kind_of Integer, t
-
- 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 ' + total.inspect)
+ assert_not_equal(0, total % 1, 'Should not truncate fractional kilobyte measurements')
+ end
end
if RubyProf::GC_RUNS

0 comments on commit 18f7bbc

Please sign in to comment.