summaryrefslogtreecommitdiffstats
path: root/Include/internal
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-10-15 14:06:30 (GMT)
committerGitHub <noreply@github.com>2021-10-15 14:06:30 (GMT)
commit547d26aa08aa5e4ec6e4f8a5587b30b39064a5ba (patch)
treef89a1327f1847ca97929efec97a12cab09478b2a /Include/internal
parent354c35220d25a893e502014478f6739dad6897f3 (diff)
downloadcpython-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 'Include/internal')
-rw-r--r--Include/internal/pycore_pystate.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index 1b74e5f..d632397 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -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);