[pypy-svn] r56443 - in pypy/branch/builtin-profiling/pypy/interpreter: . test

stephan at codespeak.net stephan at codespeak.net
Fri Jul 11 14:15:41 CEST 2008


Author: stephan
Date: Fri Jul 11 14:15:41 2008
New Revision: 56443

Modified:
   pypy/branch/builtin-profiling/pypy/interpreter/executioncontext.py
   pypy/branch/builtin-profiling/pypy/interpreter/gateway.py
   pypy/branch/builtin-profiling/pypy/interpreter/test/test_executioncontext.py
Log:
(stephan) another not working version


Modified: pypy/branch/builtin-profiling/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/branch/builtin-profiling/pypy/interpreter/executioncontext.py	(original)
+++ pypy/branch/builtin-profiling/pypy/interpreter/executioncontext.py	Fri Jul 11 14:15:41 2008
@@ -104,20 +104,23 @@
         space.setitem(w_globals, w_key, w_value)
         return w_globals
 
-    def c_call_llprofile(self, w_func):
+    def c_call_trace(self, frame, w_func):
         "Profile the call of a builtin function"
         if self.profilefunc is not None:
-            self._llprofile('c_call', w_func)
+            self._trace(frame, 'c_call', w_func)
+            #self._llprofile('c_call', w_func)
 
-    def c_return_llprofile(self, w_retval):
+    def c_return_trace(self, frame, w_retval):
         "Profile the return from a builtin function"
         if self.profilefunc is not None:
-            self._llprofile('c_return', w_retval)
+            self._trace(frame, 'c_return', w_retval)
+            #self._llprofile('c_return', w_retval)
 
-    def c_exception_llprofile(self, operationerr):
+    def c_exception_trace(self, frame, operationerr):
         "Profile function called upon OperationError."
         if self.profilefunc is not None:
-            self._llprofile('c_exception', operationerr)
+            #self._llprofile('c_exception', operationerr)
+            self._trace(frame, 'c_exception', operationerr)
 
     def _llprofile(self, event, w_arg):
         fr = self.framestack.items
@@ -201,7 +204,7 @@
             self.is_tracing = is_tracing
 
     def _trace(self, frame, event, w_arg, operr=None):
-        if self.is_tracing or frame.hide():
+        if self.is_tracing or frame.hide() or frame is None:
             return
 
         space = self.space
@@ -237,7 +240,7 @@
 
         # Profile cases
         if self.profilefunc is not None:
-            if event not in ['leaveframe', 'call']:
+            if event not in ['leaveframe', 'call', 'c_call', 'c_return']:
                 return
 
             last_exception = None

Modified: pypy/branch/builtin-profiling/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/builtin-profiling/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/builtin-profiling/pypy/interpreter/gateway.py	Fri Jul 11 14:15:41 2008
@@ -378,6 +378,16 @@
     else:
         return typ.__name__ + '_w'
 
+def getexecutioncontext_and_frame(space):
+    ctx = space.getexecutioncontext()
+    if not ctx.framestack.empty():
+        frame = ctx.framestack.top()
+    else:
+        ctx = None
+        frame = None
+    return ctx, frame
+
+
 class BuiltinCode(eval.Code):
     "The code object implementing a built-in (interpreter-level) hook."
     _immutable_ = True
@@ -480,13 +490,15 @@
 
     def funcrun(self, func, args):
         space = func.space
-        ctx = space.getexecutioncontext()
+        #ctx, frame = getexecutioncontext_and_frame(space)
         activation = self.activation
         scope_w = args.parse(func.name, self.sig, func.defs_w)
         try:
-            ctx.c_call_llprofile(activation._run)
+            #if frame:
+            #    ctx.c_call_trace(frame, activation._run)
             w_result = activation._run(space, scope_w)
-            ctx.c_return_llprofile(w_result)
+            #if frame:
+            #    ctx.c_return_trace(frame, w_result)
         except KeyboardInterrupt: 
             raise OperationError(space.w_KeyboardInterrupt,
                                  space.w_None) 
@@ -512,11 +524,13 @@
 
     def funcrun(self, func, args):
         space = func.space
-        ctx = space.getexecutioncontext()
+        #ctx, frame = getexecutioncontext_and_frame(space)
         try:
-            ctx.c_call_llprofile(self.func__args__)
+            #if frame:
+            #    ctx.c_call_trace(frame, self.func__args__)
             w_result = self.func__args__(space, args)
-            ctx.c_return_llprofile(w_result)
+            #if frame:
+            #    ctx.c_return_trace(frame, w_result)
         except KeyboardInterrupt: 
             raise OperationError(space.w_KeyboardInterrupt, space.w_None) 
         except MemoryError: 
@@ -539,16 +553,18 @@
 
     def funcrun(self, func, args):
         space = func.space
-        ctx = space.getexecutioncontext()
+        #ctx, frame = getexecutioncontext_and_frame(space)
         try:
             w_obj, newargs = args.popfirst()
         except IndexError:
             return BuiltinCode.funcrun(self, func, args)
         else:
             try:
