Skip to main content

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: 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

from praisonai import profiler

Classes

TimingRecord

Record of a single timing measurement.

APICallRecord

Record of an API/HTTP call.

StreamingRecord

Record of streaming operation (LLM responses).

MemoryRecord

Record of memory usage.

ImportRecord

Record of a module import.

FlowRecord

Record of execution flow.

StreamingTracker

Track streaming operations (LLM responses).

Profiler

Centralized profiler for performance monitoring.

ImportProfiler

Context manager to profile imports.

Functions

profile()

Decorator to profile a function.

profile_async()

Decorator to profile an async function.

profile_imports()

Create an import profiler context manager.

profile_api()

Decorator to profile a function as an API call.

profile_api_async()

Decorator to profile an async function as an API call.

profile_detailed()

Decorator for detailed cProfile profiling.

profile_lines()

Decorator for line-level profiling.

time_import()

Time how long it takes to import a module.

check_module_available()

Check if a module is available without importing it.

Agent Profiles

Profiling