On this page
pstats.Stats
Prev: pstats.SortKey | Up: pstats | Next: pstats.StatsProfile
Rel: pstats.FunctionProfile, pstats.SortKey, pstats.StatsProfile
Ref: docs.python.org — pstats.Stats
Tags: #public #python3 #stdlib #pstats
Import
import pstats
from pstats import Stats
Signature & Overview
pstats.Stats(*args, stream=None)
This class is used for creating reports from data generated by the Profile class. It is a "friend" of that class, and imports data either by direct access to members of Profile class, or by reading in a dictionary
Methods & Attributes
Stats.add(self, *arg_list)—Stats.addmethod/property.Stats.calc_callees(self)—Stats.calc_calleesmethod/property.Stats.dump_stats(self, filename)— Write the profile data to a file we know how to load back.Stats.eval_print_amount(self, sel, list, msg)—Stats.eval_print_amountmethod/property.Stats.get_print_list(self, sel_list)—Stats.get_print_listmethod/property.Stats.get_sort_arg_defs(self)— Expand all abbreviations that are unique.Stats.get_stats_profile(self)— This method returns an instance of StatsProfile, which contains a mapping of function names to instances of FunctionProfile. Each FunctionProfile instance holds information related to the function's profile such as howStats.get_top_level_stats(self)—Stats.get_top_level_statsmethod/property.Stats.init(self, arg)—Stats.initmethod/property.Stats.load_stats(self, arg)—Stats.load_statsmethod/property.Stats.print_call_heading(self, name_size, column_title)—Stats.print_call_headingmethod/property.Stats.print_call_line(self, name_size, source, call_dict, arrow='->')—Stats.print_call_linemethod/property.Stats.print_callees(self, *amount)—Stats.print_calleesmethod/property.Stats.print_callers(self, *amount)—Stats.print_callersmethod/property.Stats.print_line(self, func)—Stats.print_linemethod/property.Stats.print_stats(self, *amount)—Stats.print_statsmethod/property.Stats.print_title(self)—Stats.print_titlemethod/property.Stats.reverse_order(self)—Stats.reverse_ordermethod/property.Stats.sort_stats(self, *field)—Stats.sort_statsmethod/property.Stats.strip_dirs(self)—Stats.strip_dirsmethod/property.
Usage
import cProfile, io, pstats
with cProfile.Profile() as pr:
_ = sorted(range(500, 0, -1))
buf = io.StringIO()
pstats.Stats(pr, stream=buf).strip_dirs().sort_stats(pstats.SortKey.TIME).print_stats(5)
assert "function calls" in buf.getvalue()
Gotchas
- Call
.strip_dirs()first for readable output, and.add("other.prof")to merge multiple profile runs.
REPL Inspect
from pstats import Stats
help(Stats)
Linked from
Related notes
- tuts/python3/stdlib_module/pstats/FunctionProfile Linked here; links to this page; shared tags: #pstats, #stdlib
- tuts/python3/stdlib_module/pstats/SortKey Linked here; links to this page; shared tags: #pstats, #stdlib
- tuts/python3/stdlib_module/pstats/StatsProfile Linked here; links to this page; shared tags: #pstats, #stdlib
- tuts/python3/stdlib_module/pstats Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib