GH-93841: Allow stats to be turned on and off, cleared and dumped at runtime. (GH-93843)

This commit is contained in:
Mark Shannon 2022-06-21 15:40:54 +01:00 committed by GitHub
parent c7a79bb036
commit 6f8875eba3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 212 additions and 22 deletions

View file

@ -1909,6 +1909,66 @@ sys_is_finalizing_impl(PyObject *module)
return PyBool_FromLong(_Py_IsFinalizing());
}
#ifdef Py_STATS
/*[clinic input]
sys._stats_on
Turns on stats gathering (stats gathering is on by default).
[clinic start generated code]*/
static PyObject *
sys__stats_on_impl(PyObject *module)
/*[clinic end generated code: output=aca53eafcbb4d9fe input=8ddc6df94e484f3a]*/
{
_py_stats = &_py_stats_struct;
Py_RETURN_NONE;
}
/*[clinic input]
sys._stats_off
Turns off stats gathering (stats gathering is on by default).
[clinic start generated code]*/
static PyObject *
sys__stats_off_impl(PyObject *module)
/*[clinic end generated code: output=1534c1ee63812214 input=b3e50e71ecf29f66]*/
{
_py_stats = NULL;
Py_RETURN_NONE;
}
/*[clinic input]
sys._stats_clear
Clears the stats.
[clinic start generated code]*/
static PyObject *
sys__stats_clear_impl(PyObject *module)
/*[clinic end generated code: output=fb65a2525ee50604 input=3e03f2654f44da96]*/
{
_Py_StatsClear();
Py_RETURN_NONE;
}
/*[clinic input]
sys._stats_dump
Dump stats to file, and clears the stats.
[clinic start generated code]*/
static PyObject *
sys__stats_dump_impl(PyObject *module)
/*[clinic end generated code: output=79f796fb2b4ddf05 input=92346f16d64f6f95]*/
{
_Py_PrintSpecializationStats(1);
_Py_StatsClear();
Py_RETURN_NONE;
}
#endif
#ifdef ANDROID_API_LEVEL
/*[clinic input]
sys.getandroidapilevel
@ -1978,6 +2038,12 @@ static PyMethodDef sys_methods[] = {
SYS_GET_ASYNCGEN_HOOKS_METHODDEF
SYS_GETANDROIDAPILEVEL_METHODDEF
SYS_UNRAISABLEHOOK_METHODDEF
#ifdef Py_STATS
SYS__STATS_ON_METHODDEF
SYS__STATS_OFF_METHODDEF
SYS__STATS_CLEAR_METHODDEF
SYS__STATS_DUMP_METHODDEF
#endif
{NULL, NULL} // sentinel
};