-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
cProfile command-line should accept "-m module_name" as an alternative to script path #66061
Comments
As the title says. You should be able to type: $ python -m cProfile -m my.module.name to profile execution of my.module.name. |
I tweaked the Lib/cProfile.py a little bit to get the feature done, please review the patch attached. |
That's not how -m should work. It should use the runpy facilities (see the runpy module). Otherwise it probably won't work properly with qualified module names ("-m pkg.subpkg.mod"). |
I added runpy import mechanism |
The patch does not seem to allow parameters after the -m option. |
Now allows parameters after the -m option. |
This change will cause the module to be imported twice: What about something like: |
I haven't looked into the details of how cProfile handles command line arguments, but potentially relevant is issue bpo-19982, which proposes adding a "target" parameter that lets runpy run in the context of an existing module object, rather than always creating its own. However, if this can be implemented without that, go ahead - it can always be refactored later. |
Updated the patch and added docs and tests. |
Could someone please review the patch. Thanks. |
Hey, seems like this bug is not updated for a while. Can I work on this? |
Sanyam, you definitely can. Step #1 would probably be to port the patch to git master and turn it into a GitHub PR. |
Thanks for the heads up! I'll do that ;) |
Interesting - I'd never looked at how cProfile works before, and the fact it already doesn't support the "-i" (interactive) switch makes it much simpler to handle than the pdb case. So from a runpy perspective, this approach gets a +1 from me, but I'd prefer if there was someone more familiar with the cProfile module that was willing to handle the merge. |
Le 07/11/2017 à 08:48, Nick Coghlan a écrit :
Thanks Nick. Can you confirm the runpy invocation in the PR is sane? |
I added an inline comment on the PR - I think what's there now would work fine, but I also suggested a slightly shorter and clearer (at least to me) alternative. |
Also, based on reviewing this, I suspect the same approach would also work for the pure Python profile module. |
This is done. Thank you Sanyam! |
Thanks a lot Antoine and Nick :) |
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: