You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Count the number of function calls executed.
When this symbol is defined, the ceval mainloop and
helper functions count the number of function calls
made. It keeps detailed statistics about what kind of
object was called and whether the call hit any of the
special fast paths in the code.
Statistics can later be collected by sys.callstats().
-DCALL_PROFILE: Count the number of function calls executed.
When this symbol is defined, the ceval mainloop and helper functions
count the number of function calls made. It keeps detailed statistics
about what kind of object was called and whether the call hit any of
the special fast paths in the code.
When we take the fast_function() path, which seems to be taken for
most function calls, and there is minimal frame setup to do, avoid
call PyEval_EvalCodeEx(). The eval code ex function does a lot of
work to handle keywords args and star args, free variables,
generators, etc. The inlined version simply allocates the frame and
copies the arguments values into the frame.
The optimization gets a little help from compile.c which adds a
CO_NOFREE flag to code objects that don't have free variables or cell
variables. This change allows fast_function() to get into the fast
path with fewer tests.
I measure a couple of percent speedup in pystone with this change, but
there's surely more that can be done.
The changeset adds an optimization using CO_NOFREE and the CALL_PROFILE feature.
My problem is that with my work on FASTCALL, it became harder to track where the functions are called in practice. It maybe out of the Python/ceval.c file. I'm not sure that statistics are still computed correctly after my FASTCALL changes, and I don't know how to check it.
Python has already sys.setprofile(), cProfile and profile modules. There is also sys.settrace(). Do we still need CALL_PROFILE?
Attached patch removes the feature:
Calling the the untested and undocumented sys.callstats() function now emits a DeprecationWarning warning
Remove the PyEval_GetCallStats() function and its documentation
PyEval_GetCallStats() seems to be part of the stable API, but I don't expect that anyone uses it outside the CPython source code since it requires to rebuild CPython with a special build flag (-D CALL_PROFILE).
Raymond Hettinger is also ok to remove it:
"This seems reasonable to me. I've never used or needed this special build; StackOverflow has no mention of it; and a Google search comes up nearly empty. That said, it might be worthwhile to check with Jeremy to get his thoughts before removing his code." https://mail.python.org/pipermail/python-dev/2016-November/146864.html