[pypy-commit] pypy cpyext-gc-cycle: Improved stats

stevie_92 pypy.commits at gmail.com
Thu Oct 24 15:23:14 EDT 2019


Author: Stefan Beyer <home at sbeyer.at>
Branch: cpyext-gc-cycle
Changeset: r97852:4f393184be0e
Date: 2019-10-23 19:53 +0200
http://bitbucket.org/pypy/pypy/changeset/4f393184be0e/

Log:	Improved stats

diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -161,7 +161,7 @@
                     use_bytecode_counter=True)
             else:
                 module = space.builtin_modules['gc']
-                attribute = space.newtext('cpyext_durations')
+                attribute = space.newtext('cpyext_stat')
                 space.setattr(module, attribute, space.newlist([]))
 
                 pyobj_dealloc_action = PyObjDeallocAction(space)
@@ -321,26 +321,33 @@
                                              finalize, from_ref, cts)
     from pypy.module.cpyext.api import generic_cpy_call
 
-
+    #debug_print("rrc perform")
     if rawrefcount.check_state():
         start = time.time()
+        dead_calls = 0
+        cyclic_isolate_calls = 0
+        cyclic_garbage_calls = 0
+        garbage_calls = 0
 
         while True:
             py_obj = rawrefcount.next_dead(PyObject)
             if not py_obj:
                 break
+            dead_calls += 1
             decref(space, py_obj)
 
         while True:
             py_obj = rawrefcount.next_cyclic_isolate(PyObject)
             if not py_obj:
                 break
+            cyclic_isolate_calls += 1
             finalize(space, py_obj)
 
         while True:
             py_obj = rawrefcount.cyclic_garbage_head(PyObject)
             if not py_obj:
                 break
+            cyclic_garbage_calls += 1
             pyobj = rffi.cast(PyObject, py_obj)
             adr_int = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(pyobj))
             pto = pyobj.c_ob_type
@@ -357,27 +364,38 @@
             if adr_int == llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(head)):
                 rawrefcount.cyclic_garbage_remove()
 
-        rawrefcount.begin_garbage()
-        w_list = space.newlist([])
-        while True:
-            w_obj = rawrefcount.next_garbage_pypy(W_Root)
-            if not py_obj:
-                break
-            w_list.append(w_obj)
-        while True:
-            w_pyobj = rawrefcount.next_garbage_pyobj(PyObject)
-            if not w_pyobj:
-                break
-            w_obj = from_ref(space, w_pyobj)
-            w_list.append(w_obj)
-        space.setattr(space.builtin_modules['gc'], space.newtext('garbage'),
-                      w_list)
-        rawrefcount.end_garbage()
+        # TODO: instead of building up this list every time, only do it in case something changed
+        if False: # TODO add check, if something changed
+            rawrefcount.begin_garbage()
+            w_list = space.newlist([]) # append to existing list???
+            while True:
+                w_obj = rawrefcount.next_garbage_pypy(W_Root)
+                if not w_obj:
+                    break
+                garbage_calls += 1
+                debug_print("append garbage pypy", w_obj)
+                w_list.append(w_obj)
+            while True:
+                w_pyobj = rawrefcount.next_garbage_pyobj(PyObject)
+                if not w_pyobj:
+                    break
+                garbage_calls += 1
+                w_obj = from_ref(space, w_pyobj)
+                debug_print("append garbage pyobj", w_obj)
+                w_list.append(w_obj)
+            space.setattr(space.builtin_modules['gc'],
+                          space.newtext('garbage'), w_list)
+            rawrefcount.end_garbage()
 
         duration = time.time() - start
+        list = space.newlist([space.newfloat(duration),
+                              space.newint(dead_calls),
+                              space.newint(cyclic_isolate_calls),
+                              space.newint(cyclic_garbage_calls),
+                              space.newint(garbage_calls)])
         module = space.builtin_modules['gc']
-        durations = space.getattr(module, space.newtext('cpyext_durations'))
-        durations.append(space.newfloat(duration))
+        durations = space.getattr(module, space.newtext('cpyext_stat'))
+        durations.append(list)
 
 class PyObjDeallocAction(executioncontext.AsyncAction):
     """An action that invokes _Py_Dealloc() on the dying PyObjects.
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
@@ -2026,7 +2026,7 @@
             #
             # Check that the flags are correct: we must not have
             # GCFLAG_TRACK_YOUNG_PTRS so far.
-            # TODO: fix
+            # TODO: fix (with rrc incmark, seems to work with rrc mark)
             #ll_assert(self.header(obj).tid & GCFLAG_TRACK_YOUNG_PTRS == 0,
             #          "old_objects_pointing_to_young contains obj with "
             #          "GCFLAG_TRACK_YOUNG_PTRS")
@@ -2411,7 +2411,13 @@
                 if self.rrc_enabled:
                     debug_print("starting rrc state:", self.rrc_gc.state)
                     debug_print("starting marking_state:", self.rrc_gc.marking_state)
+                    start_rrc = time.time()
+
                     rrc_finished = self.rrc_gc.major_collection_trace_step()
+
+                    duration_rrc = time.time() - start_rrc
+                    debug_print("rrc duration:", duration_rrc)
+
                     debug_print("ending rrc state:", self.rrc_gc.state)
                     debug_print("ending marking_state:", self.rrc_gc.marking_state)
                 else:
@@ -3146,6 +3152,7 @@
 
     def rawrefcount_check_state(self):
         ll_assert(self.rrc_enabled, "rawrefcount.init not called")
+        #debug_print("check state", self.rrc_gc.state)
         return self.rrc_gc.state == RawRefCountBaseGC.STATE_DEFAULT
 
     def rawrefcount_next_dead(self):
diff --git a/rpython/memory/gc/rrc/base.py b/rpython/memory/gc/rrc/base.py
--- a/rpython/memory/gc/rrc/base.py
+++ b/rpython/memory/gc/rrc/base.py
@@ -120,12 +120,12 @@
         self.tuple_maybe_untrack = tuple_maybe_untrack
         self.state = self.STATE_DEFAULT
         self.marking_state = 0
-        self.cycle_enabled = True
         inc_limit = env.read_uint_from_env('PYPY_RRC_GC_INCREMENT_STEP')
         if inc_limit > 0:
             self.inc_limit = inc_limit
         else:
             self.inc_limit = 1000
+        self.cycle_enabled = True
 
     def create_link_pypy(self, gcobj, pyobject):
         obj = llmemory.cast_ptr_to_adr(gcobj)
@@ -227,9 +227,9 @@
             # the first (c_gc_next) and last (c_gc_prev) pyobject in the list
             # of live objects that are garbage, so just fix the references
             list = self.pyobj_garbage_list
-            gchdr = list.c_gc_next
-            if list.c_gc_prev == gchdr:
-                list.c_gc_next = list # reached end of list, reset it
+            gchdr = list.c_gc_next # get next object in list
+            if list.c_gc_prev == gchdr: # if at end of list
+                list.c_gc_next = list # reset the list (now it is empty)
             else:
                 list.c_gc_next = gchdr.c_gc_next # move pointer foward
             return llmemory.cast_ptr_to_adr(self.gc_as_pyobj(gchdr))


More information about the pypy-commit mailing list