frame_processor_metrics
Frame processor metrics collection and reporting.
- class pipecat.processors.metrics.frame_processor_metrics.FrameProcessorMetrics[source]
Bases:
BaseObjectMetrics collection and reporting for frame processors.
Provides comprehensive metrics tracking for frame processing operations, including timing measurements, resource usage, and performance analytics. Supports TTFB tracking, processing duration metrics, and usage statistics for LLM and TTS operations.
- __init__()[source]
Initialize the frame processor metrics collector.
Sets up internal state for tracking various metrics including TTFB, processing times, and usage statistics.
- async setup(task_manager: BaseTaskManager)[source]
Set up the metrics collector with a task manager.
- Parameters:
task_manager – The task manager for handling async operations.
- property task_manager: BaseTaskManager
Get the associated task manager.
- Returns:
The task manager instance for async operations.
- property ttfb: float | None
Get the current TTFB value in seconds.
- Returns:
The TTFB value in seconds, or None if not measured.
- set_core_metrics_data(data: MetricsData)[source]
Set the core metrics data for this collector.
- Parameters:
data – The core metrics data containing processor and model information.
- set_processor_name(name: str)[source]
Set the processor name for metrics reporting.
- Parameters:
name – The name of the processor to use in metrics.
- async start_ttfb_metrics(*, start_time: float | None = None, report_only_initial_ttfb: bool)[source]
Start measuring time-to-first-byte (TTFB).
- Parameters:
start_time – Optional timestamp to use as the start time. If None, uses the current time.
report_only_initial_ttfb – Whether to report only the first TTFB measurement.
- async stop_ttfb_metrics(*, end_time: float | None = None)[source]
Stop TTFB measurement and generate metrics frame.
- Parameters:
end_time – Optional timestamp to use as the end time. If None, uses the current time.
- Returns:
MetricsFrame containing TTFB data, or None if not measuring.
- async start_processing_metrics(*, start_time: float | None = None)[source]
Start measuring processing time.
- Parameters:
start_time – Optional timestamp to use as the start time. If None, uses the current time.
- async stop_processing_metrics(*, end_time: float | None = None)[source]
Stop processing time measurement and generate metrics frame.
- Parameters:
end_time – Optional timestamp to use as the end time. If None, uses the current time.
- Returns:
MetricsFrame containing processing duration data, or None if not measuring.
- async start_llm_usage_metrics(tokens: LLMTokenUsage)[source]
Record LLM token usage metrics.
- Parameters:
tokens – Token usage information including prompt and completion tokens.
- Returns:
MetricsFrame containing LLM usage data.
- async start_tts_usage_metrics(text: str)[source]
Record TTS character usage metrics.
- Parameters:
text – The text being processed by TTS.
- Returns:
MetricsFrame containing TTS usage data.