[Python-checkins] python/dist/src/Python ceval.c, 2.386,
2.387 sysmodule.c, 2.121, 2.122
mondragon at users.sourceforge.net
mondragon at users.sourceforge.net
Wed Mar 24 16:57:12 EST 2004
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8622/Python
Modified Files:
ceval.c sysmodule.c
Log Message:
Enable the profiling of C functions (builtins and extensions)
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.386
retrieving revision 2.387
diff -C2 -d -r2.386 -r2.387
*** ceval.c 22 Mar 2004 19:24:58 -0000 2.386
--- ceval.c 24 Mar 2004 21:57:09 -0000 2.387
***************
*** 537,543 ****
}
-
/* Status code for main loop (reason for stack unwind) */
-
enum why_code {
WHY_NOT, /* No error */
--- 537,541 ----
***************
*** 3426,3429 ****
--- 3424,3463 ----
}
+ #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)
***************
*** 3436,3439 ****
--- 3470,3477 ----
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.
***************
*** 3445,3453 ****
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
! if (flags & METH_NOARGS && na == 0)
x = (*meth)(self, NULL);
else if (flags & METH_O && na == 1) {
PyObject *arg = EXT_POP(*pp_stack);
x = (*meth)(self, arg);
Py_DECREF(arg);
}
--- 3483,3496 ----
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
! 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);
}
***************
*** 3460,3464 ****
--- 3503,3509 ----
PyObject *callargs;
callargs = load_args(pp_stack, na);
+ BEGIN_C_TRACE
x = PyCFunction_Call(func, callargs, NULL);
+ END_C_TRACE
Py_XDECREF(callargs);
}
Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.121
retrieving revision 2.122
diff -C2 -d -r2.121 -r2.122
*** sysmodule.c 9 Aug 2003 09:47:11 -0000 2.121
--- sysmodule.c 24 Mar 2004 21:57:10 -0000 2.122
***************
*** 273,285 ****
* trace functions. Initialized by trace_init().
*/
! static PyObject *whatstrings[4] = {NULL, NULL, NULL, NULL};
static int
trace_init(void)
{
! static char *whatnames[4] = {"call", "exception", "line", "return"};
PyObject *name;
int i;
! for (i = 0; i < 4; ++i) {
if (whatstrings[i] == NULL) {
name = PyString_InternFromString(whatnames[i]);
--- 273,286 ----
* trace functions. Initialized by trace_init().
*/
! static PyObject *whatstrings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
static int
trace_init(void)
{
! static char *whatnames[7] = {"call", "exception", "line", "return",
! "c_call", "c_exception", "c_return"};
PyObject *name;
int i;
! for (i = 0; i < 7; ++i) {
if (whatstrings[i] == NULL) {
name = PyString_InternFromString(whatnames[i]);
More information about the Python-checkins
mailing list