summaryrefslogtreecommitdiff
path: root/Include/internal/pycore_code.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-21 15:40:54 +0100
committerGitHub <noreply@github.com>2022-06-21 15:40:54 +0100
commit6f8875eba38b08c802905635759b5f905e3a415c (patch)
tree6ee112e6f2e61ccbde70f9bf4bc5f103c0e12508 /Include/internal/pycore_code.h
parentc7a79bb036b42f96b7379b95efa643ee27df2168 (diff)
downloadcpython-git-6f8875eba38b08c802905635759b5f905e3a415c.tar.gz
GH-93841: Allow stats to be turned on and off, cleared and dumped at runtime. (GH-93843)
Diffstat (limited to 'Include/internal/pycore_code.h')
-rw-r--r--Include/internal/pycore_code.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index 71dd3b3b42..c975f1cb74 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -259,16 +259,16 @@ extern int _PyStaticCode_InternStrings(PyCodeObject *co);
#ifdef Py_STATS
-#define STAT_INC(opname, name) _py_stats.opcode_stats[(opname)].specialization.name++
-#define STAT_DEC(opname, name) _py_stats.opcode_stats[(opname)].specialization.name--
-#define OPCODE_EXE_INC(opname) _py_stats.opcode_stats[(opname)].execution_count++
-#define CALL_STAT_INC(name) _py_stats.call_stats.name++
-#define OBJECT_STAT_INC(name) _py_stats.object_stats.name++
+#define STAT_INC(opname, name) do { if (_py_stats) _py_stats->opcode_stats[opname].specialization.name++; } while (0)
+#define STAT_DEC(opname, name) do { if (_py_stats) _py_stats->opcode_stats[opname].specialization.name--; } while (0)
+#define OPCODE_EXE_INC(opname) do { if (_py_stats) _py_stats->opcode_stats[opname].execution_count++; } while (0)
+#define CALL_STAT_INC(name) do { if (_py_stats) _py_stats->call_stats.name++; } while (0)
+#define OBJECT_STAT_INC(name) do { if (_py_stats) _py_stats->object_stats.name++; } while (0)
#define OBJECT_STAT_INC_COND(name, cond) \
- do { if (cond) _py_stats.object_stats.name++; } while (0)
-#define EVAL_CALL_STAT_INC(name) _py_stats.call_stats.eval_calls[(name)]++
+ do { if (_py_stats && cond) _py_stats->object_stats.name++; } while (0)
+#define EVAL_CALL_STAT_INC(name) do { if (_py_stats) _py_stats->call_stats.eval_calls[name]++; } while (0)
#define EVAL_CALL_STAT_INC_IF_FUNCTION(name, callable) \
- do { if (PyFunction_Check(callable)) _py_stats.call_stats.eval_calls[(name)]++; } while (0)
+ do { if (_py_stats && PyFunction_Check(callable)) _py_stats->call_stats.eval_calls[name]++; } while (0)
// Used by the _opcode extension which is built as a shared library
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);