Our code base has a few decorators that are used extensively.
When I create a runtime profile, a large part of the call graph looks like an hour glass; many functions call one function (the decorator), which then calls many functions. This is a less-useful profile than I’d like.
Is there any way to rectify this situation? Removing the decorator is not an option; it provides necessary functionality.
We’ve considered manually stripping the decorator from the cProfile data after the fact, but it doesn’t seem possible, because the data is summarized into caller->callee relationships, which destroys the caller->decorator->callee relationship.
Using something like the
newlibrary (ortypesin Python 2.6+), you could theoretically dynamically create a code object and then a function object based on that code object that had a built-in name that varied along with the function you were wrapping.That would allow you to manipulate things as deep as
<func>.__code__.co_name(which is normally read-only).(
functools.wrapsis still used here in order to allow for pass-through of things like docstrings, module names, etc.)