mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-43760: Add PyThreadState_EnterTracing() (GH-28542)
Add PyThreadState_EnterTracing() and PyThreadState_LeaveTracing() functions to the limited C API to suspend and resume tracing and profiling. Add an unit test on the PyThreadState C API to _testcapi. Add also internal _PyThreadState_DisableTracing() and _PyThreadState_ResetTracing().
This commit is contained in:
parent
354c35220d
commit
547d26aa08
9 changed files with 146 additions and 25 deletions
|
@ -185,6 +185,13 @@ PyAPI_FUNC(PyThreadState *) _PyThreadState_UncheckedGet(void);
|
|||
|
||||
PyAPI_FUNC(PyObject *) _PyThreadState_GetDict(PyThreadState *tstate);
|
||||
|
||||
// Disable tracing and profiling.
|
||||
PyAPI_FUNC(void) PyThreadState_EnterTracing(PyThreadState *tstate);
|
||||
|
||||
// Reset tracing and profiling: enable them if a trace function or a profile
|
||||
// function is set, otherwise disable them.
|
||||
PyAPI_FUNC(void) PyThreadState_LeaveTracing(PyThreadState *tstate);
|
||||
|
||||
/* PyGILState */
|
||||
|
||||
/* Helper/diagnostic function - return 1 if the current thread
|
||||
|
|
|
@ -125,7 +125,7 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
|
|||
}
|
||||
|
||||
|
||||
/* Other */
|
||||
// PyThreadState functions
|
||||
|
||||
PyAPI_FUNC(void) _PyThreadState_Init(
|
||||
PyThreadState *tstate);
|
||||
|
@ -133,6 +133,23 @@ PyAPI_FUNC(void) _PyThreadState_DeleteExcept(
|
|||
_PyRuntimeState *runtime,
|
||||
PyThreadState *tstate);
|
||||
|
||||
static inline void
|
||||
_PyThreadState_DisableTracing(PyThreadState *tstate)
|
||||
{
|
||||
tstate->cframe->use_tracing = 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
_PyThreadState_ResetTracing(PyThreadState *tstate)
|
||||
{
|
||||
int use_tracing = (tstate->c_tracefunc != NULL
|
||||
|| tstate->c_profilefunc != NULL);
|
||||
tstate->cframe->use_tracing = (use_tracing ? 255 : 0);
|
||||
}
|
||||
|
||||
|
||||
/* Other */
|
||||
|
||||
PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap(
|
||||
struct _gilstate_runtime_state *gilstate,
|
||||
PyThreadState *newts);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue