Issue29237
Created on 2017-01-11 01:31 by Thane Brimhall, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 5103 | merged | mawidjaj, 2018-01-05 03:52 | |
| PR 5336 | closed | ethan.furman, 2018-01-26 05:09 | |
| Messages (13) | |||
|---|---|---|---|
| msg285178 - (view) | Author: Thane Brimhall (Thane Brimhall) * | Date: 2017-01-11 01:31 | |
When using the cProfile and pstats modules, I often forget which string keys are available for sorting. It would be nice to add an enum for these so a user could have their linter and IDE check that value pre-runtime.
By subclassing both `str` and `Enum` this proposal would be backwards-compatible with all existing code.
The patch for such a change would be trivial:
1. Add a new Sort class to the pstats module:
class Sort(str, enum.Enum):
calls = 'calls' # call count
cumulative = 'cumulative' # cumulative time
cumtime = 'cumtime' # cumulative time
file = 'file' # file name
filename = 'filename' # file name
module = 'module' # file name
ncalls = 'ncalls' # call count
pcalls = 'pcalls' # primitive call count
line = 'line' # line number
name = 'name' # function name
nfl = 'nfl' # name/file/line
stdname = 'stdname' # standard name
time = 'time' # internal time
tottime = 'tottime' # internal time
2. Change the print_stats method signature on the profiler base and subclasses to look like this:
def print_stats(self, sort: Sort=Sort.stdname):
Optionally, you could build the Sort enum like below to remove redundant options and increase explicitness:
class Sort(str, enum.Enum):
call_count = 'calls'
cumulative_time = 'cumulative'
filename = 'filename'
primitive_call_count = 'pcalls'
line_number = 'line'
function_name = 'name'
name_file_line = 'nfl'
standard_name = 'stdname'
internal_time = 'time'
|
|||
| msg285179 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2017-01-11 01:45 | |
To keep backwards compatibility and lesson the burden on new code, simply make the value of the duplicate names be the same:
cumulative = 'cumulative'
cumtime = 'cumulative'
This way the standard name is 'cumulative' but 'cumtime' works as well.
|
|||
| msg286390 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2017-01-27 22:45 | |
Mariatta, would you like to prepare a patch for this. Ethan and I will review it. |
|||
| msg288087 - (view) | Author: Ratnadeep Debnath (rtnpro) * | Date: 2017-02-18 19:47 | |
I am taking up to create a patch/pull request for this to get it reviewed. |
|||
| msg288135 - (view) | Author: Mariatta (Mariatta) * | Date: 2017-02-19 14:05 | |
Thank you, Ratnadeep. I've been assigned to this issue, and have made some progress on it. I'm away for a conference right now, and I plan on getting back once I'm back. Will it be possible for you to work on a different issue? Thanks. |
|||
| msg288285 - (view) | Author: Ratnadeep Debnath (rtnpro) * | Date: 2017-02-21 10:17 | |
It's good to hear that you're working on it. You can go ahead with this. Anyways, I will be around to see and learn how you fix this issue :) |
|||
| msg292146 - (view) | Author: Louie Lu (louielu) * | Date: 2017-04-23 02:41 | |
Mariatta, is there any movement on this issue? Thanks! |
|||
| msg295458 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2017-06-08 18:04 | |
Marriatta, perhaps it is time to let Ratnadeep work on this issue? |
|||
| msg295459 - (view) | Author: Mariatta (Mariatta) * | Date: 2017-06-08 18:34 | |
Thanks for checking in, Ethan. Sorry, since this was first assigned to me, I got pre-occupied with other issues and projects in the core-workflow. Ratnadeep, if you are still interested, please go ahead with this issue. I've unassigned myself. Thanks. |
|||
| msg309268 - (view) | Author: Marcel Widjaja (mawidjaj) * | Date: 2017-12-31 05:31 | |
I'd like to try to work on this one |
|||
| msg310735 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2018-01-26 04:49 | |
New changeset 863b1e4d0e95036bca4e97c1b8b2ca72c19790fb by Ethan Furman (mwidjaja) in branch 'master': bpo-29237: Create enum for pstats sorting options (GH-5103) https://github.com/python/cpython/commit/863b1e4d0e95036bca4e97c1b8b2ca72c19790fb |
|||
| msg312865 - (view) | Author: Cheryl Sabella (cheryl.sabella) * | Date: 2018-02-25 21:31 | |
Can this one be closed since it was an enhancement and doesn't need to be backported? |
|||
| msg312870 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2018-02-26 01:23 | |
Thanks for catching that! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:41 | admin | set | github: 73423 |
| 2018-02-26 01:23:43 | ethan.furman | set | status: open -> closed resolution: fixed messages: + msg312870 stage: patch review -> resolved |
| 2018-02-25 21:31:25 | cheryl.sabella | set | nosy:
+ cheryl.sabella messages: + msg312865 |
| 2018-01-26 05:09:18 | ethan.furman | set | pull_requests: + pull_request5183 |
| 2018-01-26 04:49:58 | ethan.furman | set | messages: + msg310735 |
| 2018-01-05 03:52:40 | mawidjaj | set | keywords:
+ patch stage: needs patch -> patch review pull_requests: + pull_request4972 |
| 2017-12-31 05:31:06 | mawidjaj | set | nosy:
+ mawidjaj messages: + msg309268 |
| 2017-06-08 18:34:17 | Mariatta | set | assignee: Mariatta -> messages: + msg295459 |
| 2017-06-08 18:04:48 | ethan.furman | set | messages: + msg295458 |
| 2017-04-23 02:41:40 | louielu | set | nosy:
+ louielu messages: + msg292146 |
| 2017-02-21 10:17:30 | rtnpro | set | messages: + msg288285 |
| 2017-02-19 14:05:23 | Mariatta | set | messages: + msg288135 |
| 2017-02-18 19:47:02 | rtnpro | set | nosy:
+ rtnpro messages: + msg288087 |
| 2017-01-27 22:45:29 | rhettinger | set | assignee: Mariatta messages:
+ msg286390 |
| 2017-01-11 01:45:23 | ethan.furman | set | nosy:
+ ethan.furman messages:
+ msg285179 |
| 2017-01-11 01:31:34 | Thane Brimhall | create | |