[pypy-svn] r49733 - pypy/branch/pypy-gc-traceopt/rpython/memory/gc
arigo at codespeak.net
arigo at codespeak.net
Thu Dec 13 18:28:20 CET 2007
Author: arigo
Date: Thu Dec 13 18:28:19 2007
New Revision: 49733
Modified:
pypy/branch/pypy-gc-traceopt/rpython/memory/gc/traceopt.py
Log:
Count the number of traces with almost no overhead.
Must be enabled by setting LOG_COUNT_TRACES to a file name.
Modified: pypy/branch/pypy-gc-traceopt/rpython/memory/gc/traceopt.py
==============================================================================
--- pypy/branch/pypy-gc-traceopt/rpython/memory/gc/traceopt.py (original)
+++ pypy/branch/pypy-gc-traceopt/rpython/memory/gc/traceopt.py Thu Dec 13 18:28:19 2007
@@ -4,6 +4,10 @@
from pypy.rpython.lltypesystem.lloperation import llop
+#LOG_COUNT_TRACES = "traces.log"
+LOG_COUNT_TRACES = None
+
+
class TraceOptGCBase(object):
_alloc_flavor_ = "raw"
@@ -15,9 +19,13 @@
while i < count:
self.traceopt_index[i] = chr(0)
i += 1
+ if LOG_COUNT_TRACES:
+ self.logt = setup_log_count_traces(count)
def trace(self, obj, callback, arg):
typeid = self.get_type_id(obj)
+ if LOG_COUNT_TRACES:
+ log_count_trace(self.logt, typeid)
# first see if we have an optimized tracer for this typeid
# (this becomes a single switch)
shapeindex = ord(self.traceopt_index[typeid])
@@ -154,3 +162,42 @@
common_shape_checkers, common_shape_tracers = get_common_shape_fns()
list_common_shape_checkers = common_shape_checkers.items()
unroll_common_shape_tracers = unrolling_iterable(common_shape_tracers.items())
+
+# ____________________________________________________________
+
+if LOG_COUNT_TRACES:
+ import os
+ from pypy.rpython.lltypesystem import rffi
+ from pypy.rlib import rmmap
+
+ def setup_log_count_traces(max):
+ # XXX no error checks
+ fd = os.open(LOG_COUNT_TRACES, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0666)
+ length = max * rffi.sizeof(rffi.ULONGLONG)
+ os.write(fd, '\x00' * length)
+ os.lseek(fd, 0, 0)
+ return rmmap.mmap(fd, length)
+
+ def log_count_trace(map, typeid):
+ p = rffi.cast(rffi.ULONGLONGP, map.data)
+ p[typeid] += 1
+
+# display the content of a log file when run as __main__
+if __name__ == '__main__':
+ import sys, struct
+ if len(sys.argv) == 1:
+ filename = LOG_COUNT_TRACES
+ else:
+ filename = sys.argv[1]
+ data = open(filename, 'rb').read()
+ results = []
+ sz = struct.calcsize("Q")
+ for i in range(0, len(data), sz):
+ count, = struct.unpack("Q", data[i:i+sz])
+ results.append((count, i))
+ results.sort()
+ results.reverse()
+ N = 20
+ print '%d top results: (typeid, number of traces)' % (N,)
+ for count, i in results[:N]:
+ print '%5d %15d' % (i, count)
More information about the Pypy-commit
mailing list