profile command provides detailed cProfile-based profiling for query execution, showing per-function and per-file timing, call graphs, and latency metrics.
Quick Start
Subcommands
Query
Profile a query execution with detailed timing breakdown.
Example:
Imports
Profile module import times to identify slow imports.Startup
Profile CLI startup time.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:Python API
You can also use the profiler programmatically:Use Cases
Identify Slow Imports
Optimize Agent Performance
Debug Latency Issues
CI/CD Integration
Safety Notes
- Secrets are redacted from profiling output (API keys, tokens)
- Deep tracing is opt-in due to overhead
- No prompt logging unless explicitly saved
- Safe by default - minimal overhead in normal mode
Profile Suite
Run comprehensive profiling across multiple scenarios:suite_results.json- Machine-readable JSON with all timing datasuite_report.txt- Human-readable summary report
simple_non_stream- Simple prompt, non-streamingsimple_stream- Simple prompt, streamingmedium_non_stream- Medium prompt, non-streamingmedium_stream- Medium prompt, streaming
Performance Analysis Report
Observed Timing Breakdown
Based on profiling runs, here’s where time is spent:Import Time Hotspots
Top modules by import time:Function Time Hotspots
Top functions by cumulative time:Root Causes
-
Heavy OpenAI SDK imports (~1.3s)
- Pydantic model validation at import time
- Type definitions loaded eagerly
-
Network latency (~2-5s)
- API round-trip dominates total time
- Cannot be optimized locally
-
Streaming vs Non-streaming
- Streaming shows faster time-to-first-token
- Total time similar or slightly better
Optimization Opportunities
Tier 0 (Safe, Fast Wins):- Lazy import OpenAI SDK only when needed
- Cache provider resolution
- Preload common providers in background
- Connection pooling for repeated calls
- Optional “lite” mode without full type checking
- Async initialization pipeline
Performance Snapshots
Create baseline snapshots and compare against them to detect regressions:Performance Optimizations
Configure opt-in performance optimizations:Environment Variables
Enable optimizations via environment variables:Optimization Tiers
Tier 0 (Always Safe):- Provider/model resolution caching
- Lazy imports for heavy modules
- CLI startup path optimization
- Connection pooling for repeated API calls
- Provider pre-warming (background initialization)
- Lite mode (skip expensive validation)
- Performance snapshot baselines

