Name
run
Synopsis
run(code,filename=None)
code is a string such as you could use
with statement exec, normally a call to the main
function of the program you’re profiling.
filename is the path of a file that
run creates or rewrites with profile data. Usually
you call run a few times, specifying different
filenames, and possibly different arguments to your
program’s main function, in order to exercise
various program parts proportionately. Then, you use module
pstats to display collated results.
You may call run without a
filename to obtain a summary report,
similar to the one module pstats could give you,
directly on standard output. However, this approach gives no control
at all over output format, nor does it offer any way to consolidate
several runs into one report. In practice, you rarely use this
feature: collecting profile data into files is generally preferable.
Module profile also supplies class
Profile, mentioned in the next section. By
instantiating Profile directly, you can access
advanced functionality, such as the ability to run a command in
specified local and global dictionaries. I do not cover such advanced
functionality of class profile.Profile further in
this book.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access