| Use Case | Command | Description |
|---|---|---|
| Profile a statement string | profile.run('code') | Execute and profile a string, print stats |
| Profile a function call | Profile().runcall(func, *args, **kw) | Profile a single function call directly |
| Profile with custom globals/locals | profile.runctx('code', globals(), locals()) | Run statement with given namespace, optional file output |
| Save stats to file | Profile().dump_stats('profile.out') | Write raw profiling data to a file |
| Pretty-print stats | Profile().print_stats(sort=-1) | Print formatted report (sort by cumulative time, etc.) |
| Snapshot without stopping | Profile().snapshot_stats() | Take a statistics snapshot of the current run |
__init__(self, timer=None, bias=None) — Initialize self. See help(type(self)) for accurate signature.calibrate(self, m, verbose=0)create_stats(self)dump_stats(self, file)print_stats(self, sort=-1)run(self, cmd)runcall(self, func, /, *args, **kw) — This method is more useful to profile a single function call.runctx(self, cmd, globals, locals)set_cmd(self, cmd)simulate_call(self, name)simulate_cmd_complete(self)snapshot_stats(self)trace_dispatch(self, frame, event, arg)trace_dispatch_c_call(self, frame, t)trace_dispatch_call(self, frame, t)trace_dispatch_exception(self, frame, t)trace_dispatch_i(self, frame, event, arg)trace_dispatch_l(self, frame, event, arg)trace_dispatch_mac(self, frame, event, arg)trace_dispatch_return(self, frame, t)__dict__ — dictionary for instance variables (if defined)__weakref__ — list of weak references to the object (if defined)bias = 0dispatch = {'c_call': <function Profile.trace_dispatch_c_call>, 'c_exc...}fake_code = <class 'profile.Profile.fake_code'>fake_frame = <class 'profile.Profile.fake_frame'>Run statement under profiler optionally saving results in filename
This function takes a single argument that can be passed to the "exec" statement, and an optional file name. In all cases this routine attempts to "exec" its first argument and gather profiling statistics from the execution. If no file name is present, then this function automatically prints a simple profiling report, sorted by the standard name string (file/line/function-name) that is presented in each line.
Run statement under profiler, supplying your own globals and locals, optionally saving results in filename.
statement and filename have the same semantics as profile.run
__all__ = ['run', 'runctx', 'Profile']
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 18:15 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format