startup_timing_observer

Observer for tracking pipeline startup timing.

This module provides an observer that measures how long each processor’s takes during pipeline startup (i.e. setup() and StartFrame). It works by tracking setup() time and when the StartFrame arrives at a processor (on_process_frame) versus when it leaves (on_push_frame), giving the exact start() duration for each processor in the pipeline.

It also measures transport timing — the time from before setup() to the first BotConnectedFrame (SFU transports only) and ClientConnectedFrame — via a separate on_transport_timing_report event.

Example:

observer = StartupTimingObserver()

@observer.event_handler("on_startup_timing_report")
async def on_report(observer, report):
    for t in report.processor_timings:
        print(f"{t.processor_name}: {t.duration_secs:.3f}s")

@observer.event_handler("on_transport_timing_report")
async def on_transport(observer, report):
    if report.bot_connected_secs is not None:
        print(f"Bot connected in {report.bot_connected_secs:.3f}s")
    print(f"Client connected in {report.client_connected_secs:.3f}s")

worker = PipelineWorker(pipeline, observers=[observer])
class pipecat.observers.startup_timing_observer.ProcessorStartupTiming(*, processor_name: str, start_offset_secs: float, duration_secs: float, setup_duration_secs: float, start_duration_secs: float = 0.0)[source]

Bases: BaseModel

Startup timing for a single processor.

Parameters:
  • processor_name – The name of the processor.

  • start_offset_secs – Offset in seconds from the StartFrame to when this processor’s start() began.

  • duration_secs – What the processor cost to get ready, in seconds: its setup() and its start() together.

  • setup_duration_secs – How long the processor’s setup() took, in seconds. Processors are set up concurrently, so this overlaps every other processor’s and only the longest of them holds up the pipeline.

  • start_duration_secs – How long the processor spent on the StartFrame, in seconds. The frame reaches processors one after another, so this adds to what every other processor spent rather than overlapping it.

class pipecat.observers.startup_timing_observer.StartupWarmupTiming(*, duration_secs: float, blocking_duration_secs: float)[source]

Bases: BaseModel

What warming the framework’s deferred imports cost startup.

Deprecated since version 1.12.0: No replacement. Nothing warms deferred imports at startup, so this timing is never reported. Will be removed in 2.0.0.

Parameters:
  • duration_secs – How long warming took, in seconds.

  • blocking_duration_secs – The part of warming the pipeline waited on once every processor had finished setting up, in seconds. Warming runs alongside setup, so a pipeline whose processors take longer to connect than warming takes to load pays nothing for it.

class pipecat.observers.startup_timing_observer.StartupTimingReport(*, start_time: float, total_duration_secs: float, setup_phase_secs: float = 0.0, start_phase_secs: float = 0.0, processor_timings: list[ProcessorStartupTiming] = <factory>, warmup: StartupWarmupTiming | None = None)[source]

Bases: BaseModel

Report of startup timings for all measured processors.

Parameters:
  • start_time – Unix timestamp when the pipeline began setting up.

  • total_duration_secs – Wall-clock time from the pipeline starting to set up until it had started, which is setup_phase_secs and start_phase_secs back to back.

  • setup_phase_secs – How long getting every processor ready took, in seconds. Setting up runs concurrently, so the longest single processor decides this rather than their sum.

  • start_phase_secs – How long the StartFrame took to travel the pipeline, in seconds. It reaches processors one after another, so what each spends on it adds up.

  • processor_timings – Per-processor timing data, in pipeline order.

  • warmup –

    Always None.

    Deprecated since version 1.12.0: No replacement. Nothing warms deferred imports at startup. Will be removed in 2.0.0.

class pipecat.observers.startup_timing_observer.TransportTimingReport(*, start_time: float, bot_connected_secs: float | None = None, client_connected_secs: float | None = None)[source]

Bases: BaseModel

Time from pipeline start to transport connection milestones.

Parameters:
  • start_time – Unix timestamp when the pipeline began setting up.

  • bot_connected_secs – Seconds from the pipeline starting to set up until the first BotConnectedFrame (only set for SFU transports).

  • client_connected_secs – Seconds from the pipeline starting to set up until the first ClientConnectedFrame.

class pipecat.observers.startup_timing_observer.StartupTimingObserver(*, processor_types: tuple[type[FrameProcessor], ...] | None = None, **kwargs)[source]

Bases: BaseObserver

Observer that measures processor startup times during pipeline initialization.

Tracks what each processor costs to get ready: its setup() and its start() together, the latter measured from the StartFrame arriving at the processor to it being pushed downstream. This captures WebSocket connections, API authentication, model loading, and other initialization work, most of which happens while the processor is being set up.

Also measures transport timing, the time from the pipeline starting to set up until each connection milestone. A transport connects while it is set up, so these can be reached before the StartFrame is pushed:

  • bot_connected_secs: When the bot joins the transport room (SFU transports only, triggered by BotConnectedFrame).

  • client_connected_secs: When a remote participant connects (triggered by ClientConnectedFrame).

By default, internal pipeline processors (PipelineSource, Pipeline) are excluded from the report. Pass processor_types to measure only specific types.

Event handlers available:

  • on_startup_timing_report: Called once after startup completes with the full timing report.

  • on_transport_timing_report: Called once when the first client connects with a TransportTimingReport containing client_connected_secs and bot_connected_secs (if available).

Example:

observer = StartupTimingObserver(
    processor_types=(STTService, TTSService)
)

@observer.event_handler("on_startup_timing_report")
async def on_report(observer, report):
    for t in report.processor_timings:
        logger.info(f"{t.processor_name}: {t.duration_secs:.3f}s")

@observer.event_handler("on_transport_timing_report")
async def on_transport(observer, report):
    if report.bot_connected_secs is not None:
        logger.info(f"Bot connected in {report.bot_connected_secs:.3f}s")
    logger.info(f"Client connected in {report.client_connected_secs:.3f}s")

worker = PipelineWorker(pipeline, observers=[observer])
Parameters:

processor_types – Optional tuple of processor types to measure. If None, all non-internal processors are measured.

__init__(*, processor_types: tuple[type[FrameProcessor], ...] | None = None, **kwargs)[source]

Initialize the startup timing observer.

Parameters:
  • processor_types – Optional tuple of processor types to measure. If None, all non-internal processors are measured.

  • **kwargs – Additional arguments passed to parent class.

async setup(task_manager: BaseTaskManager)[source]

Start the clock, before any processor has been set up.

Processors connect while they are being set up, so startup begins here rather than at the StartFrame.

Parameters:

task_manager – The task manager to run tasks on.

async on_processor_setup(data: ProcessorSetUp)[source]

Record how long a processor’s setup() took.

Parameters:

data – The processor setup event data.

async on_startup_warmup(data: StartupWarmup)[source]

Record what warming the framework’s deferred imports cost.

Deprecated since version 1.12.0: No replacement. Nothing warms deferred imports at startup, so this is never called. Will be removed in 2.0.0.

Parameters:

data – The startup warmup event data.

async on_pipeline_started()[source]

Emit the startup timing report when the pipeline has fully started.

Called by the PipelineWorker after the StartFrame has been processed by all processors, including nested ParallelPipeline branches.

async on_process_frame(data: FrameProcessed)[source]

Record when a StartFrame arrives at a processor.

Parameters:

data – The frame processing event data.

async on_push_frame(data: FramePushed)[source]

Record when a StartFrame leaves a processor and compute the delta.

Also handles BotConnectedFrame and ClientConnectedFrame to measure transport timing.

Parameters:

data – The frame push event data.