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,45 +35,56 @@ ...@@ -35,45 +35,56 @@
#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 && \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, funcname, srcfile, firstlineno); \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__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(); \
tstate->use_tracing = 0; \ if (tstate->use_tracing && \
PyObject *exc_info = __Pyx_GetExceptionTuple(); \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
if (exc_info) { \ tstate->tracing++; \
if (CYTHON_TRACE && tstate->c_tracefunc) \ tstate->use_tracing = 0; \
tstate->c_tracefunc( \ PyObject *exc_info = __Pyx_GetExceptionTuple(); \
tstate->c_traceobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \ if (exc_info) { \
tstate->c_profilefunc( \ if (CYTHON_TRACE && tstate->c_tracefunc) \
tstate->c_profileobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \ tstate->c_tracefunc( \
Py_DECREF(exc_info); \ tstate->c_traceobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \
tstate->c_profilefunc( \
tstate->c_profileobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \
Py_DECREF(exc_info); \
} \
tstate->use_tracing = 1; \
tstate->tracing--; \
} \ } \
tstate->use_tracing = 1; \
} }
#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(); \
tstate->use_tracing = 0; \ if (tstate->use_tracing) { \
if (CYTHON_TRACE && tstate->c_tracefunc) \ tstate->tracing++; \
tstate->c_tracefunc( \ tstate->use_tracing = 0; \
tstate->c_traceobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \ if (CYTHON_TRACE && tstate->c_tracefunc) \
if (tstate->c_profilefunc) \ tstate->c_tracefunc( \
tstate->c_profilefunc( \ tstate->c_traceobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \
tstate->c_profileobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \ if (tstate->c_profilefunc) \
CYTHON_FRAME_DEL; \ tstate->c_profilefunc( \
tstate->use_tracing = 1; \ tstate->c_profileobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \
CYTHON_FRAME_DEL; \
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(); \
$frame_cname->f_lineno = lineno; \ if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \
tstate->use_tracing = 0; \ $frame_cname->f_lineno = lineno; \
tstate->c_tracefunc(tstate->c_traceobj, $frame_cname, PyTrace_LINE, NULL); \ tstate->tracing++; \
tstate->use_tracing = 1; \ tstate->use_tracing = 0; \
tstate->c_tracefunc(tstate->c_traceobj, $frame_cname, PyTrace_LINE, NULL); \
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