Skip to content

proxystore.store.stats

Utilities for Tracking Stats on Store Operations.

Event

Bases: NamedTuple

Event corresponding to a function called with a specific key.

TimeStats dataclass

Helper class for tracking time stats of an operation.

add_time

add_time(
    time_ms: float, size_bytes: int | None = None
) -> None

Add a new time to the stats.

Parameters:

  • time_ms (float) –

    Time (milliseconds) of a method execution.

  • size_bytes (int | None) –

    Optionally note the data size associated with the operation that produced these statistics.

Source code in proxystore/store/stats.py
def add_time(self, time_ms: float, size_bytes: int | None = None) -> None:
    """Add a new time to the stats.

    Args:
        time_ms: Time (milliseconds) of a method execution.
        size_bytes: Optionally note the data size associated with
            the operation that produced these statistics.
    """
    self.avg_time_ms = self._weighted_avg(
        self.avg_time_ms,
        self.calls,
        time_ms,
        1,
    )
    self.min_time_ms = min(time_ms, self.min_time_ms)
    self.max_time_ms = max(time_ms, self.max_time_ms)
    self.calls += 1
    self.size_bytes = size_bytes

FunctionEventStats

FunctionEventStats() -> None

Bases: MutableMapping

Class for tracking stats of calls of functions that take a key.

Source code in proxystore/store/stats.py
def __init__(self) -> None:
    self._events: dict[Event, TimeStats] = {}

keys

keys() -> KeysView[Event]

Return list of events being tracked.

Source code in proxystore/store/stats.py
def keys(self) -> KeysView[Event]:
    """Return list of events being tracked."""
    return self._events.keys()

wrap

wrap(
    function: GenericCallable,
    *,
    key_is_result: bool = False,
    preset_key: NamedTuple | None = None
) -> GenericCallable

Wrap a method to log stats on calls to the function.

Parameters:

  • function (GenericCallable) –

    Function to wrap.

  • key_is_result (bool) –

    If True, the key is the return value of function rather than the first argument.

  • preset_key (NamedTuple | None) –

    Optionally preset the key associated with any calls to function. This overrides key_is_returned.

Returns:

  • GenericCallable

    Callable with same interface as function.

Source code in proxystore/store/stats.py
def wrap(
    self,
    function: GenericCallable,
    *,
    key_is_result: bool = False,
    preset_key: NamedTuple | None = None,
) -> GenericCallable:
    """Wrap a method to log stats on calls to the function.

    Args:
        function: Function to wrap.
        key_is_result: If `True`, the key is the return value of
            `function` rather than the first argument.
        preset_key: Optionally preset the key associated with any calls to
            `function`. This overrides `key_is_returned`.

    Returns:
        Callable with same interface as `function`.
    """
    out_fun = partial(self._function, function, key_is_result, preset_key)

    return cast(GenericCallable, out_fun)