PerfTrace is a unified performance tracing and profiling CLI for Python applications.
It provides detailed insights into function execution, context/module performance, CPU and memory usage, and system metrics, with rich statistical summaries and export support β all through a clean, production-ready command-line interface.
PerfTrace is developer-centric, explicit, and lightweight.
It focuses on performance analysis, not error or exception tracking.
- π Function & context-level profiling
- π Statistical metrics (min / max / avg / p90 / p95 / p99 / std dev)
- π Recent, daily, and historical analysis
- π’ Slowest / fastest execution detection
- π§ System & memory monitoring
- π Export to CSV & JSON
- π©Ί Health diagnostics (
doctor) - βοΈ Configurable storage backends (DuckDB & PostgreSQL)
- π§© Function, class, and context-manager based instrumentation
pip install perftraceRequirements
- Python 3.11+
perftrace helpRecommended first commands:
perftrace summary
perftrace doctor
perftrace stats-function <FUNCTION_NAME>PerfTrace works in two clear phases:
-
Instrumentation
Developers explicitly mark functions, classes, or code blocks using decorators or context managers. -
Analysis
The CLI queries stored metrics and generates summaries, statistics, and exports.
PerfTrace runs only when your code runs β there are no background agents, daemons, or always-on processes.
PerfTrace allows you to explicitly control which performance metrics are collected.
You can either:
- provide a list of specific metrics, or
- use
"all"to collect every supported metric
| Metric | Description |
|---|---|
cpu |
CPU usage and CPU time |
memory |
Memory usage and deltas |
execution |
Execution time |
file |
File I/O activity |
garbagecollector |
Garbage collection activity |
ThreadContext |
Thread and execution context |
network |
Network activity |
from perftrace import perf_trace_metrics
@perf_trace_metrics(profilers=["cpu", "memory", "execution"])
def compute():
return [i for i in range(100000)]@perf_trace_metrics(profilers="all")
def full_trace():
return [i for i in range(100000)]from perftrace import perf_trace_metrics_cl
@perf_trace_metrics_cl(profilers=["cpu", "execution"])
class MyProcessor:
@staticmethod
def step1(x):
return x + 1
def step2(self, y):
return y * 2from perftrace import PerfTraceContextManager
with PerfTraceContextManager(
context_tag="work",
cls_collectors=["cpu", "memory"]
):
work = [x ** 2 for x in range(100000)]| Command | Description |
|---|---|
version |
Show PerfTrace version |
help |
Display help |
doctor |
Run health checks |
summary |
Overall performance summary |
list |
List available functions and contexts |
| Command | Description |
|---|---|
show-function <name> |
Detailed trace data |
stats-function <name> |
Statistical metrics |
recent-function |
Recently executed functions |
search-function <name> |
Search execution history |
count-function |
Execution frequency |
slowest |
Slowest execution |
fastest |
Fastest execution |
| Command | Description |
|---|---|
show-context <name> |
Context trace data |
stats-context <name> |
Statistical metrics |
recent-context |
Recently executed contexts |
search-context <name> |
Search history |
count-context |
Execution frequency |
| Command | Description |
|---|---|
today |
Executions today |
history |
Historical data |
| Command | Description |
|---|---|
system-status |
System status |
system-info |
System information |
system-monitor |
Real-time monitoring |
memory |
Memory usage |
| Command | Description |
|---|---|
export-csv |
Export database to CSV |
export-json |
Export database to JSON |
export-function-csv |
Export function CSV |
export-context-csv |
Export context CSV |
export-function-json |
Export function JSON |
export-context-json |
Export context JSON |
Config file locations:
- Linux / macOS:
~/.perftrace/config.yaml - Windows:
%USERPROFILE%\.perftrace\config.yaml
database:
engine: duckdb
duckdb:
path: ./data/default.duckdbdatabase:
engine: postgresql
postgresql:
host: localhost
port: 5432
user: postgres
password: your_passwordInteractive setup:
perftrace set-configVerify:
perftrace doctorPerfTrace complements APM tools by providing:
- precise function-level metrics
- lightweight, on-demand profiling
- local and CI-friendly analysis
PerfTrace is not a distributed tracing or error-tracking system.