Skip to content

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

Merged
ncoghlan merged 2 commits into
python:masterfrom
mariocj89:profile_module
Nov 5, 2018
Merged

bpo-32512: Add -m option to profile for profiling modules#5132
ncoghlan merged 2 commits into
python:masterfrom
mariocj89:profile_module

Conversation

@mariocj89

@mariocj89 mariocj89 commented Jan 7, 2018

Copy link
Copy Markdown
Contributor

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
Comment thread Lib/profile.py Outdated
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
Copy Markdown
Member

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! addressed 😄

Comment thread Doc/library/profile.rst
@mariocj89

Copy link
Copy Markdown
Contributor Author

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.

@matrixise matrixise left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@mariocj89

Copy link
Copy Markdown
Contributor Author

Thanks for your review @matrixise ;)

@matrixise

Copy link
Copy Markdown
Member

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

mariocj89 commented Jul 28, 2018

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor Author

@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
Copy Markdown
Contributor

@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.

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
Copy Markdown
Contributor Author

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

Thanks!

I've also updated #5134 😄

@ncoghlan ncoghlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

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

Copy link
Copy Markdown

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

@mariocj89 mariocj89 deleted the profile_module branch November 5, 2018 12:09
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.

5 participants