Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55fb6e0

Browse files
committed
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.
1 parent 8f45585 commit 55fb6e0

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

Include/ceval.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ DL_IMPORT(PyObject *) PyEval_CallFunction(PyObject *obj, char *format, ...);
2222
DL_IMPORT(PyObject *) PyEval_CallMethod(PyObject *obj,
2323
char *methodname, char *format, ...);
2424

25+
DL_IMPORT(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
26+
DL_IMPORT(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
27+
2528
DL_IMPORT(PyObject *) PyEval_GetBuiltins(void);
2629
DL_IMPORT(PyObject *) PyEval_GetGlobals(void);
2730
DL_IMPORT(PyObject *) PyEval_GetLocals(void);

Include/pystate.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ typedef struct _is {
3131

3232
struct _frame; /* Avoid including frameobject.h */
3333

34+
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
35+
typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
36+
37+
/* The following values are used for 'what' for tracefunc functions: */
38+
#define PyTrace_CALL 0
39+
#define PyTrace_EXCEPTION 1
40+
#define PyTrace_LINE 2
41+
#define PyTrace_RETURN 3
42+
3443
typedef struct _ts {
3544

3645
struct _ts *next;
@@ -41,8 +50,10 @@ typedef struct _ts {
4150
int ticker;
4251
int tracing;
4352

44-
PyObject *sys_profilefunc;
45-
PyObject *sys_tracefunc;
53+
Py_tracefunc c_profilefunc;
54+
Py_tracefunc c_tracefunc;
55+
PyObject *c_profileobj;
56+
PyObject *c_traceobj;
4657

4758
PyObject *curexc_type;
4859
PyObject *curexc_value;

0 commit comments

Comments
 (0)