Quick Start
Enable Per-Agent Profiling
Create isolated profilers for different agents to avoid mixing performance data.
How It Works
| Component | Purpose | Context Scope |
|---|---|---|
_ProfilerImpl | Per-instance profiler class | Agent-specific |
get_profiler() | Get current context profiler | Thread/async local |
set_profiler() | Install profiler in context | Thread/async local |
max_records | Bounded buffer size | Per instance |
Configuration Options
ProfilerImpl Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
max_records | int | 10000 | Maximum records per buffer before rotation |
Context Management
Common Patterns
Agent-Specific Performance Monitoring
Function-Level Profiling
Bounded Buffer Management
Best Practices
Create profiler per agent for isolation
Create profiler per agent for isolation
Always use separate profiler instances for different agents to prevent data mixing:
Size buffers appropriately for workload
Size buffers appropriately for workload
Choose buffer sizes based on expected operation count:
Use context blocks for granular timing
Use context blocks for granular timing
Profile specific operations with descriptive block names:
Monitor memory with profiler isolation
Monitor memory with profiler isolation
Each profiler tracks memory independently:
Backward Compatibility
The global However,
Profiler class is now a ProfilerCompat instance that delegates to get_profiler().
Existing code using Profiler.enable(), Profiler.block(), etc. continues to work unchanged:isinstance(x, Profiler) and class Foo(Profiler): will break as Profiler is no longer a class.Related
Agent Architecture
Learn about multi-agent patterns
Observability Overview
Complete observability system

