Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: expose-gc-time Changeset: r95356:6759b7682f7f Date: 2018-11-22 10:59 +0100 http://bitbucket.org/pypy/pypy/changeset/6759b7682f7f/
Log: expose the time that the GC takes as a stat diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py --- a/rpython/memory/gc/incminimark.py +++ b/rpython/memory/gc/incminimark.py @@ -62,6 +62,7 @@ # XXX old_objects_pointing_to_young (IRC 2014-10-22, fijal and gregor_w) import sys import os +import time from rpython.rtyper.lltypesystem import lltype, llmemory, llarena, llgroup from rpython.rtyper.lltypesystem.lloperation import llop from rpython.rtyper.lltypesystem.llmemory import raw_malloc_usage @@ -192,6 +193,17 @@ # ____________________________________________________________ +def count_gc_time(meth): + def timing_meth(self, *args): + t1 = time.time() + res = meth(self, *args) + t2 = time.time() + self.total_gc_time += t2 - t1 + return res + timing_meth.func_name = meth.func_name + "_timing" + return timing_meth + + class IncrementalMiniMarkGC(MovingGCBase): _alloc_flavor_ = "raw" inline_simple_malloc = True @@ -374,6 +386,7 @@ self.raw_malloc_might_sweep = self.AddressStack() self.rawmalloced_total_size = r_uint(0) self.rawmalloced_peak_size = r_uint(0) + self.total_gc_time = 0.0 self.gc_state = STATE_SCANNING # @@ -1640,6 +1653,7 @@ # ---------- # Nursery collection + @count_gc_time def _minor_collection(self): """Perform a minor collection: find the objects from the nursery that remain alive and move them out.""" @@ -2248,6 +2262,7 @@ # Note - minor collections seem fast enough so that one # is done before every major collection step + @count_gc_time def major_collection_step(self, reserving_size=0): start = read_timestamp() debug_start("gc-collect-step") @@ -3000,6 +3015,8 @@ self.ac.total_memory_used)) elif stats_no == rgc.NURSERY_SIZE: return intmask(self.nursery_size) + elif stats_no == rgc.TOTAL_GC_TIME: + return int(self.total_gc_time * 1000) return 0 @@ -3093,6 +3110,7 @@ return llmemory.NULL + @count_gc_time def rrc_invoke_callback(self): if self.rrc_enabled and self.rrc_dealloc_pending.non_empty(): self.rrc_dealloc_trigger_callback() diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py --- a/rpython/rlib/rgc.py +++ b/rpython/rlib/rgc.py @@ -704,7 +704,7 @@ (TOTAL_MEMORY, TOTAL_ALLOCATED_MEMORY, TOTAL_MEMORY_PRESSURE, PEAK_MEMORY, PEAK_ALLOCATED_MEMORY, TOTAL_ARENA_MEMORY, TOTAL_RAWMALLOCED_MEMORY, PEAK_ARENA_MEMORY, PEAK_RAWMALLOCED_MEMORY, - NURSERY_SIZE) = range(10) + NURSERY_SIZE, TOTAL_GC_TIME) = range(11) @not_rpython def get_stats(stat_no): diff --git a/rpython/translator/c/test/test_newgc.py b/rpython/translator/c/test/test_newgc.py --- a/rpython/translator/c/test/test_newgc.py +++ b/rpython/translator/c/test/test_newgc.py @@ -1812,7 +1812,20 @@ res = self.run("ignore_finalizer") assert res == 1 # translated: x1 is removed from the list + def define_total_gc_time(cls): + def f(): + l = [] + for i in range(1000000): + l.append(str(i)) + l = [] + for i in range(10): + rgc.collect() + return rgc.get_stats(rgc.TOTAL_GC_TIME) + return f + def test_total_gc_time(self): + res = self.run("total_gc_time") + assert res > 0 # should take a few microseconds # ____________________________________________________________________ class TaggedPointersTest(object): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit