Skip to content

Commit

Permalink
Classify specialization failures. Provides more useful stats, with lo…
Browse files Browse the repository at this point in the history
…wer overhead. (pythonGH-27701)
  • Loading branch information
markshannon authored Aug 10, 2021
1 parent c7ea1e3 commit 9816777
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 100 deletions.
4 changes: 3 additions & 1 deletion Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT
#define SPECIALIZATION_STATS_DETAILED 0
#define SPECIALIZATION_STATS_TO_FILE 0

#define SPECIALIZATION_FAILURE_KINDS 20

#if SPECIALIZATION_STATS

typedef struct _stats {
Expand All @@ -316,7 +318,7 @@ typedef struct _stats {
uint64_t deopt;
uint64_t unquickened;
#if SPECIALIZATION_STATS_DETAILED
PyObject *miss_types;
uint64_t specialization_failure_kinds[SPECIALIZATION_FAILURE_KINDS];
#endif
} SpecializationStats;

Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test__opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ def test_specialization_stats(self):
stat_names + ['fails'])
for sn in stat_names:
self.assertIsInstance(stats['load_attr'][sn], int)
self.assertIsInstance(stats['load_attr']['fails'], dict)
for k,v in stats['load_attr']['fails'].items():
self.assertIsInstance(k, tuple)
self.assertIsInstance(stats['load_attr']['specialization_failure_kinds'], tuple)
for v in stats['load_attr']['specialization_failure_kinds']:
self.assertIsInstance(v, int)


Expand Down
Loading

0 comments on commit 9816777

Please sign in to comment.