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
Unify trace and profile interfaces #54150
Comments
The trace and profile modules provide similar functionality, but have some gratuitous differences in their APIs and command line interfaces. For example, the method to trace a single call is Trace.runfunc, but almost identical Profile method is called "runcall". The CLIs provided by the two modules are vastly different: profile splits out formatting of the results into a separate module, pstats, while trace module includes many options to control the output of traced runs. This situation leeds to an unnecessary burden on users who need to learn two different ways to do very similar things. |
The runfunc/runcall difference is the easiest to address. I propose to add runcall to Trace as an alias to runfunc and deprecate runfunc. In addition, I propose to add __enter__ and __exit__ methods to both Trace and Profile so that they can be used as context managers. |
Sounds good to me. |
I've ran into a problem adding context manager functionality to Profile/Trace objects. When profile/trace function is set in __enter__ and removed in __exit__ it catches two spurious events: a return from __enter__ and a call to __exit__. This is particularly problematic with Profile which is not prepared to handle a return event that does not follow a matching call. |
I know this is an old bug (my first-time contribution), but I checked and it still applies in current versions. As suggested by @belopolsky, I added runcall to Trace and made runfunc an alias for it. I also updated the tests for trace to reflect the change to runcall over runfunc. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: