On this page
  1. pstats.Stats
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

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

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

REPL Inspect

from pstats import Stats
help(Stats)

Linked from

Related notes