classification
Title: 'cum' not a valid sort key for pstats.Stats.sort_stats
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: berker.peksag, docs@python, jbmilam, python-dev, ramiro
Priority: normal Keywords: patch

Created on 2015-05-09 15:19 by ramiro, last changed 2015-06-05 11:50 by berker.peksag. This issue is now closed.

Files
File name Uploaded Description Edit
profile_example_fix.patch jbmilam, 2015-06-04 21:42 review
Messages (4)
msg242812 - (view) Author: Ramiro (ramiro) Date: 2015-05-09 15:19
On the documentation page "The Python Profilers" https://docs.python.org/3.4/library/profile.html#instant-user-s-manual the following example is given:

p.sort_stats('time', 'cum').print_stats(.5, 'init')

This raises a KeyError, because 'cum' is not available as a sort key to pstats.Stats.sort_stats. As per the documentation of this method (https://docs.python.org/3.4/library/profile.html#the-stats-class) you can either use 'cumulative' or 'cumtime', which both work as expected.

Since 'cumulative' is used a few examples earlier I suggest to use that for consistency.

Tested with the following Python version:

Python 3.4.3 on Ubuntu 15.04
msg244844 - (view) Author: Brandon Milam (jbmilam) * Date: 2015-06-04 21:42
They are correct. 'cum' is not one of the available keywords and so here is the fix changing it to say 'cumulative' for consistency as ramiro suggested.
msg244860 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-06-05 11:48
New changeset bfc043eab54e by Berker Peksag in branch '3.4':
Issue #24148: Fix incorrect Stats.sort_stats() example.
https://hg.python.org/cpython/rev/bfc043eab54e

New changeset ffb7019d70cf by Berker Peksag in branch '3.5':
Issue #24148: Fix incorrect Stats.sort_stats() example.
https://hg.python.org/cpython/rev/ffb7019d70cf

New changeset 123419b216e0 by Berker Peksag in branch 'default':
Issue #24148: Fix incorrect Stats.sort_stats() example.
https://hg.python.org/cpython/rev/123419b216e0
msg244861 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-06-05 11:50
Fixed! Thanks for the report, ramiro and thanks for the patch, Brandon.
History
Date User Action Args
2015-06-05 11:50:49berker.peksagsetstatus: open -> closed

versions: + Python 3.5, Python 3.6
nosy: + berker.peksag

messages: + msg244861
resolution: fixed
stage: resolved
2015-06-05 11:48:59python-devsetnosy: + python-dev
messages: + msg244860
2015-06-04 21:42:05jbmilamsetfiles: + profile_example_fix.patch

nosy: + jbmilam
messages: + msg244844

keywords: + patch
2015-05-09 15:19:17ramirocreate