profiler • AI Agents Framework

PraisonAI Profiler Module

profiler

AI Agents Framework

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:

python
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") 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
from praisonai import profiler

Classes

Functions

Constants

NameValue
_PROFILER_MAX_get_profiler_max()
_TRACEMALLOC_LOCKthreading.Lock()
_TRACEMALLOC_STARTERS0
_IMPORT_HOOK_LOCKthreading.Lock()
_IMPORT_HOOK_ORIGINALNone

Related Documentation