diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-06 15:54:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-06 15:54:59 (GMT) |
commit | a0773b89dfe5cd2190d539905dd89e7f6455668e (patch) | |
tree | e11c7306e6ed7750265eda6ba8fa49f329bc0f85 /Lib/test/test_embed.py | |
parent | 8ff11425783806f8cb78e99f667546b1f7f3428e (diff) | |
download | cpython-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 'Lib/test/test_embed.py')
-rw-r--r-- | Lib/test/test_embed.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 50c9f61..7f1a4e6 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -26,6 +26,7 @@ MACOS = (sys.platform == 'darwin') PYMEM_ALLOCATOR_NOT_SET = 0 PYMEM_ALLOCATOR_DEBUG = 2 PYMEM_ALLOCATOR_MALLOC = 3 +Py_STATS = hasattr(sys, '_stats_on') # _PyCoreConfig_InitCompatConfig() API_COMPAT = 1 @@ -512,6 +513,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'safe_path': 0, '_is_python_build': IGNORE_CONFIG, } + if Py_STATS: + CONFIG_COMPAT['_pystats'] = 0 if MS_WINDOWS: CONFIG_COMPAT.update({ 'legacy_windows_stdio': 0, @@ -895,6 +898,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'check_hash_pycs_mode': 'always', 'pathconfig_warnings': 0, } + if Py_STATS: + config['_pystats'] = 1 self.check_all_configs("test_init_from_config", config, preconfig, api=API_COMPAT) @@ -927,6 +932,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'safe_path': 1, 'int_max_str_digits': 4567, } + if Py_STATS: + config['_pystats'] = 1 self.check_all_configs("test_init_compat_env", config, preconfig, api=API_COMPAT) @@ -960,6 +967,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'safe_path': 1, 'int_max_str_digits': 4567, } + if Py_STATS: + config['_pystats'] = 1 self.check_all_configs("test_init_python_env", config, preconfig, api=API_PYTHON) |