mirror of
https://github.com/python/cpython.git
synced 2025-10-14 10:53:40 +00:00
bpo-44725 : expose specialization stats in python (GH-27192)
This commit is contained in:
parent
6741794dd4
commit
ddd1c418c0
7 changed files with 158 additions and 1 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue