gh-131253: free-threaded build support for pystats (gh-137189)

Allow the --enable-pystats build option to be used with free-threading.  The
stats are now stored on a per-interpreter basis, rather than process global.
For free-threaded builds, the stats structure is allocated per-thread and
then periodically merged into the per-interpreter stats structure (on thread
exit or when the reporting function is called). Most of the pystats related
code has be moved into the file Python/pystats.c.
This commit is contained in:
Neil Schemenauer 2025-11-03 11:36:37 -08:00 committed by GitHub
parent cf1a2c1ee4
commit c98c5b3449
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 1269 additions and 485 deletions

View file

@ -199,7 +199,7 @@ enum _GCPhase {
};
/* If we change this, we need to change the default value in the
signature of gc.collect. */
signature of gc.collect and change the size of PyStats.gc_stats */
#define NUM_GENERATIONS 3
struct _gc_runtime_state {
@ -963,6 +963,18 @@ struct _is {
# ifdef Py_STACKREF_CLOSE_DEBUG
_Py_hashtable_t *closed_stackrefs_table;
# endif
#endif
#ifdef Py_STATS
// true if recording of pystats is on, this is used when new threads
// are created to decide if recording should be on for them
int pystats_enabled;
// allocated when (and if) stats are first enabled
PyStats *pystats_struct;
#ifdef Py_GIL_DISABLED
// held when pystats related interpreter state is being updated
PyMutex pystats_mutex;
#endif
#endif
/* the initial PyInterpreterState.threads.head */