diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-07-29 16:26:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 16:26:53 (GMT) |
commit | ddd1c418c05da0de978c75dfb3e4a5b8d27e1d9f (patch) | |
tree | e43ba73ffc54a4e7a5d96c808592e43d40c45a5b /Lib/test/test__opcode.py | |
parent | 6741794dd420c6b9775a188690dbf265037cd69f (diff) | |
download | cpython-ddd1c418c05da0de978c75dfb3e4a5b8d27e1d9f.zip cpython-ddd1c418c05da0de978c75dfb3e4a5b8d27e1d9f.tar.gz cpython-ddd1c418c05da0de978c75dfb3e4a5b8d27e1d9f.tar.bz2 |
bpo-44725 : expose specialization stats in python (GH-27192)
Diffstat (limited to 'Lib/test/test__opcode.py')
-rw-r--r-- | Lib/test/test__opcode.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test__opcode.py b/Lib/test/test__opcode.py index 3bb64a7..928198a 100644 --- a/Lib/test/test__opcode.py +++ b/Lib/test/test__opcode.py @@ -1,6 +1,7 @@ import dis from test.support.import_helper import import_module import unittest +import opcode _opcode = import_module("_opcode") from _opcode import stack_effect @@ -64,5 +65,31 @@ class OpcodeTests(unittest.TestCase): self.assertEqual(nojump, common) +class SpecializationStatsTests(unittest.TestCase): + def test_specialization_stats(self): + stat_names = opcode._specialization_stats + + specialized_opcodes = [ + op[:-len("_ADAPTIVE")].lower() for + op in opcode._specialized_instructions + if op.endswith("_ADAPTIVE")] + self.assertIn('load_attr', specialized_opcodes) + self.assertIn('binary_subscr', specialized_opcodes) + + stats = _opcode.get_specialization_stats() + if stats is not None: + self.assertIsInstance(stats, dict) + self.assertCountEqual(stats.keys(), specialized_opcodes) + self.assertCountEqual( + stats['load_attr'].keys(), + 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(v, int) + + if __name__ == "__main__": unittest.main() |