Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 31796:1c117dbb2def legacy-trunk
Enable the profiling of C functions (builtins and extensions)
| author | Nicholas Bastin <nick.bastin@gmail.com> |
|---|---|
| date | Wed, 24 Mar 2004 21:57:10 +0000 |
| parents | 9817dee5d9df |
| children | 846b3ee7e106 |
line wrap: on
line diff
--- a/Python/ceval.c Wed Mar 24 16:48:24 2004 +0000 +++ b/Python/ceval.c Wed Mar 24 21:57:10 2004 +0000 @@ -536,9 +536,7 @@ return 0; } - /* Status code for main loop (reason for stack unwind) */ - enum why_code { WHY_NOT, /* No error */ WHY_EXCEPTION, /* Exception occurred */ @@ -3425,6 +3423,42 @@ nargs); } +#define BEGIN_C_TRACE \ +if (tstate->use_tracing) { \ + if (tstate->c_profilefunc != NULL) { \ + PyObject *func_name = \ + PyString_FromString (((PyCFunctionObject *) \ + func)->m_ml->ml_name); \ + are_tracing = 1; \ + if (call_trace(tstate->c_profilefunc, \ + tstate->c_profileobj, \ + tstate->frame, PyTrace_C_CALL, \ + func_name)) \ + { return NULL; } \ + Py_DECREF (func_name); \ + } \ + } + +#define END_C_TRACE \ + if (tstate->use_tracing && are_tracing) { \ + if (tstate->c_profilefunc != NULL) { \ + if (x == NULL) { \ + if (call_trace (tstate->c_profilefunc, \ + tstate->c_profileobj, \ + tstate->frame, PyTrace_C_EXCEPTION, \ + NULL)) \ + { return NULL; } \ + } else { \ + if (call_trace(tstate->c_profilefunc, \ + tstate->c_profileobj, \ + tstate->frame, PyTrace_C_RETURN, \ + NULL)) \ + { return NULL; } \ + } \ + } \ + } + + static PyObject * call_function(PyObject ***pp_stack, int oparg) { @@ -3435,6 +3469,10 @@ PyObject *func = *pfunc; PyObject *x, *w; + int are_tracing = 0; + + PyThreadState *tstate = PyThreadState_GET(); + /* Always dispatch PyCFunction first, because these are presumed to be the most frequent callable object. */ @@ -3444,11 +3482,16 @@ if (flags & (METH_NOARGS | METH_O)) { PyCFunction meth = PyCFunction_GET_FUNCTION(func); PyObject *self = PyCFunction_GET_SELF(func); - if (flags & METH_NOARGS && na == 0) + if (flags & METH_NOARGS && na == 0) { + BEGIN_C_TRACE x = (*meth)(self, NULL); + END_C_TRACE + } else if (flags & METH_O && na == 1) { PyObject *arg = EXT_POP(*pp_stack); + BEGIN_C_TRACE x = (*meth)(self, arg); + END_C_TRACE Py_DECREF(arg); } else { @@ -3459,7 +3502,9 @@ else { PyObject *callargs; callargs = load_args(pp_stack, na); + BEGIN_C_TRACE x = PyCFunction_Call(func, callargs, NULL); + END_C_TRACE Py_XDECREF(callargs); } } else {
