Commit 73022d11 authored by Stefan Behnel's avatar Stefan Behnel

refactor profiling/tracing code, make proper use of "tstate->tracing", fix code-before-declaration

parent fd839c47
...@@ -35,20 +35,25 @@ ...@@ -35,20 +35,25 @@
#endif #endif
#define __Pyx_TraceDeclarations(codeobj) \ #define __Pyx_TraceDeclarations(codeobj) \
static PyCodeObject *$frame_code_cname = NULL; if (codeobj != NULL) $frame_code_cname = (PyCodeObject*) codeobj; \ static PyCodeObject *$frame_code_cname = NULL; \
CYTHON_FRAME_MODIFIER PyFrameObject *$frame_cname = NULL; \ CYTHON_FRAME_MODIFIER PyFrameObject *$frame_cname = NULL; \
int __Pyx_use_tracing = 0; int __Pyx_use_tracing = 0; \
if (codeobj) $frame_code_cname = (PyCodeObject*) codeobj;
#define __Pyx_TraceCall(funcname, srcfile, firstlineno) \ #define __Pyx_TraceCall(funcname, srcfile, firstlineno) \
if (unlikely(PyThreadState_GET()->use_tracing && \ { PyThreadState* tstate = PyThreadState_GET(); \
(PyThreadState_GET()->c_profilefunc || (CYTHON_TRACE && PyThreadState_GET()->c_tracefunc)))) { \ if (unlikely(tstate->use_tracing) && !tstate->tracing && \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, funcname, srcfile, firstlineno); \ __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, funcname, srcfile, firstlineno); \
} \
} }
#define __Pyx_TraceException() \ #define __Pyx_TraceException() \
if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing && \ if (likely(!__Pyx_use_tracing)); else { \
(PyThreadState_GET()->c_profilefunc || (CYTHON_TRACE && PyThreadState_GET()->c_tracefunc))) { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = PyThreadState_GET(); \
if (tstate->use_tracing && \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
tstate->tracing++; \
tstate->use_tracing = 0; \ tstate->use_tracing = 0; \
PyObject *exc_info = __Pyx_GetExceptionTuple(); \ PyObject *exc_info = __Pyx_GetExceptionTuple(); \
if (exc_info) { \ if (exc_info) { \
...@@ -60,11 +65,15 @@ ...@@ -60,11 +65,15 @@
Py_DECREF(exc_info); \ Py_DECREF(exc_info); \
} \ } \
tstate->use_tracing = 1; \ tstate->use_tracing = 1; \
tstate->tracing--; \
} \
} }
#define __Pyx_TraceReturn(result) \ #define __Pyx_TraceReturn(result) \
if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing) { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = PyThreadState_GET(); \
if (tstate->use_tracing) { \
tstate->tracing++; \
tstate->use_tracing = 0; \ tstate->use_tracing = 0; \
if (CYTHON_TRACE && tstate->c_tracefunc) \ if (CYTHON_TRACE && tstate->c_tracefunc) \
tstate->c_tracefunc( \ tstate->c_tracefunc( \
...@@ -74,6 +83,8 @@ ...@@ -74,6 +83,8 @@
tstate->c_profileobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \ tstate->c_profileobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \
CYTHON_FRAME_DEL; \ CYTHON_FRAME_DEL; \
tstate->use_tracing = 1; \ tstate->use_tracing = 1; \
tstate->tracing--; \
} \
} }
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/ static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/
...@@ -90,12 +101,16 @@ ...@@ -90,12 +101,16 @@
#if CYTHON_TRACE #if CYTHON_TRACE
#define __Pyx_TraceLine(lineno) \ #define __Pyx_TraceLine(lineno) \
if (unlikely(__Pyx_use_tracing) && unlikely(PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_tracefunc)) { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = PyThreadState_GET(); \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \
$frame_cname->f_lineno = lineno; \ $frame_cname->f_lineno = lineno; \
tstate->tracing++; \
tstate->use_tracing = 0; \ tstate->use_tracing = 0; \
tstate->c_tracefunc(tstate->c_traceobj, $frame_cname, PyTrace_LINE, NULL); \ tstate->c_tracefunc(tstate->c_traceobj, $frame_cname, PyTrace_LINE, NULL); \
tstate->use_tracing = 1; \ tstate->use_tracing = 1; \
tstate->tracing--; \
} \
} }
#else #else
#define __Pyx_TraceLine(lineno) #define __Pyx_TraceLine(lineno)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment