Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21101f7

Browse files
committed
Correct Profile class usage example. Addresses issue #18033.
Patch contributed by Olivier Hervieu and Dmi Baranov.
1 parent 8ef519b commit 21101f7

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Doc/library/profile.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,13 @@ functions:
247247
import cProfile, pstats, io
248248
pr = cProfile.Profile()
249249
pr.enable()
250-
... do something ...
250+
# ... do something ...
251251
pr.disable()
252252
s = io.StringIO()
253-
ps = pstats.Stats(pr, stream=s)
254-
ps.print_results()
253+
sortby = 'cumulative'
254+
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
255+
ps.print_stats()
256+
print(s.getvalue())
255257

256258
.. method:: enable()
257259

0 commit comments

Comments
 (0)