Skip to content
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

bpo-32512: Add -m option to profile for profiling modules #5132

Merged
merged 2 commits into from Nov 5, 2018

Conversation

mariocj89
Copy link
Contributor

@mariocj89 mariocj89 commented Jan 7, 2018

Port of #4297 to the pure python profile module.

The patch adds a new option -m that allows the profile CLI to run modules as scripts.

https://bugs.python.org/issue32512

@mariocj89 mariocj89 changed the title bpo-32512: Add -m option to profile for profiling modules bpo-32512: Add -m option to profile for profiling modules (WIP, adding tests) Jan 7, 2018
@mariocj89 mariocj89 changed the title bpo-32512: Add -m option to profile for profiling modules (WIP, adding tests) bpo-32512: Add -m option to profile for profiling modules Jan 7, 2018
Lib/profile.py Outdated
@@ -553,11 +553,13 @@ def main():
import os
from optparse import OptionParser

usage = "profile.py [-o output_file_path] [-s sort] scriptfile [arg] ..."
usage = "profile.py [-o output_file_path] [-s sort] [-m module |escriptfile] [arg] ..."
Copy link
Member

@matrixise matrixise May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you upgrade the documentation (Doc/library/profile.rst) and add a ..versionadded:: 3.8 ?

Copy link
Contributor Author

@mariocj89 mariocj89 May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! addressed 😄

Doc/library/profile.rst Show resolved Hide resolved
@mariocj89
Copy link
Contributor Author

mariocj89 commented May 15, 2018

Updated, let me know how it looks for you @matrixise. If the wording and structure looks ok we can see if any core developer is interested in this.

It is a "nice to have change" as it is mainly useful for people not having cProfile available but not really urgent.

Copy link
Member

@matrixise matrixise left a comment

I am fine with this PR. Thank you so much for your job. Have a nice day.

@mariocj89
Copy link
Contributor Author

mariocj89 commented May 15, 2018

Thanks for your review @matrixise ;)

@matrixise
Copy link
Member

matrixise commented May 15, 2018

no problem, but I am not a core dev, you have to wait and see with a core review, maybe there will an other point to fix, but in this case, it's good adventure ;-) thanks again ;-)

@mariocj89
Copy link
Contributor Author

mariocj89 commented Jul 28, 2018

As a note for the reviewer, this follows the same implementation as the one in cProfile

This, therefore, includes by default the functions of using runpy. It is probably cleaner and better to get directly the code and pass it to profile to get those removed (as runpy <script> does) but I've left it with the same implementation as cProfile for consistency.

The change (if desired) to move to use the source directly can be done either in this PR or in a different one, but that will require either hitting the private API in runpy, see #5474 as an example.

@mariocj89
Copy link
Contributor Author

mariocj89 commented Oct 27, 2018

@ncoghlan we stalled this PR based on one where we were going to refactor part of the logic to extract the module details in runpy, but we agreed here that it probably makes no sense to do so.

Do you want to proceed with this PR as is? Let me know if you think it is not worth or any change should be done. I am happy to close it otherwise if you want. (really, no hard feelings I promise 😊)

I am also happy to have a look to the issue that this implementation brings as commented in [here]#5132 (comment)) in a latter PR. And "fix" both cProfile and profile if desired. But I'd prefer to leave that conversation for a different issue + PR.

Same goes about #5134

@ncoghlan
Copy link
Contributor

ncoghlan commented Oct 31, 2018

@mariocj89 Yeah, let's go ahead with updating the existing PRs and at least offering the functionality, even if it interacts a bit differently with the interpreter level "-i" switch when compared to the directly executing a path.

mariocj89 added 2 commits Nov 1, 2018
The new option in the CLI of the profile module allow to profile
executable modules. This change follows the same implementation as the
one already present in `cProfile`.
As the argument is now present on both modules, move the tests to the
common test case to be run with profile as well.
@mariocj89
Copy link
Contributor Author

mariocj89 commented Nov 2, 2018

@ncoghlan, updated per previous comment, let me know of any change that needs to be done here :)

Thanks!

I've also updated #5134 😄

Copy link
Contributor

@ncoghlan ncoghlan left a comment

LGTM, thanks!

@ncoghlan ncoghlan merged commit ad1a25f into python:master Nov 5, 2018
@bedevere-bot
Copy link

bedevere-bot commented Nov 5, 2018

@ncoghlan: Please replace # with GH- in the commit message next time. Thanks!

@mariocj89 mariocj89 deleted the profile_module branch Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants