From 2e2fa927a958fc7854924dd2a8ea258bc8408e11 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 5 Mar 2012 10:24:42 -0500 Subject: [PATCH] make trace object creation lazy --- client/tracebin/recorder.py | 16 ++++++++++++++-- client/tracebin/traces.py | 7 ++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/client/tracebin/recorder.py b/client/tracebin/recorder.py index 8191e6a..f3e6095 100644 --- a/client/tracebin/recorder.py +++ b/client/tracebin/recorder.py @@ -1,3 +1,4 @@ +import ctypes import io import inspect import mmap @@ -30,7 +31,8 @@ def record(**kwargs): class Recorder(object): def __init__(self): self.log = Logger() - self.traces = [] + self._traces = [] + self._pending_traces = [] self.aborts = [] self.calls = None self.options = { @@ -88,6 +90,14 @@ def disable(self, profile): self._find_calls() del self._end_time + @property + def traces(self): + for data in self._pending_traces: + cls, args = data[0], data[1:] + self._traces.append(cls(*args)) + del self._pending_traces[:] + return self._traces + def _new_mmap(self): self._current_profile_mmap = mmap.mmap(-1, 4 * 1024 * 1024) self._profile_mmaps.append(self._current_profile_mmap) @@ -145,7 +155,9 @@ def on_compile(self, jitdriver_name, kind, greenkey, ops, asm_ptr, asm_len): return if jitdriver_name == "pypyjit": - self.traces.append(PythonTrace(greenkey, ops, asm_ptr, asm_len)) + self._pending_traces.append( + (PythonTrace, greenkey, ops, ctypes.string_at(asm_ptr, asm_len)) + ) else: self.log.warning("[compile] Unhandled jitdriver: %s" % jitdriver_name) diff --git a/client/tracebin/traces.py b/client/tracebin/traces.py index 2f9d7d9..91f6122 100644 --- a/client/tracebin/traces.py +++ b/client/tracebin/traces.py @@ -4,8 +4,9 @@ class BaseTrace(object): - def __init__(self, ops): + def __init__(self, ops, asm): super(BaseTrace, self).__init__() + self.asm = asm self.sections = [ TraceSection(label, self.split_section(ops)) for label, ops in self.split_trace(ops) @@ -24,8 +25,8 @@ def split_trace(cls, ops): return sections class PythonTrace(BaseTrace): - def __init__(self, greenkey, ops, asm_start, asm_len): - super(PythonTrace, self).__init__(ops) + def __init__(self, greenkey, ops, asm): + super(PythonTrace, self).__init__(ops, asm) self.root_file = greenkey[0].co_filename self.root_function = greenkey[0].co_name