Commit 02be5753 authored by Stefan Behnel's avatar Stefan Behnel

Reduce some overhead in tracing code by avoiding to look up the thread state repeatedly.

parent e9dbd6df
/////////////// Profile.proto /////////////// /////////////// Profile.proto ///////////////
//@requires: Exceptions.c::PyErrFetchRestore
//@substitute: naming //@substitute: naming
// Note that cPython ignores PyTrace_EXCEPTION, // Note that cPython ignores PyTrace_EXCEPTION,
...@@ -110,7 +111,7 @@ ...@@ -110,7 +111,7 @@
static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) { static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) {
PyObject *type, *value, *traceback; PyObject *type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback); __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
tstate->tracing++; tstate->tracing++;
tstate->use_tracing = 0; tstate->use_tracing = 0;
if (CYTHON_TRACE && tstate->c_tracefunc) if (CYTHON_TRACE && tstate->c_tracefunc)
...@@ -120,7 +121,7 @@ ...@@ -120,7 +121,7 @@
CYTHON_FRAME_DEL(frame); CYTHON_FRAME_DEL(frame);
tstate->use_tracing = 1; tstate->use_tracing = 1;
tstate->tracing--; tstate->tracing--;
PyErr_Restore(type, value, traceback); __Pyx_ErrRestoreInState(tstate, type, value, traceback);
} }
#ifdef WITH_THREAD #ifdef WITH_THREAD
...@@ -172,7 +173,7 @@ ...@@ -172,7 +173,7 @@
static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) { static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) {
int ret; int ret;
PyObject *type, *value, *traceback; PyObject *type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback); __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
__Pyx_PyFrame_SetLineNumber(frame, lineno); __Pyx_PyFrame_SetLineNumber(frame, lineno);
tstate->tracing++; tstate->tracing++;
tstate->use_tracing = 0; tstate->use_tracing = 0;
...@@ -180,7 +181,7 @@ ...@@ -180,7 +181,7 @@
tstate->use_tracing = 1; tstate->use_tracing = 1;
tstate->tracing--; tstate->tracing--;
if (likely(!ret)) { if (likely(!ret)) {
PyErr_Restore(type, value, traceback); __Pyx_ErrRestoreInState(tstate, type, value, traceback);
} else { } else {
Py_XDECREF(type); Py_XDECREF(type);
Py_XDECREF(value); Py_XDECREF(value);
...@@ -266,7 +267,7 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, ...@@ -266,7 +267,7 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
retval = 1; retval = 1;
tstate->tracing++; tstate->tracing++;
tstate->use_tracing = 0; tstate->use_tracing = 0;
PyErr_Fetch(&type, &value, &traceback); __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
#if CYTHON_TRACE #if CYTHON_TRACE
if (tstate->c_tracefunc) if (tstate->c_tracefunc)
retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0; retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
...@@ -277,7 +278,7 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, ...@@ -277,7 +278,7 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
(CYTHON_TRACE && tstate->c_tracefunc)); (CYTHON_TRACE && tstate->c_tracefunc));
tstate->tracing--; tstate->tracing--;
if (retval) { if (retval) {
PyErr_Restore(type, value, traceback); __Pyx_ErrRestoreInState(tstate, type, value, traceback);
return tstate->use_tracing && retval; return tstate->use_tracing && retval;
} else { } else {
Py_XDECREF(type); Py_XDECREF(type);
......
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