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
impl PeakRecordingPool
Sourcepub fn new(inner: Arc<dyn MemoryPool>) -> Self
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.
Sourcepub fn from_pool(pool: &dyn MemoryPool) -> Option<&Self>
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.
Sourcepub fn peak_reserved(&self) -> usize
pub fn peak_reserved(&self) -> usize
Peak reservation, in bytes, since the last Self::reset_peak.
Sourcepub fn max_reserved(&self) -> usize
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.
Sourcepub fn reset_peak(&self)
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
impl Debug for PeakRecordingPool
Source§impl Display for PeakRecordingPool
impl Display for PeakRecordingPool
Source§impl MemoryPool for PeakRecordingPool
impl MemoryPool for PeakRecordingPool
Source§fn register(&self, consumer: &MemoryConsumer)
fn register(&self, consumer: &MemoryConsumer)
MemoryConsumer Read moreSource§fn unregister(&self, consumer: &MemoryConsumer)
fn unregister(&self, consumer: &MemoryConsumer)
Source§fn grow(&self, reservation: &MemoryReservation, additional: usize)
fn grow(&self, reservation: &MemoryReservation, additional: usize)
Source§fn shrink(&self, reservation: &MemoryReservation, shrink: usize)
fn shrink(&self, reservation: &MemoryReservation, shrink: usize)
reservation by shrink bytesSource§fn memory_limit(&self) -> MemoryLimit
fn memory_limit(&self) -> MemoryLimit
Auto Trait Implementations§
impl !Freeze for PeakRecordingPool
impl !RefUnwindSafe for PeakRecordingPool
impl !UnwindSafe for PeakRecordingPool
impl Send for PeakRecordingPool
impl Sync for PeakRecordingPool
impl Unpin for PeakRecordingPool
impl UnsafeUnpin for PeakRecordingPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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