[Python-checkins] Collect stats for UNPACK_SEQUENCE. (GH-31105)
markshannon
webhook-mailer at python.org
Thu Feb 3 13:41:00 EST 2022
https://github.com/python/cpython/commit/a0401d83720d93cd95ddf25f86874bfbee528722
commit: a0401d83720d93cd95ddf25f86874bfbee528722
branch: main
author: Mark Shannon <mark at hotpy.org>
committer: markshannon <mark at hotpy.org>
date: 2022-02-03T18:40:56Z
summary:
Collect stats for UNPACK_SEQUENCE. (GH-31105)
files:
M Python/ceval.c
M Python/specialize.c
diff --git a/Python/ceval.c b/Python/ceval.c
index 3197fe8eebb56..b4029d1081dcb 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2792,6 +2792,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
TARGET(UNPACK_SEQUENCE) {
PREDICTED(UNPACK_SEQUENCE);
PyObject *seq = POP(), *item, **items;
+#ifdef Py_STATS
+ extern int _PySpecialization_ClassifySequence(PyObject *);
+ _py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.failure++;
+ _py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.
+ failure_kinds[_PySpecialization_ClassifySequence(seq)]++;
+#endif
if (PyTuple_CheckExact(seq) &&
PyTuple_GET_SIZE(seq) == oparg) {
items = ((PyTupleObject *)seq)->ob_item;
diff --git a/Python/specialize.c b/Python/specialize.c
index 214f29751f388..4070d6a6a0be4 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -572,6 +572,10 @@ initial_counter_value(void) {
#define SPEC_FAIL_ITER_DICT_VALUES 22
#define SPEC_FAIL_ITER_ENUMERATE 23
+/* UNPACK_SEQUENCE */
+#define SPEC_FAIL_TUPLE 10
+#define SPEC_FAIL_LIST 11
+
static int
specialize_module_load_attr(
@@ -1880,7 +1884,6 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
adaptive->counter = initial_counter_value();
}
-
int
_PySpecialization_ClassifyIterator(PyObject *iter)
{
@@ -1930,3 +1933,15 @@ int
}
return SPEC_FAIL_OTHER;
}
+
+int
+_PySpecialization_ClassifySequence(PyObject *seq)
+{
+ if (PyTuple_CheckExact(seq)) {
+ return SPEC_FAIL_TUPLE;
+ }
+ if (PyList_CheckExact(seq)) {
+ return SPEC_FAIL_LIST;
+ }
+ return SPEC_FAIL_OTHER;
+}
More information about the Python-checkins
mailing list