|
22 | 22 | #include "pycore_runtime.h" // _PyRuntime |
23 | 23 | #include "pycore_runtime_init.h" // _PyRuntimeState_INIT |
24 | 24 | #include "pycore_stackref.h" // Py_STACKREF_DEBUG |
| 25 | +#include "pycore_stats.h" // FT_STAT_WORLD_STOP_INC() |
25 | 26 | #include "pycore_time.h" // _PyTime_Init() |
26 | 27 | #include "pycore_uniqueid.h" // _PyObject_FinalizePerThreadRefcounts() |
27 | | -#include "pycore_stats.h" // FT_STAT_WORLD_STOP_INC() |
28 | | - |
29 | 28 |
|
30 | 29 |
|
31 | 30 | /* -------------------------------------------------------------------------- |
@@ -480,6 +479,12 @@ alloc_interpreter(void) |
480 | 479 | static void |
481 | 480 | free_interpreter(PyInterpreterState *interp) |
482 | 481 | { |
| 482 | +#ifdef Py_STATS |
| 483 | + if (interp->pystats_struct) { |
| 484 | + PyMem_RawFree(interp->pystats_struct); |
| 485 | + interp->pystats_struct = NULL; |
| 486 | + } |
| 487 | +#endif |
483 | 488 | // The main interpreter is statically allocated so |
484 | 489 | // should not be freed. |
485 | 490 | if (interp != &_PyRuntime._main_interpreter) { |
@@ -1532,7 +1537,7 @@ new_threadstate(PyInterpreterState *interp, int whence) |
1532 | 1537 | #endif |
1533 | 1538 | #ifdef Py_STATS |
1534 | 1539 | // The PyStats structure is quite large and is allocated separated from tstate. |
1535 | | - if (!_PyStats_ThreadInit(tstate)) { |
| 1540 | + if (!_PyStats_ThreadInit(interp, tstate)) { |
1536 | 1541 | free_threadstate(tstate); |
1537 | 1542 | return NULL; |
1538 | 1543 | } |
@@ -2017,9 +2022,6 @@ tstate_activate(PyThreadState *tstate) |
2017 | 2022 | if (!tstate->_status.bound_gilstate) { |
2018 | 2023 | bind_gilstate_tstate(tstate); |
2019 | 2024 | } |
2020 | | -#ifdef Py_STATS |
2021 | | - _PyStats_Attach((_PyThreadStateImpl *)tstate); |
2022 | | -#endif |
2023 | 2025 |
|
2024 | 2026 | tstate->_status.active = 1; |
2025 | 2027 | } |
@@ -2139,6 +2141,10 @@ _PyThreadState_Attach(PyThreadState *tstate) |
2139 | 2141 | _PyCriticalSection_Resume(tstate); |
2140 | 2142 | } |
2141 | 2143 |
|
| 2144 | +#ifdef Py_STATS |
| 2145 | + _PyStats_Attach((_PyThreadStateImpl *)tstate); |
| 2146 | +#endif |
| 2147 | + |
2142 | 2148 | #if defined(Py_DEBUG) |
2143 | 2149 | errno = err; |
2144 | 2150 | #endif |
|
0 commit comments