On this page
  1. profile.runctx
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

profile.runctx

Prev: profile.run | Up: profile
Rel: profile.Profile, profile.run
Ref: docs.python.org — profile.runctx
Tags: #public #python3 #stdlib #profile


Import

import profile
from profile import runctx

Signature & Overview

profile.runctx(statement, globals, locals, filename=None, sort=-1)

Run statement under profiler, supplying your own globals and locals, optionally saving results in filename.

Usage

import contextlib, io, profile

buf = io.StringIO()
with contextlib.redirect_stdout(buf):
    profile.runctx("sum(range(n))", {}, {"n": 100})
assert "function calls" in buf.getvalue()

Gotchas

REPL Inspect

from profile import runctx
help(runctx)

Linked from

Related notes