Author: Antonio Cuni <anto.c...@gmail.com> Branch: gc-hooks Changeset: r94183:5fbf8b32c70c Date: 2018-03-29 10:45 +0200 http://bitbucket.org/pypy/pypy/changeset/5fbf8b32c70c/
Log: add a hook for gc-collect-done diff --git a/rpython/memory/gc/hook.py b/rpython/memory/gc/hook.py --- a/rpython/memory/gc/hook.py +++ b/rpython/memory/gc/hook.py @@ -4,3 +4,10 @@ """ Called after a minor collection """ + + def on_gc_collect(self, count, arenas_count_before, arenas_count_after, + arenas_bytes, rawmalloc_bytes_before, + rawmalloc_bytes_after): + """ + Called after a major collection is fully done + """ 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 @@ -2422,6 +2422,13 @@ self.stat_rawmalloced_total_size, " => ", self.rawmalloced_total_size) debug_stop("gc-collect-done") + self.hooks.on_gc_collect( + count=self.num_major_collects, + arenas_count_before=self.stat_ac_arenas_count, + arenas_count_after=self.ac.arenas_count, + arenas_bytes=self.ac.total_memory_used, + rawmalloc_bytes_before=self.stat_rawmalloced_total_size, + rawmalloc_bytes_after=self.rawmalloced_total_size) # # Set the threshold for the next major collection to be when we # have allocated 'major_collection_threshold' times more than diff --git a/rpython/memory/gc/test/test_hook.py b/rpython/memory/gc/test/test_hook.py --- a/rpython/memory/gc/test/test_hook.py +++ b/rpython/memory/gc/test/test_hook.py @@ -9,10 +9,14 @@ def reset(self): self.minors = [] + self.collects = [] def on_gc_minor(self, **kwds): self.minors.append(kwds) + def on_gc_collect(self, **kwds): + self.collects.append(kwds) + class TestIncMiniMarkHooks(BaseDirectGCTest): from rpython.memory.gc.incminimark import IncrementalMiniMarkGC as GCClass @@ -20,6 +24,11 @@ def get_extra_gc_params(self): return {'hooks': MyGcHooks()} + def setup_method(self, m): + BaseDirectGCTest.setup_method(self, m) + size = llmemory.sizeof(S) + self.gc.gcheaderbuilder.size_gc_header + self.size_of_S = llmemory.raw_malloc_usage(size) + def test_on_gc_minor(self): self.malloc(S) self.gc._minor_collection() @@ -31,9 +40,31 @@ # these objects survive, so the total_memory_used is > 0 self.stackroots.append(self.malloc(S)) self.stackroots.append(self.malloc(S)) - size = llmemory.sizeof(S) + self.gc.gcheaderbuilder.size_gc_header - rawsize = llmemory.raw_malloc_usage(size) self.gc._minor_collection() assert self.gc.hooks.minors == [ - {'total_memory_used': rawsize*2, 'pinned_objects': 0} + {'total_memory_used': self.size_of_S*2, 'pinned_objects': 0} ] + + def test_on_gc_collect(self): + self.malloc(S) + self.gc.collect() + assert self.gc.hooks.collects == [ + {'count': 1, + 'arenas_count_before': 0, + 'arenas_count_after': 0, + 'arenas_bytes': 0, + 'rawmalloc_bytes_after': 0, + 'rawmalloc_bytes_before': 0} + ] + self.gc.hooks.reset() + # + self.stackroots.append(self.malloc(S)) + self.gc.collect() + assert self.gc.hooks.collects == [ + {'count': 2, + 'arenas_count_before': 1, + 'arenas_count_after': 1, + 'arenas_bytes': self.size_of_S, + 'rawmalloc_bytes_after': 0, + 'rawmalloc_bytes_before': 0} + ] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit