mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +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
|
@ -33,7 +33,8 @@ uint8_t _PyOpcode_Adaptive[256] = {
|
|||
|
||||
Py_ssize_t _Py_QuickenedCount = 0;
|
||||
#ifdef Py_STATS
|
||||
PyStats _py_stats = { 0 };
|
||||
PyStats _py_stats_struct = { 0 };
|
||||
PyStats *_py_stats = &_py_stats_struct;
|
||||
|
||||
#define ADD_STAT_TO_DICT(res, field) \
|
||||
do { \
|
||||
|
@ -93,7 +94,7 @@ add_stat_dict(
|
|||
int opcode,
|
||||
const char *name) {
|
||||
|
||||
SpecializationStats *stats = &_py_stats.opcode_stats[opcode].specialization;
|
||||
SpecializationStats *stats = &_py_stats_struct.opcode_stats[opcode].specialization;
|
||||
PyObject *d = stats_to_dict(stats);
|
||||
if (d == NULL) {
|
||||
return -1;
|
||||
|
@ -209,9 +210,18 @@ print_stats(FILE *out, PyStats *stats) {
|
|||
print_object_stats(out, &stats->object_stats);
|
||||
}
|
||||
|
||||
void
|
||||
_Py_StatsClear(void)
|
||||
{
|
||||
_py_stats_struct = (PyStats) { 0 };
|
||||
}
|
||||
|
||||
void
|
||||
_Py_PrintSpecializationStats(int to_file)
|
||||
{
|
||||
if (_py_stats == NULL) {
|
||||
return;
|
||||
}
|
||||
FILE *out = stderr;
|
||||
if (to_file) {
|
||||
/* Write to a file instead of stderr. */
|
||||
|
@ -242,7 +252,7 @@ _Py_PrintSpecializationStats(int to_file)
|
|||
else {
|
||||
fprintf(out, "Specialization stats:\n");
|
||||
}
|
||||
print_stats(out, &_py_stats);
|
||||
print_stats(out, _py_stats);
|
||||
if (out != stderr) {
|
||||
fclose(out);
|
||||
}
|
||||
|
@ -250,8 +260,12 @@ _Py_PrintSpecializationStats(int to_file)
|
|||
|
||||
#ifdef Py_STATS
|
||||
|
||||
#define SPECIALIZATION_FAIL(opcode, kind) _py_stats.opcode_stats[opcode].specialization.failure_kinds[kind]++
|
||||
|
||||
#define SPECIALIZATION_FAIL(opcode, kind) \
|
||||
do { \
|
||||
if (_py_stats) { \
|
||||
_py_stats->opcode_stats[opcode].specialization.failure_kinds[kind]++; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue