mirror of
https://github.com/python/cpython.git
synced 2025-07-31 07:04:42 +00:00
GH-93841: Allow stats to be turned on and off, cleared and dumped at runtime. (GH-93843)
This commit is contained in:
parent
c7a79bb036
commit
6f8875eba3
7 changed files with 212 additions and 22 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue