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: enabling cProfile to profile code given as an argument "à la" timeit
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: danielnoord, jul2, matrixise, vstinner
Priority: normal Keywords:

Created on 2022-01-24 21:25 by jul2, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 30859 jul2, 2022-01-24 21:25
Messages (2)
msg411517 - (view) Author: julien tayon (jul2) Date: 2022-01-24 21:25
well, you want to use
python3 -mcProfile -othis.prof 'oneliner in python to test something'

And weirdly enough this normally expected behaviour does not work.

It's because last argument is expected to be the path of the script name to profile.

But, it can be fixed easily with no downside

Since it is an expected behaviour and is minimal changing anything in documentation or news seems to superfluous

An exemple of « this is a standard de fait » is the fact that the awesome module of vstinner timeit does this already.


https://github.com/python/cpython/pull/30859
msg415328 - (view) Author: Daniël van Noord (danielnoord) * Date: 2022-03-16 08:31
There were some comments on the (now closed) PR associated to this report.

One was about requiring a new flag to tell cProfile to consider the code in question code instead of a file path. `-c` was proposed, I presume abbreviating `--code`. Is this indeed the way to go? Allow `cProfile` to profile code directly by supplying the `-c` or `--code` argument, which indicates that the last argument should be considered code instead of a file path?
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90665
2022-03-16 08:31:29danielnoordsetnosy: + danielnoord
messages: + msg415328
2022-01-24 21:29:22jul2setnosy: + matrixise
2022-01-24 21:25:45jul2create