[Python-checkins] cpython (2.7): Correct Profile class usage example. Addresses issue #18033 .
senthil.kumaran
python-checkins at python.org
Sun Sep 8 02:52:46 CEST 2013
http://hg.python.org/cpython/rev/93018d47793f
changeset: 85601:93018d47793f
branch: 2.7
parent: 85592:d5c5ac33b9a1
user: Senthil Kumaran <senthil at uthcode.com>
date: Sat Sep 07 17:50:35 2013 -0700
summary:
Correct Profile class usage example. Addresses issue #18033 .
Patch contributed by Olivier Hervieu and Dmi Baranov.
files:
Doc/library/profile.rst | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst
--- a/Doc/library/profile.rst
+++ b/Doc/library/profile.rst
@@ -267,14 +267,16 @@
Directly using the :class:`Profile` class allows formatting profile results
without writing the profile data to a file::
- import cProfile, pstats, io
+ import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.enable()
- ... do something ...
+ # ... do something ...
pr.disable()
- s = io.StringIO()
- ps = pstats.Stats(pr, stream=s)
- ps.print_results()
+ s = StringIO.StringIO()
+ sortby = 'cumulative'
+ ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
+ ps.print_stats()
+ print s.getvalue()
.. method:: enable()
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list