Skip to main content

PeakRecordingPool

Struct PeakRecordingPool 

Source
pub struct PeakRecordingPool { /* private fields */ }
Expand description

Wraps a MemoryPool, recording the high-water mark of MemoryPool::reserved as reservations come and go.

Every method delegates to the wrapped pool, so wrapping does not change how memory is granted, limited, or reported. The one thing it does change is downcasting: rt.memory_pool.downcast_ref::<FairSpillPool>() now finds this wrapper instead of the pool it wraps. Nothing in the benchmarks relies on that, and Self::from_pool uses the same mechanism to find the recorder.

Both high-water marks are held per instance, so a benchmark that builds a fresh runtime per query gets a reading scoped to that query without any coordination.

§Example

let recording = Arc::new(PeakRecordingPool::new(Arc::new(GreedyMemoryPool::new(1024))));
let pool: Arc<dyn MemoryPool> = Arc::clone(&recording) as _;

let reservation = MemoryConsumer::new("example").register(&pool);
reservation.try_grow(512)?;
reservation.shrink(512);

// The pool is back to empty, but the high-water mark is retained.
assert_eq!(pool.reserved(), 0);
assert_eq!(recording.peak_reserved(), 512);

// The recorder can also be recovered from the pool it was installed as.
assert_eq!(PeakRecordingPool::from_pool(&*pool).unwrap().peak_reserved(), 512);

Implementations§

Source§

impl PeakRecordingPool

Source

pub fn new(inner: Arc<dyn MemoryPool>) -> Self

Wrap inner, recording its peak reservation from here on.

inner is expected to be empty: the running total starts at zero, so anything reserved before wrapping is not counted.

Source

pub fn from_pool(pool: &dyn MemoryPool) -> Option<&Self>

The recorder installed as pool, if there is one.

Returns None whenever a benchmark runs without a memory limit, since CommonOpt::runtime_env_builder only installs the wrapper alongside a pool it has a limit for.

Source

pub fn peak_reserved(&self) -> usize

Peak reservation, in bytes, since the last Self::reset_peak.

Source

pub fn max_reserved(&self) -> usize

Peak reservation, in bytes, since this pool was created.

Unlike Self::peak_reserved this is never reset, so it reports the peak across every query that shared this pool.

Source

pub fn reset_peak(&self)

Reset the value returned by Self::peak_reserved to what is reserved right now, so the next reading covers only what follows.

BenchmarkRun::start_new_case calls this, giving each benchmark query its own reading. Anything still held when a query starts — data the benchmark loaded up front, say — stays in the reading, since the query runs with those bytes reserved.

Trait Implementations§

Source§

impl Debug for PeakRecordingPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PeakRecordingPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl MemoryPool for PeakRecordingPool

Source§

fn name(&self) -> &str

Return pool name
Source§

fn register(&self, consumer: &MemoryConsumer)

Registers a new MemoryConsumer Read more
Source§

fn unregister(&self, consumer: &MemoryConsumer)

Records the destruction of a MemoryReservation with MemoryConsumer Read more
Source§

fn grow(&self, reservation: &MemoryReservation, additional: usize)

Infallibly grow the provided reservation by additional bytes Read more
Source§

fn shrink(&self, reservation: &MemoryReservation, shrink: usize)

Infallibly shrink the provided reservation by shrink bytes
Source§

fn try_grow( &self, reservation: &MemoryReservation, additional: usize, ) -> Result<()>

Attempt to grow the provided reservation by additional bytes Read more
Source§

fn reserved(&self) -> usize

Return the total amount of memory reserved
Source§

fn memory_limit(&self) -> MemoryLimit

Return the memory limit of the pool Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V