From: Senthil Kumaran Date: Sun, 8 Sep 2013 00:50:35 +0000 (-0700) Subject: Correct Profile class usage example. Addresses issue #18033 . X-Git-Tag: v2.7.6rc1~166 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb7e5fa935183ddf9aa59bca91c82a69fa689b35;p=thirdparty%2FPython%2Fcpython.git Correct Profile class usage example. Addresses issue #18033 . Patch contributed by Olivier Hervieu and Dmi Baranov. --- diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index e2757f6632a6..00abef2873ef 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -267,14 +267,16 @@ functions: 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()