mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
Revise the interface to the profiling and tracing support for the
Python interpreter. This change adds two new C-level APIs: PyEval_SetProfile() and PyEval_SetTrace(). These can be used to install profile and trace functions implemented in C, which can operate at much higher speeds than Python-based functions. The overhead for calling a C-based profile function is a very small fraction of a percent of the overhead involved in calling a Python-based function. The machinery required to call a Python-based profile or trace function been moved to sysmodule.c, where sys.setprofile() and sys.setprofile() simply become users of the new interface.
This commit is contained in:
parent
8f4558583f
commit
55fb6e0371
2 changed files with 16 additions and 2 deletions
|
@ -22,6 +22,9 @@ DL_IMPORT(PyObject *) PyEval_CallFunction(PyObject *obj, char *format, ...);
|
||||||
DL_IMPORT(PyObject *) PyEval_CallMethod(PyObject *obj,
|
DL_IMPORT(PyObject *) PyEval_CallMethod(PyObject *obj,
|
||||||
char *methodname, char *format, ...);
|
char *methodname, char *format, ...);
|
||||||
|
|
||||||
|
DL_IMPORT(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
|
||||||
|
DL_IMPORT(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
|
||||||
|
|
||||||
DL_IMPORT(PyObject *) PyEval_GetBuiltins(void);
|
DL_IMPORT(PyObject *) PyEval_GetBuiltins(void);
|
||||||
DL_IMPORT(PyObject *) PyEval_GetGlobals(void);
|
DL_IMPORT(PyObject *) PyEval_GetGlobals(void);
|
||||||
DL_IMPORT(PyObject *) PyEval_GetLocals(void);
|
DL_IMPORT(PyObject *) PyEval_GetLocals(void);
|
||||||
|
|
|
@ -31,6 +31,15 @@ typedef struct _is {
|
||||||
|
|
||||||
struct _frame; /* Avoid including frameobject.h */
|
struct _frame; /* Avoid including frameobject.h */
|
||||||
|
|
||||||
|
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
|
||||||
|
typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
|
||||||
|
|
||||||
|
/* The following values are used for 'what' for tracefunc functions: */
|
||||||
|
#define PyTrace_CALL 0
|
||||||
|
#define PyTrace_EXCEPTION 1
|
||||||
|
#define PyTrace_LINE 2
|
||||||
|
#define PyTrace_RETURN 3
|
||||||
|
|
||||||
typedef struct _ts {
|
typedef struct _ts {
|
||||||
|
|
||||||
struct _ts *next;
|
struct _ts *next;
|
||||||
|
@ -41,8 +50,10 @@ typedef struct _ts {
|
||||||
int ticker;
|
int ticker;
|
||||||
int tracing;
|
int tracing;
|
||||||
|
|
||||||
PyObject *sys_profilefunc;
|
Py_tracefunc c_profilefunc;
|
||||||
PyObject *sys_tracefunc;
|
Py_tracefunc c_tracefunc;
|
||||||
|
PyObject *c_profileobj;
|
||||||
|
PyObject *c_traceobj;
|
||||||
|
|
||||||
PyObject *curexc_type;
|
PyObject *curexc_type;
|
||||||
PyObject *curexc_value;
|
PyObject *curexc_value;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue