Skip to main content
The 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.
Options: Example:
Output:

Imports

Profile module import times to identify slow imports.
Output:

Startup

Profile CLI startup time.
Output:

Advanced Usage

Deep Call Tracing

Enable deep call tracing for detailed call graph analysis:
Deep call tracing adds significant overhead. Use only for detailed debugging.

Save Artifacts

Save profiling artifacts for later analysis:
This creates:
  • 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:
Output Files:
  • suite_results.json - Machine-readable JSON with all timing data
  • suite_report.txt - Human-readable summary report
Scenarios Tested:
  • simple_non_stream - Simple prompt, non-streaming
  • simple_stream - Simple prompt, streaming
  • medium_non_stream - Medium prompt, non-streaming
  • medium_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

  1. Heavy OpenAI SDK imports (~1.3s)
    • Pydantic model validation at import time
    • Type definitions loaded eagerly
  2. Network latency (~2-5s)
    • API round-trip dominates total time
    • Cannot be optimized locally
  3. 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
Tier 1 (Medium Effort):
  • Preload common providers in background
  • Connection pooling for repeated calls
Tier 2 (Architectural):
  • Optional “lite” mode without full type checking
  • Async initialization pipeline

Performance Snapshots

Create baseline snapshots and compare against them to detect regressions:
Output (comparison):

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
Tier 1 (Opt-in):
  • Connection pooling for repeated API calls
  • Provider pre-warming (background initialization)
Tier 2 (Opt-in, Architectural):
  • Lite mode (skip expensive validation)
  • Performance snapshot baselines