diff options
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index c9cf35f..948fb32 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -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; @@ -210,8 +211,17 @@ print_stats(FILE *out, PyStats *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 |