]> granicus.if.org Git - python/commitdiff
Correct Profile class usage example. Addresses issue #18033 .
authorSenthil Kumaran <senthil@uthcode.com>
Sun, 8 Sep 2013 00:50:35 +0000 (17:50 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Sun, 8 Sep 2013 00:50:35 +0000 (17:50 -0700)
Patch contributed by Olivier Hervieu and Dmi Baranov.

Doc/library/profile.rst

index e2757f6632a6f058555fb50e51893c6b707386d1..00abef2873efac64d833ebc82555e08cec9b0dd9 100644 (file)
@@ -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()