> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# profiler • AI Agents Framework

> PraisonAI Profiler Module

# profiler

<Badge color="purple">AI Agents Framework</Badge>

PraisonAI Profiler Module

Standardized profiling for performance monitoring across praisonai and praisonai-agents.

Features:

* Import timing
* Function execution timing
* Flow tracking
* File/module usage tracking
* Memory usage (tracemalloc)
* API call profiling (wall-clock time)
* Streaming profiling (TTFT, total time)
* Statistics (p50, p95, p99)
* cProfile integration
* Flamegraph generation
* Line-level profiling
* JSON/HTML export

Usage:
from praisonai.profiler import Profiler, profile, profile\_imports

# Profile a function

@profile
def my\_function():
pass

# Profile a block

with Profiler.block("my\_operation"):
do\_something()

# Profile API calls

with Profiler.api\_call("[https://api.example.com](https://api.example.com)") as call:
response = requests.get(...)

# Profile streaming

with Profiler.streaming("chat") as tracker:
tracker.first\_token()
for chunk in stream:
tracker.chunk()

# Profile imports

with profile\_imports():
import heavy\_module

# Get report with statistics

Profiler.report()
stats = Profiler.get\_statistics()

# Export

Profiler.export\_json()
Profiler.export\_html()

## Import

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonai import profiler
```

## Classes

<CardGroup cols={2}>
  <Card title="TimingRecord" icon="brackets-curly" href="../classes/TimingRecord">
    Record of a single timing measurement.
  </Card>

  <Card title="APICallRecord" icon="brackets-curly" href="../classes/APICallRecord">
    Record of an API/HTTP call.
  </Card>

  <Card title="StreamingRecord" icon="brackets-curly" href="../classes/StreamingRecord">
    Record of streaming operation (LLM responses).
  </Card>

  <Card title="MemoryRecord" icon="brackets-curly" href="../classes/MemoryRecord">
    Record of memory usage.
  </Card>

  <Card title="ImportRecord" icon="brackets-curly" href="../classes/ImportRecord">
    Record of a module import.
  </Card>

  <Card title="FlowRecord" icon="brackets-curly" href="../classes/FlowRecord">
    Record of execution flow.
  </Card>

  <Card title="StreamingTracker" icon="brackets-curly" href="../classes/StreamingTracker">
    Track streaming operations (LLM responses).
  </Card>

  <Card title="Profiler" icon="brackets-curly" href="../classes/Profiler">
    Centralized profiler for performance monitoring.
  </Card>

  <Card title="ImportProfiler" icon="brackets-curly" href="../classes/ImportProfiler">
    Context manager to profile imports.
  </Card>
</CardGroup>

## Functions

<CardGroup cols={2}>
  <Card title="profile()" icon="function" href="../functions/profile">
    Decorator to profile a function.
  </Card>

  <Card title="profile_async()" icon="function" href="../functions/profile_async">
    Decorator to profile an async function.
  </Card>

  <Card title="profile_imports()" icon="function" href="../functions/profile_imports">
    Create an import profiler context manager.
  </Card>

  <Card title="profile_api()" icon="function" href="../functions/profile_api">
    Decorator to profile a function as an API call.
  </Card>

  <Card title="profile_api_async()" icon="function" href="../functions/profile_api_async">
    Decorator to profile an async function as an API call.
  </Card>

  <Card title="profile_detailed()" icon="function" href="../functions/profile_detailed">
    Decorator for detailed cProfile profiling.
  </Card>

  <Card title="profile_lines()" icon="function" href="../functions/profile_lines">
    Decorator for line-level profiling.
  </Card>

  <Card title="time_import()" icon="function" href="../functions/time_import">
    Time how long it takes to import a module.
  </Card>

  <Card title="check_module_available()" icon="function" href="../functions/check_module_available">
    Check if a module is available without importing it.
  </Card>
</CardGroup>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Agent Profiles" icon="id-card" href="/docs/features/agent-profiles" />

  <Card title="Profiling" icon="chart-line" href="/docs/features/profiling" />
</CardGroup>
