Skip to content

Performance profiler

cutana.performance_profiler

Performance profiler for Cutana cutout processing.

This module provides a lightweight profiler to track runtime of different processing steps within the cutout creation pipeline. Each cutout process instance should have one profiler to monitor performance.

PerformanceProfiler(process_id=None, timing_function=time.perf_counter)

Lightweight performance profiler for tracking runtime of processing steps.

Each cutout process should have one instance of this profiler to track: - FITS file loading time - Cutout extraction time - Image processing time - Output writing time

Initialize performance profiler.

Parameters:

Name Type Description Default
process_id Optional[str]

Optional process identifier, defaults to PID

None
timing_function Callable[[], float]

Optional function to use for timing, defaults to time.perf_counter

perf_counter

start_timing(step)

Start timing a processing step.

Parameters:

Name Type Description Default
step str

Name of the processing step to time

required

end_timing(step)

End timing a processing step and record the duration.

Parameters:

Name Type Description Default
step str

Name of the processing step to stop timing

required

Returns:

Type Description
float

Duration in seconds

Raises:

Type Description
ValueError

If start_timing was not called for this step

record_source_processed()

Record that a source has been processed.

get_statistics()

Get performance statistics for all timed steps.

Returns:

Type Description
Dict[str, Any]

Dictionary containing timing statistics

log_performance_summary()

Log a summary of performance statistics.

get_bottlenecks(threshold_percent=20.0)

Identify performance bottlenecks.

Parameters:

Name Type Description Default
threshold_percent float

Minimum percentage of total time to be considered a bottleneck

20.0

Returns:

Type Description
List[str]

List of step names that are bottlenecks

ContextProfiler(profiler, step)

Context manager for easy timing of code blocks.

Initialize context profiler.

Parameters:

Name Type Description Default
profiler PerformanceProfiler

PerformanceProfiler instance

required
step str

Name of the step to time

required

__enter__()

Start timing when entering context.

__exit__(_exc_type, _exc_val, _exc_tb)

End timing when exiting context.