diff options
author | Victor Stinner <vstinner@python.org> | 2021-10-15 14:06:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 14:06:30 (GMT) |
commit | 547d26aa08aa5e4ec6e4f8a5587b30b39064a5ba (patch) | |
tree | f89a1327f1847ca97929efec97a12cab09478b2a /Python/sysmodule.c | |
parent | 354c35220d25a893e502014478f6739dad6897f3 (diff) | |
download | cpython-547d26aa08aa5e4ec6e4f8a5587b30b39064a5ba.zip cpython-547d26aa08aa5e4ec6e4f8a5587b30b39064a5ba.tar.gz cpython-547d26aa08aa5e4ec6e4f8a5587b30b39064a5ba.tar.bz2 |
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().
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ad9be71..5e663c1 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -256,8 +256,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event, } /* Disallow tracing in hooks unless explicitly enabled */ - ts->tracing++; - ts->cframe->use_tracing = 0; + PyThreadState_EnterTracing(ts); while ((hook = PyIter_Next(hooks)) != NULL) { _Py_IDENTIFIER(__cantrace__); PyObject *o; @@ -270,14 +269,12 @@ sys_audit_tstate(PyThreadState *ts, const char *event, break; } if (canTrace) { - ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc) ? 255 : 0; - ts->tracing--; + PyThreadState_LeaveTracing(ts); } PyObject* args[2] = {eventName, eventArgs}; o = _PyObject_FastCallTstate(ts, hook, args, 2); if (canTrace) { - ts->tracing++; - ts->cframe->use_tracing = 0; + PyThreadState_EnterTracing(ts); } if (!o) { break; @@ -285,8 +282,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event, Py_DECREF(o); Py_CLEAR(hook); } - ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc) ? 255 : 0; - ts->tracing--; + PyThreadState_LeaveTracing(ts); if (_PyErr_Occurred(ts)) { goto exit; } |