Author: Antonio Cuni <[email protected]>
Branch: gc-hooks
Changeset: r94299:98f9de10e075
Date: 2018-04-10 00:10 +0200
http://bitbucket.org/pypy/pypy/changeset/98f9de10e075/
Log: WIP: compute the duration of gc-minor and gc-collect-step, and pass
it to the GC hooks; for now we simply pass the difference between
two read_timestamp(), but ideally we need a way to get a reliable
way to convert them to nanoseconds or so
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
@@ -21,12 +21,12 @@
def is_gc_collect_enabled(self):
return False
- def on_gc_minor(self, total_memory_used, pinned_objects):
+ def on_gc_minor(self, duration, total_memory_used, pinned_objects):
"""
Called after a minor collection
"""
- def on_gc_collect_step(self, oldstate, newstate):
+ def on_gc_collect_step(self, duration, oldstate, newstate):
"""
Called after each individual step of a major collection, in case the
GC is
incremental.
@@ -48,14 +48,14 @@
# overridden
@rgc.no_collect
- def fire_gc_minor(self, total_memory_used, pinned_objects):
+ def fire_gc_minor(self, duration, total_memory_used, pinned_objects):
if self.is_gc_minor_enabled():
- self.on_gc_minor(total_memory_used, pinned_objects)
+ self.on_gc_minor(duration, total_memory_used, pinned_objects)
@rgc.no_collect
- def fire_gc_collect_step(self, oldstate, newstate):
+ def fire_gc_collect_step(self, duration, oldstate, newstate):
if self.is_gc_collect_step_enabled():
- self.on_gc_collect_step(oldstate, newstate)
+ self.on_gc_collect_step(duration, oldstate, newstate)
@rgc.no_collect
def fire_gc_collect(self, count, arenas_count_before, arenas_count_after,
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
@@ -73,6 +73,7 @@
from rpython.rlib.debug import ll_assert, debug_print, debug_start, debug_stop
from rpython.rlib.objectmodel import specialize
from rpython.rlib import rgc
+from rpython.rlib.rtimer import read_timestamp
from rpython.memory.gc.minimarkpage import out_of_memory
#
@@ -1641,6 +1642,7 @@
"""Perform a minor collection: find the objects from the nursery
that remain alive and move them out."""
#
+ start = read_timestamp()
debug_start("gc-minor")
#
# All nursery barriers are invalid from this point on. They
@@ -1838,8 +1840,11 @@
self.root_walker.finished_minor_collection()
#
debug_stop("gc-minor")
- self.hooks.fire_gc_minor(total_memory_used=total_memory_used,
- pinned_objects=self.pinned_objects_in_nursery)
+ duration = read_timestamp() - start
+ self.hooks.fire_gc_minor(
+ duration=duration,
+ total_memory_used=total_memory_used,
+ pinned_objects=self.pinned_objects_in_nursery)
def _reset_flag_old_objects_pointing_to_pinned(self, obj, ignore):
ll_assert(self.header(obj).tid & GCFLAG_PINNED_OBJECT_PARENT_KNOWN !=
0,
@@ -2242,6 +2247,7 @@
# Note - minor collections seem fast enough so that one
# is done before every major collection step
def major_collection_step(self, reserving_size=0):
+ start = read_timestamp()
debug_start("gc-collect-step")
oldstate = self.gc_state
debug_print("starting gc state: ", GC_STATES[self.gc_state])
@@ -2481,8 +2487,11 @@
debug_print("stopping, now in gc state: ", GC_STATES[self.gc_state])
debug_stop("gc-collect-step")
- self.hooks.fire_gc_collect_step(oldstate=oldstate,
- newstate=self.gc_state)
+ duration = read_timestamp() - start
+ self.hooks.fire_gc_collect_step(
+ duration=duration,
+ oldstate=oldstate,
+ newstate=self.gc_state)
def _sweep_old_objects_pointing_to_pinned(self, obj, new_list):
if self.header(obj).tid & GCFLAG_VISITED:
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
@@ -25,13 +25,16 @@
self.minors = []
self.steps = []
self.collects = []
+ self.durations = []
- def on_gc_minor(self, total_memory_used, pinned_objects):
+ def on_gc_minor(self, duration, total_memory_used, pinned_objects):
+ self.durations.append(duration)
self.minors.append({
'total_memory_used': total_memory_used,
'pinned_objects': pinned_objects})
- def on_gc_collect_step(self, oldstate, newstate):
+ def on_gc_collect_step(self, duration, oldstate, newstate):
+ self.durations.append(duration)
self.steps.append({
'oldstate': oldstate,
'newstate': newstate})
@@ -66,6 +69,7 @@
assert self.gc.hooks.minors == [
{'total_memory_used': 0, 'pinned_objects': 0}
]
+ assert self.gc.hooks.durations[0] > 0
self.gc.hooks.reset()
#
# these objects survive, so the total_memory_used is > 0
@@ -96,6 +100,9 @@
'rawmalloc_bytes_after': 0,
'rawmalloc_bytes_before': 0}
]
+ assert len(self.gc.hooks.durations) == 4 # 4 steps
+ for d in self.gc.hooks.durations:
+ assert d > 0
self.gc.hooks.reset()
#
self.stackroots.append(self.malloc(S))
diff --git a/rpython/memory/test/test_transformed_gc.py
b/rpython/memory/test/test_transformed_gc.py
--- a/rpython/memory/test/test_transformed_gc.py
+++ b/rpython/memory/test/test_transformed_gc.py
@@ -1421,10 +1421,10 @@
def is_gc_collect_enabled(self):
return True
- def on_gc_minor(self, total_memory_used, pinned_objects):
+ def on_gc_minor(self, duration, total_memory_used, pinned_objects):
self.stats.minors += 1
- def on_gc_collect_step(self, oldstate, newstate):
+ def on_gc_collect_step(self, duration, oldstate, newstate):
self.stats.steps += 1
def on_gc_collect(self, count, arenas_count_before, arenas_count_after,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit