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: Make Profile.print_stats support sorting by mutiple values
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: JelleZijlstra, SilentGhost, danielnoord, georg.brandl, wdv4758h
Priority: normal Keywords: patch

Created on 2015-12-05 08:25 by wdv4758h, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
print_stats.patch wdv4758h, 2015-12-05 08:25 enhance print_stats review
print_stats_with_test.patch wdv4758h, 2015-12-05 13:24 refactor patch & add tests review
Messages (5)
msg255935 - (view) Author: Chiu-Hsiang Hsu (wdv4758h) * Date: 2015-12-05 08:25
Currently, the result of profile.run can not easily sort by mutiple values with "sort" keyword argument. Following code will work with this patch.

>>> import cProfile
>>> cProfile.run('42**42', sort=('tottime', 'stdname'))
         3 function calls in 0.000 seconds

   Ordered by: internal time, standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 {built-in method builtins.exec}
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

>>> import cProfile
>>> cProfile.run('42**42', sort=('tottime', 'stdname'))
         3 function calls in 0.000 seconds

   Ordered by: internal time, standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 {built-in method builtins.exec}
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}


>>> import profile
>>> profile.run('42**42', sort=('tottime', 'stdname'))
         4 function calls in 0.000 seconds

   Ordered by: internal time, standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 profile:0(42**42)
        1    0.000    0.000    0.000    0.000 :0(exec)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        0    0.000             0.000          profile:0(profiler)
msg255940 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-12-05 09:23
It would be good to add test for this.
msg255952 - (view) Author: Chiu-Hsiang Hsu (wdv4758h) * Date: 2015-12-05 13:24
Attached refactored patch with tests.
msg267273 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2016-06-04 16:58
Patch looks good to me
msg415329 - (view) Author: Daniël van Noord (danielnoord) * Date: 2022-03-16 08:34
@wdv4758h, do you think you will be able to resubmit the patch to Github? This would probably still be a useful addition and some review has already been done.

If not, I could pick up the patch and re-submit, but I don't want to take credit for your work unnecessarily.
History
Date User Action Args
2022-04-11 14:58:24adminsetgithub: 69990
2022-03-16 08:34:17danielnoordsetnosy: + danielnoord
messages: + msg415329
2016-06-04 16:58:23JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg267273
2015-12-05 13:24:31wdv4758hsetfiles: + print_stats_with_test.patch

messages: + msg255952
2015-12-05 09:24:19SilentGhostsetstage: test needed
2015-12-05 09:23:49SilentGhostsetnosy: + georg.brandl
2015-12-05 09:23:38SilentGhostsetnosy: + SilentGhost
messages: + msg255940
2015-12-05 08:25:52wdv4758hcreate