GH-90230: Add stats to breakdown the origin of calls to PyEval_EvalFrame (GH-93284)

This commit is contained in:
Mark Shannon 2022-05-27 16:31:41 +01:00 • committed by GitHub
parent 8995177030
commit bbcf42449e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 63 additions and 11 deletions

View file

@ -109,7 +109,9 @@ _Py_CheckSlotResult(PyObject *obj, const char *slot_name, int success)
PyObject *
PyObject_CallNoArgs(PyObject *func)
{
return _PyObject_CallNoArgs(func);
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
PyThreadState *tstate = _PyThreadState_GET();
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
}
@ -322,7 +324,7 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable,
assert(!_PyErr_Occurred(tstate));
assert(PyTuple_Check(args));
assert(kwargs == NULL || PyDict_Check(kwargs));
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
vectorcallfunc vector_func = _PyVectorcall_Function(callable);
if (vector_func != NULL) {
return _PyVectorcall_Call(tstate, vector_func, callable, args, kwargs);
@ -367,6 +369,7 @@ PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
PyObject *
PyObject_CallOneArg(PyObject *func, PyObject *arg)
{
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, func);
assert(arg != NULL);
PyObject *_args[2];
PyObject **args = _args + 1; // For PY_VECTORCALL_ARGUMENTS_OFFSET
@ -389,6 +392,7 @@ _PyFunction_Vectorcall(PyObject *func, PyObject* const* stack,
assert(nargs >= 0);
PyThreadState *tstate = _PyThreadState_GET();
assert(nargs == 0 || stack != NULL);
EVAL_CALL_STAT_INC(EVAL_CALL_FUNCTION_VECTORCALL);
if (((PyCodeObject *)f->func_code)->co_flags & CO_OPTIMIZED) {
return _PyEval_Vector(tstate, f, NULL, stack, nargs, kwnames);
}
@ -520,7 +524,7 @@ _PyObject_CallFunctionVa(PyThreadState *tstate, PyObject *callable,
if (stack == NULL) {
return NULL;
}
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_API, callable);
if (nargs == 1 && PyTuple_Check(stack[0])) {
/* Special cases for backward compatibility:
- PyObject_CallFunction(func, "O", tuple) calls func(*tuple)
@ -815,6 +819,11 @@ object_vacall(PyThreadState *tstate, PyObject *base,
stack[i] = va_arg(vargs, PyObject *);
}
#ifdef Py_STATS
if (PyFunction_Check(callable)) {
EVAL_CALL_STAT_INC(EVAL_CALL_API);
}
#endif
/* Call the function */
result = _PyObject_VectorcallTstate(tstate, callable, stack, nargs, NULL);
@ -852,6 +861,7 @@ PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
args++;
nargsf--;
}
EVAL_CALL_STAT_INC_IF_FUNCTION(EVAL_CALL_METHOD, callable);
PyObject *result = _PyObject_VectorcallTstate(tstate, callable,
args, nargsf, kwnames);
Py_DECREF(callable);