diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-08-24 23:21:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 23:21:39 +0100 |
commit | e34c82abeb7ace09e6b5d116585c47cc372996c1 (patch) | |
tree | 16f130870af42de041ddf52a36540b9c421aec8c /Python/sysmodule.c | |
parent | 657976ad950e56b33b7dc15e64a0baecdd184f5a (diff) | |
download | cpython-e34c82abeb7ace09e6b5d116585c47cc372996c1.tar.gz cpython-e34c82abeb7ace09e6b5d116585c47cc372996c1.zip |
GH-93503: Add thread-specific APIs to set profiling and tracing functions in the C-API (#93504)
* gh-93503: Add APIs to set profiling and tracing functions in all threads in the C-API
* Use a separate API
* Fix NEWS entry
* Add locks around the loop
* Document ignoring exceptions
* Use the new APIs in the sys module
* Update docs
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b8009b2db45..c2864387941 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1022,6 +1022,36 @@ function call. See the debugger chapter in the library manual." ); /*[clinic input] +sys._settraceallthreads + + arg: object + / + +Set the global debug tracing function in all running threads belonging to the current interpreter. + +It will be called on each function call. See the debugger chapter +in the library manual. +[clinic start generated code]*/ + +static PyObject * +sys__settraceallthreads(PyObject *module, PyObject *arg) +/*[clinic end generated code: output=161cca30207bf3ca input=5906aa1485a50289]*/ +{ + PyObject* argument = NULL; + Py_tracefunc func = NULL; + + if (arg != Py_None) { + func = trace_trampoline; + argument = arg; + } + + + PyEval_SetTraceAllThreads(func, argument); + + Py_RETURN_NONE; +} + +/*[clinic input] sys.gettrace Return the global debug tracing function set with sys.settrace. @@ -1067,6 +1097,35 @@ and return. See the profiler chapter in the library manual." ); /*[clinic input] +sys._setprofileallthreads + + arg: object + / + +Set the profiling function in all running threads belonging to the current interpreter. + +It will be called on each function call and return. See the profiler chapter +in the library manual. +[clinic start generated code]*/ + +static PyObject * +sys__setprofileallthreads(PyObject *module, PyObject *arg) +/*[clinic end generated code: output=2d61319e27b309fe input=d1a356d3f4f9060a]*/ +{ + PyObject* argument = NULL; + Py_tracefunc func = NULL; + + if (arg != Py_None) { + func = profile_trampoline; + argument = arg; + } + + PyEval_SetProfileAllThreads(func, argument); + + Py_RETURN_NONE; +} + +/*[clinic input] sys.getprofile Return the profiling function set with sys.setprofile. @@ -2035,9 +2094,11 @@ static PyMethodDef sys_methods[] = { SYS_GETSWITCHINTERVAL_METHODDEF SYS_SETDLOPENFLAGS_METHODDEF {"setprofile", sys_setprofile, METH_O, setprofile_doc}, + SYS__SETPROFILEALLTHREADS_METHODDEF SYS_GETPROFILE_METHODDEF SYS_SETRECURSIONLIMIT_METHODDEF {"settrace", sys_settrace, METH_O, settrace_doc}, + SYS__SETTRACEALLTHREADS_METHODDEF SYS_GETTRACE_METHODDEF SYS_CALL_TRACING_METHODDEF SYS__DEBUGMALLOCSTATS_METHODDEF |