sec_interp.core.performance_metrics module

Performance metrics module for SecInterp plugin.

This module provides tools for tracking performance and resource usage across the plugin’s operations.

class sec_interp.core.performance_metrics.MetricsCollector

Bases: object

Collects and aggregates performance metrics.

record_timing(operation: str, duration: float) None

Record duration of an operation.

Parameters:
  • operation – Name of the operation

  • duration – Duration in seconds

record_count(metric: str, count: int) None

Record a count metric (e.g. number of points).

Parameters:
  • metric – Name of the metric

  • count – Count value

add_metadata(key: str, value: Any) None

Add metadata to the metrics collection.

Parameters:
  • key – Metadata key

  • value – Metadata value

get_summary() dict[str, Any]

Get summary of collected metrics.

Returns:

Dictionary with all collected metrics

clear() None

Clear all collected metrics.

class sec_interp.core.performance_metrics.PerformanceTimer(operation_name: str, collector: MetricsCollector | None = None, logger_func: Any | None = None)

Bases: object

Context manager for timing operations.

Initialize timer.

Parameters:
  • operation_name – Name of operation to measure

  • collector – Optional metrics collector to record into

  • logger_func – Optional logger function for immediate logging

__init__(operation_name: str, collector: MetricsCollector | None = None, logger_func: Any | None = None)

Initialize timer.

Parameters:
  • operation_name – Name of operation to measure

  • collector – Optional metrics collector to record into

  • logger_func – Optional logger function for immediate logging

__enter__()

Start the timer.

Returns:

The timer instance

Return type:

self

__exit__(exc_type, exc_val, exc_tb)

Stop the timer and record/log validity.

Parameters:
  • exc_type – Exception type if raised

  • exc_val – Exception value if raised

  • exc_tb – Exception traceback if raised

sec_interp.core.performance_metrics.format_duration(seconds: float) str

Format duration in human readable format.

Parameters:

seconds – Duration in seconds

Returns:

Formatted string (e.g. “1.2s”, “150ms”)

class sec_interp.core.performance_metrics.PerformanceMonitor(log_file='performance.log')

Bases: object

Performance monitoring using only Python standard library.

measure_operation(operation_name, **metadata)

Context manager to measure operation performance.

get_operation_stats(operation_name)

Get statistics for an operation.

sec_interp.core.performance_metrics.performance_monitor(func)

Decorator to automatically monitor function performance.