Quick Start
Inline Profiling (—profile flag)
The simplest way to profile any command is with the--profile flag:
Deep Profiling
For detailed function-level analysis with call graphs:- Decision Trace: Agent config, model, streaming mode, tools
- Top Functions: Cumulative time by function
- Module Breakdown: Time grouped by module category
- Call Graph: Caller/callee relationships
JSON Output
Get machine-readable profile data:Commands
profile query
Profile a query execution with detailed timing breakdown:
Examples:
profile imports
Profile module import times to identify slow imports:profile startup
Profile CLI startup time (cold and warm):profile suite
Run a comprehensive profiling suite with multiple scenarios:
Examples:
suite_results.json- Machine-readable JSON with all timing datasuite_report.txt- Human-readable summary report
Advanced Usage
Deep Call Tracing
Enable deep call tracing for detailed call graph analysis:Save Artifacts
Save profiling artifacts for later analysis:profile_results.prof- Binary cProfile data (can be loaded with pstats)profile_results.txt- Human-readable report
JSON Output
Get machine-readable output for CI/CD integration:Streaming with First Token Tracking
Track time to first token in streaming mode:Combine with py-spy
For production-grade flamegraphs:CI/CD Integration
Add profiling to your CI pipeline:Output Formats
Text Output (Default)
Human-readable format printed to terminal with timing breakdown, function stats, and response preview.JSON Output
Machine-readable format for processing:Best Practices
Use suite for comprehensive benchmarks
Use suite for comprehensive benchmarks
The suite command runs multiple scenarios with warmup:
Profile in production-like environment
Profile in production-like environment
Run benchmarks with similar data sizes and network conditions as production.
Use --show-files to identify hotspots
Use --show-files to identify hotspots
Group timing by file to find which modules are slowest:
Compare streaming vs non-streaming
Compare streaming vs non-streaming
Streaming often has faster time-to-first-token:
Troubleshooting
High import times
High import times
Import times are dominated by OpenAI SDK. This is expected:Consider lazy imports if startup time is critical.
High variance in benchmarks
High variance in benchmarks
Increase iterations in suite mode:
Deep tracing too slow
Deep tracing too slow
Deep tracing adds significant overhead. Use only for debugging:

