8000 gh-115058: Add ``reset_rare_event_counters`` function in `_testintern… · python/cpython@93ac78a · GitHub
[go: up one dir, main page]

Skip to content

Commit 93ac78a

Browse files
authored
gh-115058: Add reset_rare_event_counters function in _testinternalcapi (GH-115128)
1 parent 95ebd45 commit 93ac78a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Lib/test/test_optimizer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88

99
class TestRareEventCounters(unittest.TestCase):
10+
def setUp(self):
11+
_testinternalcapi.reset_rare_event_counters()
12+
1013
def test_set_class(self):
1114
class A:
1215
pass

Modules/_testinternalcapi.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,20 @@ get_rare_event_counters(PyObject *self, PyObject *type)
16501650
);
16511651
}
16521652

1653+
static PyObject *
1654+
reset_rare_event_counters(PyObject *self, PyObject *Py_UNUSED(type))
1655+
{
1656+
PyInterpreterState *interp = PyInterpreterState_Get();
1657+
1658+
interp->rare_events.set_class = 0;
1659+
interp->rare_events.set_bases = 0;
1660+
interp->rare_events.set_eval_frame_func = 0;
1661+
interp->rare_events.builtin_dict = 0;
1662+
interp->rare_events.func_modification = 0;
1663+
1664+
return Py_None;
1665+
}
1666+
16531667

16541668
#ifdef Py_GIL_DISABLED
16551669
static PyObject *
@@ -1727,6 +1741,7 @@ static PyMethodDef module_functions[] = {
17271741
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
17281742
{"get_type_module_name", get_type_module_name, METH_O},
17291743
{"get_rare_event_counters", get_rare_event_counters, METH_NOARGS},
1744+
{"reset_rare_event_counters", reset_rare_event_counters, METH_NOARGS},
17301745
#ifdef Py_GIL_DISABLED
17311746
{"py_thread_id", get_py_thread_id, METH_NOARGS},
17321747
#endif

0 commit comments

Comments
 (0)
0