[pypy-svn] r70521 - in pypy/branch/jit-profiling/pypy/interpreter: . test
fijal at codespeak.net
fijal at codespeak.net
Tue Jan 12 11:42:47 CET 2010
Author: fijal
Date: Tue Jan 12 11:42:46 2010
New Revision: 70521
Modified:
pypy/branch/jit-profiling/pypy/interpreter/executioncontext.py
pypy/branch/jit-profiling/pypy/interpreter/test/test_profiling.py
Log:
A bit break everything. Now the profiling hook is invoked depending on us
being jitted or not (except for leave)
Modified: pypy/branch/jit-profiling/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/branch/jit-profiling/pypy/interpreter/executioncontext.py (original)
+++ pypy/branch/jit-profiling/pypy/interpreter/executioncontext.py Tue Jan 12 11:42:46 2010
@@ -36,6 +36,9 @@
# XXX self.w_tracefunc, self.profilefunc
# XXX frame.is_being_profiled
+ # bind it here, so tests can overwrite it
+ _we_are_jitted = staticmethod(jit.we_are_jitted)
+
def __init__(self, space):
self.space = space
self.topframeref = jit.vref_None
@@ -75,7 +78,10 @@
def leave(self, frame):
try:
- if self.profilefunc:
+ # below we need to check if is_being_profiled is set, instead
+ # of profilefunc, since when jitted we have profilefunc, but not
+ # is_being_profiled
+ if frame.is_being_profiled:
self._trace(frame, TRACE_LEAVEFRAME, self.space.w_None)
finally:
self.topframeref = frame.f_backref
@@ -179,7 +185,8 @@
def call_trace(self, frame):
"Trace the call of a function"
- if self.w_tracefunc is not None or self.profilefunc is not None:
+ if (self.w_tracefunc is not None or
+ (not self._we_are_jitted() and self.profilefunc is not None)):
self._trace(frame, TRACE_CALL, self.space.w_None)
if self.profilefunc:
frame.is_being_profiled = True
Modified: pypy/branch/jit-profiling/pypy/interpreter/test/test_profiling.py
==============================================================================
--- pypy/branch/jit-profiling/pypy/interpreter/test/test_profiling.py (original)
+++ pypy/branch/jit-profiling/pypy/interpreter/test/test_profiling.py Tue Jan 12 11:42:46 2010
@@ -3,17 +3,31 @@
TRACE_RETURN
class MockExecutionContext(ExecutionContext):
- pass
+ _jitted = False
+
+ def _we_are_jitted(self):
+ return self._jitted
+
+ def enter_jit(self):
+ self._jitted = True
+
+ def leave_jit(self):
+ self._jitted = False
+
+ def call(self, frame):
+ self.enter(frame)
+ self.call_trace(frame)
class MockFrame(object):
- w_f_trace = None
- last_exception = None
+ w_f_trace = None
+ last_exception = None
+ is_being_profiled = False
def hide(self):
return False
class TestProfiling(object):
- def test_simple(self):
+ def test_no_jit(self):
events = []
def profilefunc(space, ignored, frame, event, w_arg):
events.append(event)
@@ -21,7 +35,25 @@
ec = MockExecutionContext(self.space)
frame = MockFrame()
ec.setllprofile(profilefunc, self.space.w_None)
- ec.enter(frame)
- ec.call_trace(frame)
+ ec.call(frame)
ec.leave(frame)
assert events == [TRACE_CALL, TRACE_RETURN]
+
+ def test_inlined_call(self):
+ events = []
+ def profilefunc(space, ignored, frame, event, w_arg):
+ events.append((event, frame))
+
+ ec = MockExecutionContext(self.space)
+ frame = MockFrame()
+ frame2 = MockFrame()
+ ec.setllprofile(profilefunc, self.space.w_None)
+ ec.call(frame)
+ ec.enter_jit()
+ ec.call(frame2)
+ ec.leave(frame2)
+ ec.call(frame2)
+ ec.leave(frame2)
+ ec.leave_jit()
+ ec.leave(frame)
+ assert events == [(TRACE_CALL, frame), (TRACE_RETURN, frame)]
More information about the Pypy-commit
mailing list