-                ctx.c_call_llprofile(self.func__args__)
+                #if frame:
+                #    ctx.c_call_trace(frame, self.func__args__)
                 w_result = self.func__args__(space, w_obj, newargs)
-                ctx.c_return_llprofile(w_result)
+                #if frame:
+                #    ctx.c_return_trace(frame, w_result)
             except KeyboardInterrupt: 
                 raise OperationError(space.w_KeyboardInterrupt, space.w_None) 
             except MemoryError: 
@@ -571,10 +587,12 @@
     def fastcall_0(self, space, w_func):
         self = hint(self, deepfreeze=True)
         try:
-            ctx = space.getexecutioncontext()
-            ctx.c_call_llprofile(self.fastfunc_0)
+            #ctx, frame = getexecutioncontext_and_frame(space)
+            #if frame:
+            #    ctx.c_call_trace(frame, self.fastfunc_0)
             w_result = self.fastfunc_0(space)
-            ctx.c_return_llprofile(w_result)
+            #if frame:
+            #    ctx.c_return_trace(frame, w_result)
         except KeyboardInterrupt: 
             raise OperationError(space.w_KeyboardInterrupt, space.w_None) 
         except MemoryError: 
@@ -590,10 +608,12 @@
     def fastcall_1(self, space, w_func, w1):
         self = hint(self, deepfreeze=True)
         try:
-            ctx = space.getexecutioncontext()
-            ctx.c_call_llprofile(self.fastfunc_1)
+            #ctx, frame = getexecutioncontext_and_frame(space)
+            #if frame:
+            #    ctx.c_call_trace(frame, self.fastfunc_1)
             w_result = self.fastfunc_1(space, w1)
-            ctx.c_return_llprofile(w_result)
+            #if frame:
+            #    ctx.c_return_trace(frame, w_result)
         except KeyboardInterrupt: 
             raise OperationError(space.w_KeyboardInterrupt, space.w_None) 
         except MemoryError: 
@@ -616,10 +636,12 @@
     def fastcall_2(self, space, w_func, w1, w2):
         self = hint(self, deepfreeze=True)
         try:
-            ctx = space.getexecutioncontext()
-            ctx.c_call_llprofile(self.fastfunc_2)
+            #ctx, frame = getexecutioncontext_and_frame(space)
+            #if frame:
+            #    ctx.c_call_trace(frame, self.fastfunc_2)
             w_result = self.fastfunc_2(space, w1, w2)
-            ctx.c_return_llprofile(w_result)
+            #if frame:
+            #    ctx.c_return_trace(frame, w_result)
         except KeyboardInterrupt: 
             raise OperationError(space.w_KeyboardInterrupt, space.w_None) 
         except MemoryError: 
@@ -642,10 +664,12 @@
     def fastcall_3(self, space, w_func, w1, w2, w3):
         self = hint(self, deepfreeze=True)
         try:
-            ctx = space.getexecutioncontext()
-            ctx.c_call_llprofile(self.fastfunc_3)
+            #ctx, frame = getexecutioncontext_and_frame(space)
+            #if frame:
+            #    ctx.c_call_trace(frame, self.fastfunc_3)
             w_result = self.fastfunc_3(space, w1, w2, w3)
-            ctx.c_return_llprofile(w_result)
+            #if frame:
+            #    ctx.c_return_trace(frame, w_result)
         except KeyboardInterrupt: 
             raise OperationError(space.w_KeyboardInterrupt, space.w_None) 
         except MemoryError: 
@@ -667,11 +691,13 @@
 class BuiltinCode4(BuiltinCode):
     def fastcall_4(self, space, w_func, w1, w2, w3, w4):
         self = hint(self, deepfreeze=True)
+        #ctx, frame = getexecutioncontext_and_frame(space)
         try:
-            ctx = space.getexecutioncontext()
-            ctx.c_call_llprofile(self.fastfunc_4)
+            #if frame:
+                #ctx.c_call_trace(frame, self.fastfunc_4)
             w_result = self.fastfunc_4(space, w1, w2, w3, w4)
-            ctx.c_return_llprofile(w_result)
+            #if frame:
+            #    ctx.c_return_trace(frame, w_result)
         except KeyboardInterrupt: 
             raise OperationError(space.w_KeyboardInterrupt, space.w_None) 
         except MemoryError: 

Modified: pypy/branch/builtin-profiling/pypy/interpreter/test/test_executioncontext.py
==============================================================================
--- pypy/branch/builtin-profiling/pypy/interpreter/test/test_executioncontext.py	(original)
+++ pypy/branch/builtin-profiling/pypy/interpreter/test/test_executioncontext.py	Fri Jul 11 14:15:41 2008
@@ -73,9 +73,12 @@
         space.appexec([], """():
         l = []
         l.append(3)
+
+        return l
         """)
         space.getexecutioncontext().setllprofile(None, None)
         from pprint import pprint
-        pprint([(x, y, z) for x,y,z in l if x in ('call','c_call')])
+        pprint(l)
+        #pprint([(x, y, z) for x,y,z in l if x in ('call','c_call')])
         assert l == ['call', 'return', 'call', 'c_call', 'c_return', 'return']
 



More information about the Pypy-commit mailing list