Tracks 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::vector< Stat > const &)> |
| 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 | |
| Statistics & | operator= (Statistics const &)=delete |
| Statistics (Statistics &&o) noexcept | |
| Move constructor. More... | |
| Statistics & | operator= (Statistics &&o) noexcept |
| Move assignment operator. More... | |
| bool | enabled () const noexcept |
| Checks if statistics tracking is enabled. More... | |
| void | enable () noexcept |
| Enable statistics tracking for this instance. | |
| void | disable () noexcept |
| Disable statistics tracking for this instance. | |
| std::string | report (std::string const &header="Statistics:") const |
| Generates a formatted report of all collected statistics. More... | |
| void | write_json (std::ostream &os) const |
| Writes a JSON representation of all collected statistics to a stream. More... | |
| void | write_json (std::filesystem::path const &filepath) const |
| Writes a JSON report of all collected statistics to a file. More... | |
| Stat | get_stat (std::string const &name) const |
| Retrieves a statistic by name. More... | |
| void | add_stat (std::string const &name, double value) |
| Adds a numeric value to the named statistic. More... | |
| bool | exist_report_entry_name (std::string const &name) const |
| Check whether a report entry name already has a formatter registered. More... | |
| void | register_formatter (std::string const &name, Formatter formatter) |
| Register a formatter for a single named statistic. More... | |
| void | register_formatter (std::string const &report_entry_name, std::vector< std::string > const &stat_names, Formatter formatter) |
| Register a formatter that takes multiple named statistics. More... | |
| void | add_bytes_stat (std::string const &name, std::size_t nbytes) |
| Adds a byte count to the named statistic. More... | |
| void | add_duration_stat (std::string const &name, Duration seconds) |
| Adds a duration to the named statistic. More... | |
| void | record_copy (MemoryType src, MemoryType dst, std::size_t nbytes, StreamOrderedTiming &&timing) |
| Record byte count and wall-clock duration for a memory copy operation. More... | |
| void | record_alloc (MemoryType mem_type, std::size_t nbytes, StreamOrderedTiming &&timing) |
| Record size and wall-clock duration for a buffer allocation. 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< Statistics > | from_options (RmmResourceAdaptor *mr, config::Options options) |
| Construct from configuration options. More... | |
| static std::shared_ptr< Statistics > | disabled () |
| Returns a shared pointer to a disabled (no-op) Statistics instance. More... | |
Tracks statistics across rapidsmpf operations.
Two naming concepts are used throughout this class:
Stat accumulator, as passed to add_stat(), get_stat(), add_bytes_stat(), and add_duration_stat(). Stats can be accumulated and retrieved without registering a formatter. Examples: "spill-time", "spill-bytes".report(), passed to register_formatter(). An entry may aggregate one or more stats. For the single-stat overload of register_formatter(), the report entry name and stat name are identical. Example: "spill" (aggregating "spill-bytes" and "spill-time").Definition at line 62 of file statistics.hpp.
| using rapidsmpf::Statistics::Formatter = std::function<void(std::ostream&, std::vector<Stat> const&)> |
Type alias for a statistics formatting function.
The formatter receives all the named stats it declared interest in as a vector.
Definition at line 267 of file statistics.hpp.
| rapidsmpf::Statistics::Statistics | ( | bool | enabled = true | ) |
Constructs a Statistics object without memory profiling.
| enabled | If true, enables tracking of statistics. If false, all operations are no-ops. |
| rapidsmpf::Statistics::Statistics | ( | RmmResourceAdaptor * | mr | ) |
Constructs a Statistics object with memory profiling enabled.
Automatically enables both statistics and memory profiling.
| mr | Pointer to a memory resource used for memory profiling. Must remain valid for the lifetime of the returned object. |
| std::invalid_argument | If mr is the nullptr. |
|
inlinenoexcept |
Move constructor.
| o | The Statistics object to move from. |
Definition at line 116 of file statistics.hpp.
| void rapidsmpf::Statistics::add_bytes_stat | ( | std::string const & | name, |
| std::size_t | nbytes | ||
| ) |
Adds a byte count to the named statistic.
Registers a formatter that formats values as human-readable byte sizes if no formatter is already registered for name, then adds nbytes to the named statistic.
| name | Name of the statistic. |
| nbytes | Number of bytes to add. |
| void rapidsmpf::Statistics::add_duration_stat | ( | std::string const & | name, |
| Duration | seconds | ||
| ) |
Adds a duration to the named statistic.
Registers a formatter that formats values as time durations in seconds if no formatter is already registered for name, then adds seconds to the named statistic.
| name | Name of the statistic. |
| seconds | Duration in seconds to add. |
| void rapidsmpf::Statistics::add_stat | ( | std::string const & | name, |
| double | value | ||
| ) |
Adds a numeric value to the named statistic.
Creates the statistic if it doesn't exist.
| name | Name of the statistic. |
| value | Value to add. |
| void rapidsmpf::Statistics::clear | ( | ) |
Clears all statistics.
| 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.
| name | Name of the scope. |
|
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.
|
inlinenoexcept |
Checks if statistics tracking is enabled.
Definition at line 139 of file statistics.hpp.
| bool rapidsmpf::Statistics::exist_report_entry_name | ( | std::string const & | name | ) | const |
Check whether a report entry name already has a formatter registered.
Intended as a cheap pre-check before constructing arguments to register_formatter().
true for a given name it will never return false again, because formatters cannot be unregistered.| name | Report entry name to look up. |
name, otherwise false.
|
static |
Construct from configuration options.
| mr | Pointer to a memory resource used for memory profiling. Must remain valid for the lifetime of the returned object. |
| options | Configuration options. |
| std::unordered_map<std::string, MemoryRecord> const& rapidsmpf::Statistics::get_memory_records | ( | ) | const |
Retrieves all memory profiling records stored by this instance.
| Stat rapidsmpf::Statistics::get_stat | ( | std::string const & | name | ) | const |
Retrieves a statistic by name.
| name | Name of the statistic. |
| bool rapidsmpf::Statistics::is_memory_profiling_enabled | ( | ) | const |
Checks whether memory profiling is enabled.
| std::vector<std::string> rapidsmpf::Statistics::list_stat_names | ( | ) | const |
Get the names of all statistics.
|
inlinenoexcept |
Move assignment operator.
| o | The Statistics object to move from. |
Definition at line 127 of file statistics.hpp.
| void rapidsmpf::Statistics::record_alloc | ( | MemoryType | mem_type, |
| std::size_t | nbytes, | ||
| StreamOrderedTiming && | timing | ||
| ) |
Record size and wall-clock duration for a buffer allocation.
Records three statistics entries for "alloc-{memtype}":
"-bytes" — the number of bytes allocated."-time" — the allocation duration, recorded in stream order."-stream-delay" — time between CPU submission and GPU execution, recorded in stream order.All three entries are aggregated into a single combined report line showing total bytes, total time, throughput, and average stream delay.
| mem_type | Memory type of the allocation. |
| nbytes | Number of bytes allocated. |
| timing | A StreamOrderedTiming constructed just before the allocation was issued. Its stop_and_record() is called here. |
| void rapidsmpf::Statistics::record_copy | ( | MemoryType | src, |
| MemoryType | dst, | ||
| std::size_t | nbytes, | ||
| StreamOrderedTiming && | timing | ||
| ) |
Record byte count and wall-clock duration for a memory copy operation.
Records three statistics entries for "copy-{src}-to-{dst}":
"-bytes" — the number of bytes copied."-time" — the copy duration, recorded in stream order."-stream-delay" — time between CPU submission and GPU execution of the copy, recorded in stream order.All three entries are aggregated into a single combined report line under the name "copy-{src}-to-{dst}", showing total bytes, total time, bandwidth, and average stream delay.
| src | Source memory type. |
| dst | Destination memory type. |
| nbytes | Number of bytes copied. |
| timing | A StreamOrderedTiming that should be started just before the copy was enqueued on the stream. Its stop_and_record() is called here to enqueue the stop callback. |
| void rapidsmpf::Statistics::register_formatter | ( | std::string const & | name, |
| Formatter | formatter | ||
| ) |
Register a formatter for a single named statistic.
If a formatter is already registered under name, this call has no effect. The formatter is only invoked during report() if the named statistic has been recorded.
| name | Report entry name (also used as the stat name to collect). |
| formatter | Function used to format this statistic when reporting. |
| void rapidsmpf::Statistics::register_formatter | ( | std::string const & | report_entry_name, |
| std::vector< std::string > const & | stat_names, | ||
| Formatter | formatter | ||
| ) |
Register a formatter that takes multiple named statistics.
If a formatter is already registered under report_entry_name, this call has no effect. The formatter is invoked during report() only if all stats in stat_names have been recorded; if any are missing the entry reads "No data collected".
| report_entry_name | Report entry name. |
| stat_names | Names of the stats to collect and pass to the formatter. |
| formatter | Function called with all collected stats during reporting. |
| std::string rapidsmpf::Statistics::report | ( | std::string const & | header = "Statistics:" | ) | const |
Generates a formatted report of all collected statistics.
Every registered formatter always produces an entry. If all its required statistics have been recorded the formatter renders the values; otherwise the entry reads "No data collected". Statistics not covered by any formatter are shown as plain numeric values. All entries are sorted alphabetically.
record_copy()), all relevant CUDA streams must be synchronized before calling this method. Otherwise, some timing statistics may not yet have been recorded, causing entries to read "No data collected" or imprecise statistics.| header | Header line prepended to the report. |
| void rapidsmpf::Statistics::write_json | ( | std::filesystem::path const & | filepath | ) | const |
Writes a JSON report of all collected statistics to a file.
| filepath | Path to the output file. Created or overwritten. |
| std::ios_base::failure | If the file cannot be opened or writing fails. |
| void rapidsmpf::Statistics::write_json | ( | std::ostream & | os | ) | const |
Writes a JSON representation of all collected statistics to a stream.
Values are written as raw numbers (count, sum, max). Registered formatters, which produce human-readable strings such as "1.0 KiB" or "3.5 ms" in the text report, are not applied so that the output remains machine-parseable with consistent numeric types.
| os | Output stream to write to. |
| std::invalid_argument | If any stat name or memory record name contains characters that require JSON escaping (double quotes, backslashes, or ASCII control characters 0x00–0x1F). |