Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
make trace object creation lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Mar 5, 2012
1 parent 70610a8 commit 2e2fa92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 14 additions & 2 deletions client/tracebin/recorder.py
@@ -1,3 +1,4 @@
import ctypes
import io
import inspect
import mmap
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions client/tracebin/traces.py
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 2e2fa92

Please sign in to comment.