Project

General

Profile

Feature #10917 ยป gc-total-time.patch

jasonrclark (Jason Clark), 02/27/2015 11:14 PM

View differences:

gc.c
481 481

  
482 482
    rb_event_flag_t hook_events;
483 483
    size_t total_allocated_objects;
484
    double gc_total_time;
484 485

  
485 486
    rb_heap_t eden_heap;
486 487
    rb_heap_t tomb_heap; /* heap for zombies and ghosts */
......
6399 6400
    gc_stat_sym_total_freed_pages,
6400 6401
    gc_stat_sym_total_allocated_objects,
6401 6402
    gc_stat_sym_total_freed_objects,
6403
    gc_stat_sym_total_time,
6402 6404
    gc_stat_sym_malloc_increase_bytes,
6403 6405
    gc_stat_sym_malloc_increase_bytes_limit,
6404 6406
#if USE_RGENGC
......
6476 6478
	S(total_freed_pages);
6477 6479
	S(total_allocated_objects);
6478 6480
	S(total_freed_objects);
6481
	S(total_time);
6479 6482
	S(malloc_increase_bytes);
6480 6483
	S(malloc_increase_bytes_limit);
6481 6484
#if USE_RGENGC
......
6650 6653
    SET(total_freed_pages, objspace->profile.total_freed_pages);
6651 6654
    SET(total_allocated_objects, objspace->total_allocated_objects);
6652 6655
    SET(total_freed_objects, objspace->profile.total_freed_objects);
6656
    SET(total_time, NUM2SIZET(DBL2NUM(objspace->gc_total_time * 1000000)));
6653 6657
    SET(malloc_increase_bytes, malloc_increase);
6654 6658
    SET(malloc_increase_bytes_limit, malloc_limit);
6655 6659
#if USE_RGENGC
......
6725 6729
 *          :total_freed_pages=>0,
6726 6730
 *          :total_allocated_objects=>7796,
6727 6731
 *          :total_freed_objects=>83,
6732
 *          :total_time=>1978,
6728 6733
 *          :malloc_increase_bytes=>2389312,
6729 6734
 *          :malloc_increase_bytes_limit=>16777216,
6730 6735
 *          :minor_gc_count=>0,
......
8103 8108
{
8104 8109
    if (gc_prof_enabled(objspace)) {
8105 8110
	gc_profile_record *record = gc_prof_record(objspace);
8106
	record->gc_time = elapsed_time_from(record->gc_invoke_time);
8111
	double elapsed_time = elapsed_time_from(record->gc_invoke_time);
8112
	objspace->gc_total_time += elapsed_time;
8113
	record->gc_time = elapsed_time;
8107 8114
	record->gc_invoke_time -= objspace->profile.invoke_time;
8108 8115
    }
8109 8116
}
......
8164 8171
	if (record->gc_time > 0) {
8165 8172
	    sweep_time = elapsed_time_from(objspace->profile.gc_sweep_start_time);
8166 8173
	    /* need to accumulate GC time for lazy sweep after gc() */
8174
	    objspace->gc_total_time += sweep_time;
8167 8175
	    record->gc_time += sweep_time;
8168 8176
	}
8169 8177
	else if (GC_PROFILE_MORE_DETAIL) {
test/ruby/test_gc.rb
277 277
    GC::Profiler.disable
278 278
  end
279 279

  
280
  def test_gc_stat_total_time
281
    GC::Profiler.enable
282
    GC::Profiler.clear
283

  
284
    GC.start
285
    assert_operator(GC.stat[:total_time], :>=, 0)
286
  ensure
287
    GC::Profiler.disable
288
  end
289

  
290
  def test_gc_stat_total_time_when_disabled
291
    GC::Profiler.disable
292
    original = GC.stat[:total_time]
293

  
294
    GC.start
295
    assert_operator(GC.stat[:total_time], :==, original)
296
  ensure
297
    GC::Profiler.disable
298
  end
299

  
300
  def test_gc_stat_total_time_is_monotonic
301
    GC::Profiler.enable
302
    GC::Profiler.clear
303

  
304
    GC.start
305
    GC::Profiler.clear
306

  
307
    assert_operator(GC.stat[:total_time], :>=, 0)
308
  ensure
309
    GC::Profiler.disable
310
  end
311

  
280 312
  def test_finalizing_main_thread
281 313
    assert_in_out_err(%w[--disable-gems], <<-EOS, ["\"finalize\""], [], "[ruby-dev:46647]")
282 314
      ObjectSpace.define_finalizer(Thread.main) { p 'finalize' }