mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Correct Profile class usage example. Addresses issue #18033 .
Patch contributed by Olivier Hervieu and Dmi Baranov.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user