Pigweed
 
Loading...
Searching...
No Matches
pw::allocator::internal::Metrics< MetricsType > Class Template Referencefinal

#include <metrics.h>

Public Member Functions

 Metrics (metric::Token token)
 
const metric::Group & group () const
 
metric::Group & group ()
 
const MetricsType & metrics () const
 
void ModifyRequested (size_t increase, size_t decrease)
 
void ModifyAllocated (size_t increase, size_t decrease)
 
void IncrementAllocations ()
 Records that a call to Allocate was made.
 
void IncrementDeallocations ()
 Records that a call to Deallocate was made.
 
void IncrementResizes ()
 Records that a call to Resize was made.
 
void IncrementReallocations ()
 Records that a call to Reallocate was made.
 
void RecordFailure (size_t requested)
 
void UpdateDeferred (Allocator &allocator)
 

Detailed Description

template<typename MetricsType>
class pw::allocator::internal::Metrics< MetricsType >

Encapsulates the metrics struct for pw::allocator::TrackingAllocator.

This class uses the type traits from PW_ALLOCATOR_METRICS_DECLARE to conditionally include or exclude code to update metrics based on calls to the pw::Allocator API. This minimizes code size without adding additional conditions to be evaluated at runtime.

Template Parameters
MetricsTypeThe struct defining which metrics are enabled.

Member Function Documentation

◆ ModifyAllocated()

template<typename MetricsType >
void pw::allocator::internal::Metrics< MetricsType >::ModifyAllocated ( size_t  increase,
size_t  decrease 
)

Updates how much memory is allocated.

This will update the current, peak, and cumulative amounts of memory that has been actually allocated or freed. This method acts as if it frees memory before allocating. If a routine suchas Reallocate allocates before freeing, the update should be separated into two calls, e.g.

ModifyAllocated(increase, 0);
ModifyAllocated(0, decrease);
void ModifyAllocated(size_t increase, size_t decrease)
Definition: metrics.h:330
Parameters
increaseHow much memory was allocated.
decreaseHow much memory was freed.

◆ ModifyRequested()

template<typename MetricsType >
void pw::allocator::internal::Metrics< MetricsType >::ModifyRequested ( size_t  increase,
size_t  decrease 
)

Updates how much memory was requested and successfully allocated.

This will update the current, peak, and cumulative amounts of memory requests that were satisfied by an allocator.

Parameters
increaseHow much memory was requested to be allocated.
decreaseHow much memory was requested to be freed.

◆ RecordFailure()

template<typename MetricsType >
void pw::allocator::internal::Metrics< MetricsType >::RecordFailure ( size_t  requested)

Records that a call to Allocate, Resize, or Reallocate failed.

This may indicated that memory becoming exhausted and/or highly fragmented.

Parameters
requestedHow much memory was requested in the failed call.

◆ UpdateDeferred()

template<typename MetricsType >
void pw::allocator::internal::Metrics< MetricsType >::UpdateDeferred ( Allocator allocator)
inline

Updates metrics by querying an allocator directly.

See also NoMetrics::UpdateDeferred.


The documentation for this class was generated from the following file: