homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cProfile command-line should accept "-m module_name" as an alternative to script path
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: CuriousLearner, amaury.forgeotdarc, berker.peksag, gennad, georg.brandl, ncoghlan, oquanox, pitrou, rock
Priority: normal Keywords: easy, patch

Created on 2014年06月24日 20:06 by pitrou, last changed 2022年04月11日 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cProfile-add-new-option-module.patch rock, 2014年06月24日 21:30 patch review
21862.patch gennad, 2014年07月25日 22:08 review
cProfile_module_option.patch oquanox, 2015年01月17日 20:00 patch review
cProfile_module_option_2.patch oquanox, 2015年01月27日 23:21 patch review
Pull Requests
URL Status Linked Edit
PR 4297 merged CuriousLearner, 2017年11月06日 19:42
Messages (20)
msg221488 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014年06月24日 20:06
As the title says. You should be able to type:
$ python -m cProfile -m my.module.name
to profile execution of my.module.name.
msg221502 - (view) Author: Rock Lee (rock) Date: 2014年06月24日 21:30
I tweaked the Lib/cProfile.py a little bit to get the feature done, please review the patch attached.
msg221546 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014年06月25日 13:13
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").
msg224008 - (view) Author: Gennadiy Zlobin (gennad) * Date: 2014年07月25日 22:08
I added runpy import mechanism
msg232932 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2014年12月19日 14:07
The patch does not seem to allow parameters after the -m option.
I'm sure this restriction can be lifted.
msg234195 - (view) Author: Mayank Tripathi (oquanox) * Date: 2015年01月17日 20:00
Now allows parameters after the -m option.
msg234560 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2015年01月23日 15:44
This change will cause the module to be imported twice:
 progname = runpy.run_module(args[0])['__file__']
... and then the runctx() call.
What about something like:
 code = "runpy.run_module(modname, run_name='__main__')"
 globs = { 'runpy': runpy, 'modname': args[0] }
msg234614 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2015年01月24日 13:22
I haven't looked into the details of how cProfile handles command line arguments, but potentially relevant is issue #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.
msg234863 - (view) Author: Mayank Tripathi (oquanox) * Date: 2015年01月27日 23:21
Updated the patch and added docs and tests.
msg238195 - (view) Author: Mayank Tripathi (oquanox) * Date: 2015年03月16日 11:41
Could someone please review the patch. Thanks.
msg305666 - (view) Author: Sanyam Khurana (CuriousLearner) * (Python triager) Date: 2017年11月06日 18:13
Hey, seems like this bug is not updated for a while. Can I work on this?
msg305667 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017年11月06日 18:17
Sanyam, you definitely can. Step #1 would probably be to port the patch to git master and turn it into a GitHub PR.
msg305668 - (view) Author: Sanyam Khurana (CuriousLearner) * (Python triager) Date: 2017年11月06日 18:22
Thanks for the heads up! I'll do that ;)
msg305714 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017年11月07日 07:48
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.
msg305720 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017年11月07日 08:29
Le 07/11/2017 à 08:48, Nick Coghlan a écrit :
> 
> 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.
Thanks Nick. Can you confirm the runpy invocation in the PR is sane?
msg305741 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017年11月07日 12:07
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.
msg305742 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017年11月07日 12:08
Also, based on reviewing this, I suspect the same approach would also work for the pure Python profile module.
msg305819 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017年11月08日 10:51
New changeset 7973e279a21999f134aff92dd6d344ec4591fae9 by Antoine Pitrou (Sanyam Khurana) in branch 'master':
bpo-21862: Add -m option to cProfile for profiling modules (#4297)
https://github.com/python/cpython/commit/7973e279a21999f134aff92dd6d344ec4591fae9
msg305820 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017年11月08日 10:51
This is done. Thank you Sanyam!
msg305822 - (view) Author: Sanyam Khurana (CuriousLearner) * (Python triager) Date: 2017年11月08日 11:21
Thanks a lot Antoine and Nick :)
History
Date User Action Args
2022年04月11日 14:58:05adminsetgithub: 66061
2018年01月05日 07:34:30ncoghlanlinkissue9325 dependencies
2017年11月08日 11:21:16CuriousLearnersetmessages: + msg305822
2017年11月08日 10:51:30pitrousetstatus: open -> closed
resolution: fixed
messages: + msg305820

stage: patch review -> resolved
2017年11月08日 10:51:02pitrousetmessages: + msg305819
2017年11月07日 12:08:20ncoghlansetmessages: + msg305742
2017年11月07日 12:07:22ncoghlansetmessages: + msg305741
2017年11月07日 08:29:07pitrousetmessages: + msg305720
2017年11月07日 07:48:46ncoghlansetmessages: + msg305714
2017年11月06日 19:42:34CuriousLearnersetpull_requests: + pull_request4259
2017年11月06日 18:22:10CuriousLearnersetmessages: + msg305668
2017年11月06日 18:17:19pitrousetmessages: + msg305667
2017年11月06日 18:13:47CuriousLearnersetnosy: + CuriousLearner
messages: + msg305666
2017年11月06日 14:41:02pitrousetversions: + Python 3.7, - Python 3.5
2015年03月16日 11:41:08oquanoxsetmessages: + msg238195
2015年01月27日 23:21:11oquanoxsetfiles: + cProfile_module_option_2.patch

messages: + msg234863
2015年01月24日 13:22:28ncoghlansetmessages: + msg234614
2015年01月23日 15:44:48amaury.forgeotdarcsetmessages: + msg234560
2015年01月22日 22:21:33berker.peksagsetnosy: + berker.peksag

stage: needs patch -> patch review
2015年01月17日 20:00:29oquanoxsetfiles: + cProfile_module_option.patch
nosy: + oquanox
messages: + msg234195

2014年12月19日 14:07:54amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg232932
2014年07月25日 22:08:08gennadsetfiles: + 21862.patch
nosy: + gennad
messages: + msg224008

2014年06月25日 13:13:21pitrousetmessages: + msg221546
2014年06月24日 21:30:21rocksetfiles: + cProfile-add-new-option-module.patch

nosy: + rock
messages: + msg221502

keywords: + patch
2014年06月24日 20:06:54pitroucreate

AltStyle によって変換されたページ (->オリジナル) /