Profiler
Defined in the profiler module.Centralized profiler for performance monitoring. Thread-safe singleton pattern for global access. Features:
- Function/block timing
- API call profiling (wall-clock)
- Streaming profiling (TTFT)
- Memory profiling
- Import timing
- Statistics (p50, p95, p99)
- cProfile integration
- Export (JSON, HTML)
Methods
enable()
Enable profiling.
disable()
Disable profiling.
is_enabled()
Check if profiling is enabled.
clear()
Clear all profiling data.
record_timing()
Record a timing measurement.
record_import()
Record an import timing.
record_flow()
Record a flow step.
block()
Context manager for profiling a block of code.
get_timings()
Get timing records, optionally filtered by category.
get_imports()
Get import records, optionally filtered by minimum duration.
get_flow()
Get flow records.
get_files_accessed()
Get files accessed with counts.
get_summary()
Get profiling summary.
report()
Generate and output profiling report.
record_api_call()
Record an API/HTTP call timing.
get_api_calls()
Get API call records.
api_call()
Context manager for profiling API calls.
record_streaming()
Record streaming metrics.
get_streaming_records()
Get streaming records.
streaming()
Context manager for profiling streaming operations.
streaming_async()
Async context manager for profiling streaming operations.
record_memory()
Record memory usage.
get_memory_records()
Get memory records.
memory()
Context manager for profiling memory usage.
memory_snapshot()
Take a memory snapshot.
get_statistics()
Get statistical analysis of timing data.
cprofile()
Context manager for cProfile profiling.
get_cprofile_stats()
Get cProfile statistics.
get_line_profile_data()
Get line-level profiling data.
set_line_profile_data()
Store line-level profiling data.
get_flamegraph_data()
Generate flamegraph-compatible data from flow records.
export_flamegraph()
Export flamegraph to SVG file.
export_json()
Export profiling data as JSON.
export_html()
Export profiling data as HTML report.
export_to_file()
Export profiling data to file.

