summaryrefslogtreecommitdiffstats
path: root/Python/clinic/sysmodule.c.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-06 15:54:59 (GMT)
committerGitHub <noreply@github.com>2023-09-06 15:54:59 (GMT)
commita0773b89dfe5cd2190d539905dd89e7f6455668e (patch)
treee11c7306e6ed7750265eda6ba8fa49f329bc0f85 /Python/clinic/sysmodule.c.h
parent8ff11425783806f8cb78e99f667546b1f7f3428e (diff)
downloadcpython-a0773b89dfe5cd2190d539905dd89e7f6455668e.zip
cpython-a0773b89dfe5cd2190d539905dd89e7f6455668e.tar.gz
cpython-a0773b89dfe5cd2190d539905dd89e7f6455668e.tar.bz2
gh-108753: Enhance pystats (#108754)
Statistics gathering is now off by default. Use the "-X pystats" command line option or set the new PYTHONSTATS environment variable to 1 to turn statistics gathering on at Python startup. Statistics are no longer dumped at exit if statistics gathering was off or statistics have been cleared. Changes: * Add PYTHONSTATS environment variable. * sys._stats_dump() now returns False if statistics are not dumped because they are all equal to zero. * Add PyConfig._pystats member. * Add tests on sys functions and on setting PyConfig._pystats to 1. * Add Include/cpython/pystats.h and Include/internal/pycore_pystats.h header files. * Rename '_py_stats' variable to '_Py_stats'. * Exclude Include/cpython/pystats.h from the Py_LIMITED_API. * Move pystats.h include from object.h to Python.h. * Add _Py_StatsOn() and _Py_StatsOff() functions. Remove '_py_stats_struct' variable from the API: make it static in specialize.c. * Document API in Include/pystats.h and Include/cpython/pystats.h. * Complete pystats documentation in Doc/using/configure.rst. * Don't write "all zeros" stats: if _stats_off() and _stats_clear() or _stats_dump() were called. * _PyEval_Fini() now always call _Py_PrintSpecializationStats() which does nothing if stats are all zeros. Co-authored-by: Michael Droettboom <mdboom@gmail.com>
Diffstat (limited to 'Python/clinic/sysmodule.c.h')
-rw-r--r--Python/clinic/sysmodule.c.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h
index a4b3987..30691c3 100644
--- a/Python/clinic/sysmodule.c.h
+++ b/Python/clinic/sysmodule.c.h
@@ -1120,7 +1120,7 @@ PyDoc_STRVAR(sys__stats_on__doc__,
"_stats_on($module, /)\n"
"--\n"
"\n"
-"Turns on stats gathering (stats gathering is on by default).");
+"Turns on stats gathering (stats gathering is off by default).");
#define SYS__STATS_ON_METHODDEF \
{"_stats_on", (PyCFunction)sys__stats_on, METH_NOARGS, sys__stats_on__doc__},
@@ -1142,7 +1142,7 @@ PyDoc_STRVAR(sys__stats_off__doc__,
"_stats_off($module, /)\n"
"--\n"
"\n"
-"Turns off stats gathering (stats gathering is on by default).");
+"Turns off stats gathering (stats gathering is off by default).");
#define SYS__STATS_OFF_METHODDEF \
{"_stats_off", (PyCFunction)sys__stats_off, METH_NOARGS, sys__stats_off__doc__},
@@ -1186,18 +1186,30 @@ PyDoc_STRVAR(sys__stats_dump__doc__,
"_stats_dump($module, /)\n"
"--\n"
"\n"
-"Dump stats to file, and clears the stats.");
+"Dump stats to file, and clears the stats.\n"
+"\n"
+"Return False if no statistics were not dumped because stats gathering was off.");
#define SYS__STATS_DUMP_METHODDEF \
{"_stats_dump", (PyCFunction)sys__stats_dump, METH_NOARGS, sys__stats_dump__doc__},
-static PyObject *
+static int
sys__stats_dump_impl(PyObject *module);
static PyObject *
sys__stats_dump(PyObject *module, PyObject *Py_UNUSED(ignored))
{
- return sys__stats_dump_impl(module);
+ PyObject *return_value = NULL;
+ int _return_value;
+
+ _return_value = sys__stats_dump_impl(module);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+ return return_value;
}
#endif /* defined(Py_STATS) */
@@ -1411,4 +1423,4 @@ exit:
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
#define SYS_GETANDROIDAPILEVEL_METHODDEF
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
-/*[clinic end generated code: output=6619682ea70e7375 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=549bb1f92a15f916 input=a9049054013a1b77]*/