Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
rapidsmpf::Statistics Class Reference

Track statistics across rapidsmpf operations. More...

#include <statistics.hpp>

Classes

struct  MemoryRecord
 Holds memory profiling information for a named scope. More...
 
class  MemoryRecorder
 RAII-style object for scoped memory usage tracking. More...
 
class  Stat
 Represents a single tracked statistic. More...
 

Public Types

using Formatter = std::function< void(std::ostream &, std::size_t, double)>
 Type alias for a statistics formatting function. More...
 

Public Member Functions

 Statistics (bool enabled=true)
 Constructs a Statistics object without memory profiling. More...
 
 Statistics (RmmResourceAdaptor *mr)
 Constructs a Statistics object with memory profiling enabled. More...
 
 Statistics (Statistics const &)=delete
 
Statisticsoperator= (Statistics const &)=delete
 
 Statistics (Statistics &&o) noexcept
 Move constructor. More...
 
Statisticsoperator= (Statistics &&o) noexcept
 Move assignment operator. More...
 
bool enabled () const noexcept
 Checks if statistics tracking is enabled. More...
 
std::string report (std::string const &header="Statistics:") const
 Generates a formatted report of all collected statistics. More...
 
Stat get_stat (std::string const &name) const
 Retrieves a statistic by name. More...
 
double add_stat (std::string const &name, double value, Formatter const &formatter=FormatterDefault)
 Adds a numeric value to the named statistic. More...
 
std::size_t add_bytes_stat (std::string const &name, std::size_t nbytes)
 Adds a byte count to the named statistic. More...
 
Duration add_duration_stat (std::string const &name, Duration seconds)
 Adds a duration to the named statistic. More...
 
std::vector< std::string > list_stat_names () const
 Get the names of all statistics. More...
 
void clear ()
 Clears all statistics. More...
 
bool is_memory_profiling_enabled () const
 Checks whether memory profiling is enabled. More...
 
MemoryRecorder create_memory_recorder (std::string name)
 Creates a scoped memory recorder for the given name. More...
 
std::unordered_map< std::string, MemoryRecord > const & get_memory_records () const
 Retrieves all memory profiling records stored by this instance. More...
 

Static Public Member Functions

static std::shared_ptr< Statisticsdisabled ()
 Returns a shared pointer to a disabled (no-op) Statistics instance. More...
 
static void FormatterDefault (std::ostream &os, std::size_t count, double val)
 Default formatter for statistics output (implements Formatter). More...
 

Detailed Description

Track statistics across rapidsmpf operations.

Definition at line 23 of file statistics.hpp.

Member Typedef Documentation

◆ Formatter

using rapidsmpf::Statistics::Formatter = std::function<void(std::ostream&, std::size_t, double)>

Type alias for a statistics formatting function.

The formatter is called with the output stream, update count, and accumulated value.

Definition at line 101 of file statistics.hpp.

Constructor & Destructor Documentation

◆ Statistics() [1/3]

rapidsmpf::Statistics::Statistics ( bool  enabled = true)

Constructs a Statistics object without memory profiling.

Parameters
enabledIf true, enables tracking of statistics. If false, all operations are no-ops.

◆ Statistics() [2/3]

rapidsmpf::Statistics::Statistics ( RmmResourceAdaptor mr)

Constructs a Statistics object with memory profiling enabled.

Automatically enables both statistics and memory profiling.

Parameters
mrPointer to a memory resource used for memory profiling.
Exceptions
std::invalid_argumentIf mr is the nullptr.

◆ Statistics() [3/3]

rapidsmpf::Statistics::Statistics ( Statistics &&  o)
inlinenoexcept

Move constructor.

Parameters
oThe Statistics object to move from.

Definition at line 63 of file statistics.hpp.

Member Function Documentation

◆ add_bytes_stat()

std::size_t rapidsmpf::Statistics::add_bytes_stat ( std::string const &  name,
std::size_t  nbytes 
)

Adds a byte count to the named statistic.

Uses a formatter that formats values as human-readable byte sizes.

Parameters
nameName of the statistic.
nbytesNumber of bytes to add.
Returns
The updated byte total.

◆ add_duration_stat()

Duration rapidsmpf::Statistics::add_duration_stat ( std::string const &  name,
Duration  seconds 
)

Adds a duration to the named statistic.

Uses a formatter that formats values as time durations in seconds.

Parameters
nameName of the statistic.
secondsDuration in seconds to add.
Returns
The updated total duration.

◆ add_stat()

double rapidsmpf::Statistics::add_stat ( std::string const &  name,
double  value,
Formatter const &  formatter = FormatterDefault 
)

Adds a numeric value to the named statistic.

Creates the statistic if it doesn't exist.

Parameters
nameName of the statistic.
valueValue to add.
formatterOptional formatter to use for this statistic.
Returns
Updated total value.

◆ clear()

void rapidsmpf::Statistics::clear ( )

Clears all statistics.

Memory profiling records are not cleared.

◆ create_memory_recorder()

MemoryRecorder rapidsmpf::Statistics::create_memory_recorder ( std::string  name)

Creates a scoped memory recorder for the given name.

If memory profiling is not enabled, returns a no-op recorder.

Parameters
nameName of the scope.
Returns
A MemoryRecorder instance.

◆ disabled()

static std::shared_ptr<Statistics> rapidsmpf::Statistics::disabled ( )
static

Returns a shared pointer to a disabled (no-op) Statistics instance.

Useful when you need to pass a Statistics reference but do not want to collect any data.

Returns
A shared pointer to a Statistics instance with tracking disabled.

◆ enabled()

bool rapidsmpf::Statistics::enabled ( ) const
inlinenoexcept

Checks if statistics tracking is enabled.

Returns
True if statistics tracking is active, otherwise False.

Definition at line 83 of file statistics.hpp.

◆ FormatterDefault()

static void rapidsmpf::Statistics::FormatterDefault ( std::ostream &  os,
std::size_t  count,
double  val 
)
static

Default formatter for statistics output (implements Formatter).

Prints the total value and, if count > 1, also prints the average.

Parameters
osOutput stream to write the formatted result to.
countNumber of updates to the statistic.
valAccumulated value.

◆ get_memory_records()

std::unordered_map<std::string, MemoryRecord> const& rapidsmpf::Statistics::get_memory_records ( ) const

Retrieves all memory profiling records stored by this instance.

Returns
A reference to a map from record name to memory usage data.

◆ get_stat()

Stat rapidsmpf::Statistics::get_stat ( std::string const &  name) const

Retrieves a statistic by name.

Parameters
nameName of the statistic.
Returns
The requested statistic.

◆ is_memory_profiling_enabled()

bool rapidsmpf::Statistics::is_memory_profiling_enabled ( ) const

Checks whether memory profiling is enabled.

Returns
True if memory profiling is active, otherwise False.

◆ list_stat_names()

std::vector<std::string> rapidsmpf::Statistics::list_stat_names ( ) const

Get the names of all statistics.

Returns
A vector of all statistic names.

◆ operator=()

Statistics& rapidsmpf::Statistics::operator= ( Statistics &&  o)
inlinenoexcept

Move assignment operator.

Parameters
oThe Statistics object to move from.
Returns
Reference to this updated instance.

Definition at line 72 of file statistics.hpp.

◆ report()

std::string rapidsmpf::Statistics::report ( std::string const &  header = "Statistics:") const

Generates a formatted report of all collected statistics.

Parameters
headerAn optional header to prepend to the report.
Returns
A string containing the formatted statistics.

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