Skip to content
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

Create enum for pstats sorting options #73423

Closed
ThaneBrimhall mannequin opened this issue Jan 11, 2017 · 13 comments
Closed

Create enum for pstats sorting options #73423

ThaneBrimhall mannequin opened this issue Jan 11, 2017 · 13 comments
Labels
3.7 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ThaneBrimhall
Copy link
Mannequin

ThaneBrimhall mannequin commented Jan 11, 2017

BPO 29237
Nosy @rhettinger, @ethanfurman, @mwidjaja, @Mariatta, @rtnpro, @mlouielu, @csabella
PRs
  • bpo-29237: Create enum for pstats sorting options #5103
  • bpo-29237: Add missing NEWS entry #5336
  • 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:

    assignee = None
    closed_at = <Date 2018-02-26.01:23:43.691>
    created_at = <Date 2017-01-11.01:31:34.126>
    labels = ['3.7', 'type-feature', 'library']
    title = 'Create enum for pstats sorting options'
    updated_at = <Date 2018-02-26.01:23:43.675>
    user = 'https://bugs.python.org/ThaneBrimhall'

    bugs.python.org fields:

    activity = <Date 2018-02-26.01:23:43.675>
    actor = 'ethan.furman'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-02-26.01:23:43.691>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2017-01-11.01:31:34.126>
    creator = 'Thane Brimhall'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29237
    keywords = ['patch']
    message_count = 13.0
    messages = ['285178', '285179', '286390', '288087', '288135', '288285', '292146', '295458', '295459', '309268', '310735', '312865', '312870']
    nosy_count = 8.0
    nosy_names = ['rhettinger', 'ethan.furman', 'mawidjaj', 'Mariatta', 'Thane Brimhall', 'rtnpro', 'louielu', 'cheryl.sabella']
    pr_nums = ['5103', '5336']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue29237'
    versions = ['Python 3.7']

    @ThaneBrimhall
    Copy link
    Mannequin Author

    ThaneBrimhall mannequin commented Jan 11, 2017

    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
    1. 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'

    @ThaneBrimhall ThaneBrimhall mannequin added 3.7 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jan 11, 2017
    @ethanfurman
    Copy link
    Member

    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.

    @rhettinger
    Copy link
    Contributor

    Mariatta, would you like to prepare a patch for this. Ethan and I will review it.

    @rtnpro
    Copy link
    Mannequin

    rtnpro mannequin commented Feb 18, 2017

    I am taking up to create a patch/pull request for this to get it reviewed.

    @Mariatta
    Copy link
    Sponsor Member

    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.

    @rtnpro
    Copy link
    Mannequin

    rtnpro mannequin commented Feb 21, 2017

    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 :)

    @mlouielu
    Copy link
    Mannequin

    mlouielu mannequin commented Apr 23, 2017

    Mariatta, is there any movement on this issue?

    Thanks!

    @ethanfurman
    Copy link
    Member

    Marriatta, perhaps it is time to let Ratnadeep work on this issue?

    @Mariatta
    Copy link
    Sponsor Member

    Mariatta commented Jun 8, 2017

    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.

    @Mariatta Mariatta removed their assignment Jun 8, 2017
    @mwidjaja
    Copy link
    Mannequin

    mwidjaja mannequin commented Dec 31, 2017

    I'd like to try to work on this one

    @ethanfurman
    Copy link
    Member

    New changeset 863b1e4 by Ethan Furman (mwidjaja) in branch 'master':
    bpo-29237: Create enum for pstats sorting options (GH-5103)
    863b1e4

    @csabella
    Copy link
    Contributor

    Can this one be closed since it was an enhancement and doesn't need to be backported?

    @ethanfurman
    Copy link
    Member

    Thanks for catching that!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants