Skip to main content

Profiler Module

The Profiler module provides 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

Import

Quick Examples

Profile a Function

Profile a Block

Profile API Calls

Profile Streaming

Profile Imports

Profiler Class

Static Methods

Profiler.block(name)

Context manager for profiling a code block.

Profiler.api_call(url)

Context manager for profiling API calls.

Profiler.streaming(name)

Context manager for profiling streaming operations.

Profiler.report()

Print a profiling report to console.

Profiler.get_statistics()

Get profiling statistics. Returns: dict with p50, p95, p99 percentiles

Profiler.export_json(path)

Export profiling data to JSON.

Profiler.export_html(path)

Export profiling data to HTML report.

Profiler.reset()

Reset all profiling data.

Decorators

@profile

Decorator to profile a function.

Context Managers

profile_imports()

Profile import times for modules.

Example: Full Profiling Session