GH-100143: Improve collecting pystats for parts of runs (GH-100144)

* pystats off by default

* Add -Xpystats flag

* Always dump pystats, even if turned off
This commit is contained in:
Michael Droettboom 2022-12-12 09:50:43 -05:00 committed by GitHub
parent e4ea33b178
commit 1583c6e326
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 25 deletions

View file

@ -129,7 +129,14 @@ The following implementation-specific options are available:\n\
\n\
-X int_max_str_digits=number: limit the size of int<->str conversions.\n\
This helps avoid denial of service attacks when parsing untrusted data.\n\
The default is sys.int_info.default_max_str_digits. 0 disables.";
The default is sys.int_info.default_max_str_digits. 0 disables."
#ifdef Py_STATS
"\n\
\n\
-X pystats: Enable pystats collection at startup."
#endif
;
/* Envvars that don't have equivalent command-line options are listed first */
static const char usage_envvars[] =
@ -2186,6 +2193,12 @@ config_read(PyConfig *config, int compute_path_config)
config->show_ref_count = 1;
}
#ifdef Py_STATS
if (config_get_xoption(config, L"pystats")) {
_py_stats = &_py_stats_struct;
}
#endif
status = config_read_complex_options(config);
if (_PyStatus_EXCEPTION(status)) {
return status;

View file

@ -18,7 +18,7 @@
#ifdef Py_STATS
PyStats _py_stats_struct = { 0 };
PyStats *_py_stats = &_py_stats_struct;
PyStats *_py_stats = NULL;
#define ADD_STAT_TO_DICT(res, field) \
do { \
@ -205,9 +205,6 @@ _Py_StatsClear(void)
void
_Py_PrintSpecializationStats(int to_file)
{
if (_py_stats == NULL) {
return;
}
FILE *out = stderr;
if (to_file) {
/* Write to a file instead of stderr. */
@ -238,7 +235,7 @@ _Py_PrintSpecializationStats(int to_file)
else {
fprintf(out, "Specialization stats:\n");
}
print_stats(out, _py_stats);
print_stats(out, &_py_stats_struct);
if (out != stderr) {
fclose(out);
}