summaryrefslogtreecommitdiffstats
path: root/Include/pystats.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-21 14:40:54 (GMT)
committerGitHub <noreply@github.com>2022-06-21 14:40:54 (GMT)
commit6f8875eba38b08c802905635759b5f905e3a415c (patch)
tree6ee112e6f2e61ccbde70f9bf4bc5f103c0e12508 /Include/pystats.h
parentc7a79bb036b42f96b7379b95efa643ee27df2168 (diff)
downloadcpython-6f8875eba38b08c802905635759b5f905e3a415c.zip
cpython-6f8875eba38b08c802905635759b5f905e3a415c.tar.gz
cpython-6f8875eba38b08c802905635759b5f905e3a415c.tar.bz2
GH-93841: Allow stats to be turned on and off, cleared and dumped at runtime. (GH-93843)
Diffstat (limited to 'Include/pystats.h')
-rw-r--r--Include/pystats.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/Include/pystats.h b/Include/pystats.h
index bea471b..87e92aa 100644
--- a/Include/pystats.h
+++ b/Include/pystats.h
@@ -73,19 +73,22 @@ typedef struct _stats {
ObjectStats object_stats;
} PyStats;
-PyAPI_DATA(PyStats) _py_stats;
+PyAPI_DATA(PyStats) _py_stats_struct;
+PyAPI_DATA(PyStats *) _py_stats;
+
+extern void _Py_StatsClear(void);
extern void _Py_PrintSpecializationStats(int to_file);
#ifdef _PY_INTERPRETER
-#define _Py_INCREF_STAT_INC() _py_stats.object_stats.interpreter_increfs++
-#define _Py_DECREF_STAT_INC() _py_stats.object_stats.interpreter_decrefs++
+#define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_increfs++; } while (0)
+#define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.interpreter_decrefs++; } while (0)
#else
-#define _Py_INCREF_STAT_INC() _py_stats.object_stats.increfs++
-#define _Py_DECREF_STAT_INC() _py_stats.object_stats.decrefs++
+#define _Py_INCREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.increfs++; } while (0)
+#define _Py_DECREF_STAT_INC() do { if (_py_stats) _py_stats->object_stats.decrefs++; } while (0)
#endif