Skip to content

bpo-46072: Add stats for PRECALL_FUNCTION. #31250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4447,6 +4447,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr

call_shape.total_args = oparg;
call_shape.kwnames = NULL;
#ifdef Py_STATS
extern int _PySpecialization_ClassifyCallable(PyObject *);
_py_stats.opcode_stats[PRECALL_FUNCTION].specialization.failure++;
_py_stats.opcode_stats[PRECALL_FUNCTION].specialization.failure_kinds[_PySpecialization_ClassifyCallable(call_shape.callable)]++;
#endif
DISPATCH();
}

Expand Down
32 changes: 29 additions & 3 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ print_spec_stats(FILE *out, OpcodeStats *stats)
/* Mark some opcodes as specializable for stats,
* even though we don't specialize them yet. */
fprintf(out, " opcode[%d].specializable : 1\n", FOR_ITER);
fprintf(out, " opcode[%d].specializable : 1\n", PRECALL_FUNCTION);
fprintf(out, " opcode[%d].specializable : 1\n", UNPACK_SEQUENCE);
for (int i = 0; i < 256; i++) {
if (adaptive_opcodes[i]) {
Expand Down Expand Up @@ -556,14 +557,15 @@ initial_counter_value(void) {
#define SPEC_FAIL_CALL_BAD_CALL_FLAGS 17
#define SPEC_FAIL_CALL_CLASS 18
#define SPEC_FAIL_CALL_PYTHON_CLASS 19
#define SPEC_FAIL_CALL_C_METHOD_CALL 20
#define SPEC_FAIL_CALL_METHOD_DESCRIPTOR 20
#define SPEC_FAIL_CALL_BOUND_METHOD 21
#define SPEC_FAIL_CALL_STR 22
#define SPEC_FAIL_CALL_CLASS_NO_VECTORCALL 23
#define SPEC_FAIL_CALL_CLASS_MUTABLE 24
#define SPEC_FAIL_CALL_KWNAMES 25
#define SPEC_FAIL_CALL_METHOD_WRAPPER 26
#define SPEC_FAIL_CALL_OPERATOR_WRAPPER 27
#define SPEC_FAIL_CALL_PYFUNCTION 28

/* COMPARE_OP */
#define SPEC_FAIL_COMPARE_OP_DIFFERENT_TYPES 12
Expand Down Expand Up @@ -1651,7 +1653,13 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
static int
call_fail_kind(PyObject *callable)
{
if (PyInstanceMethod_Check(callable)) {
if (PyCFunction_CheckExact(callable)) {
return SPEC_FAIL_CALL_PYCFUNCTION;
}
else if (PyFunction_Check(callable)) {
return SPEC_FAIL_CALL_PYFUNCTION;
}
else if (PyInstanceMethod_Check(callable)) {
return SPEC_FAIL_CALL_INSTANCE_METHOD;
}
else if (PyMethod_Check(callable)) {
Expand All @@ -1662,7 +1670,15 @@ call_fail_kind(PyObject *callable)
return SPEC_FAIL_CALL_CMETHOD;
}
else if (PyType_Check(callable)) {
return SPEC_FAIL_CALL_CLASS;
if (((PyTypeObject *)callable)->tp_new == PyBaseObject_Type.tp_new) {
return SPEC_FAIL_CALL_PYTHON_CLASS;
}
else {
return SPEC_FAIL_CALL_CLASS;
}
}
else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
return SPEC_FAIL_CALL_METHOD_DESCRIPTOR;
}
else if (Py_TYPE(callable) == &PyWrapperDescr_Type) {
return SPEC_FAIL_CALL_OPERATOR_WRAPPER;
Expand Down Expand Up @@ -1905,6 +1921,8 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
adaptive->counter = initial_counter_value();
}

#ifdef Py_STATS

int
_PySpecialization_ClassifyIterator(PyObject *iter)
{
Expand Down Expand Up @@ -1966,3 +1984,11 @@ _PySpecialization_ClassifySequence(PyObject *seq)
}
return SPEC_FAIL_OTHER;
}

int
_PySpecialization_ClassifyCallable(PyObject *callable)
{
return call_fail_kind(callable);
}

#endif
2 changes: 2 additions & 0 deletions Tools/scripts/summarize_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def kind_to_text(kind, defines, opname):
opname = "ATTR"
if opname.endswith("SUBSCR"):
opname = "SUBSCR"
if opname.startswith("PRECALL"):
opname = "CALL"
for name in defines[kind]:
if name.startswith(opname):
return pretty(name[len(opname)+1:])
Expand Down