Message285183
Using the pstats class to print off profiler results is helpful when you want to filter, order, and limit the number of returned lines. I'd rather see the most commonly-used subset of pstats functionality included in the profiler's print_stats implementation directly.
# The current way
pstats.Stats(profiler).strip_dirs().sort_stats('cumulative').reverse_order().print_stats(10)
# Proposed way
profiler.print_stats(strip_dirs=False, sort='cumulative', reverse=True, limit=10)
Currently only the `sort` kwarg is available. To me this implies that some level of control was originally intended to be available in the print_stats method anyway. I also feel like the proposed API is more readable and explicit.
Note that for complex situations you'd still need to use the pstats class directly, eg. substituting a different stream implementation or filtering/sorting by multiple values.
This would be a backwards-compatible patch and would be implemented something like this:
def print_stats(self, sort=-1, limit=None, strip_dirs=True, reverse=True):
import pstats
stats = pstats.Stats(self)
if strip_dirs:
stats = stats.strip_dirs()
stats = stats.sort_stats(sort)
if reverse:
stats = stats.reverse_order()
stats.print_stats(limit) |
|
Date |
User |
Action |
Args |
2017-01-11 03:00:31 | Thane Brimhall | set | recipients:
+ Thane Brimhall |
2017-01-11 03:00:31 | Thane Brimhall | set | messageid: <1484103631.29.0.405631580429.issue29238@psf.upfronthosting.co.za> |
2017-01-11 03:00:31 | Thane Brimhall | link | issue29238 messages |
2017-01-11 03:00:30 | Thane Brimhall | create | |
|