From cb7e5fa935183ddf9aa59bca91c82a69fa689b35 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Sat, 7 Sep 2013 17:50:35 -0700 Subject: Correct Profile class usage example. Addresses issue #18033 . Patch contributed by Olivier Hervieu and Dmi Baranov. --- Doc/library/profile.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index e2757f6..00abef2 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() -- cgit v0.12