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 | |
| enum class | Formatter : std::uint8_t { Default = 0 , Bytes , Duration , HitRate , MemoryThroughput , _Count } |
Identifies a predefined formatter used by report(). More... | |
Public Member Functions | |
| Statistics (bool enabled=true) | |
| Constructs a Statistics object without memory profiling. More... | |
| Statistics (RmmResourceAdaptor mr, std::shared_ptr< PinnedMemoryResource > pinned_mr=PinnedMemoryResource::Disabled) | |
| Constructs a Statistics object with memory profiling enabled. More... | |
| Statistics (Statistics const &)=delete | |
| Statistics & | operator= (Statistics const &)=delete |
| Statistics (Statistics &&)=delete | |
| Statistics & | operator= (Statistics &&)=delete |
| 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... | |
| std::shared_ptr< Statistics > | copy () const |
| Creates a deep copy of this Statistics object. More... | |
| std::vector< std::uint8_t > | serialize () const |
| Serializes the stats and report entries to a binary byte vector. 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... | |
| void | add_report_entry (std::string const &report_entry_name, std::initializer_list< std::string_view > stat_names, Formatter formatter) |
| Associate a formatter with one or more named statistics for report rendering. More... | |
| void | add_report_entry (std::string const &report_entry_name, std::vector< std::string > stat_names, Formatter formatter) |
| Associate a formatter with one or more named statistics for report rendering. 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, std::shared_ptr< PinnedMemoryResource > pinned_mr=PinnedMemoryResource::Disabled) |
| Construct from configuration options. More... | |
| static std::shared_ptr< Statistics > | disabled () |
| Returns a shared pointer to a disabled (no-op) Statistics instance. More... | |
| static std::shared_ptr< Statistics > | deserialize (std::span< std::uint8_t const > data) |
| Deserializes a Statistics object from a binary byte vector. More... | |
| static std::shared_ptr< Statistics > | merge (std::span< std::shared_ptr< Statistics > const > stats) |
| Merge a set of Statistics into a new 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 are pure numeric accumulators with no associated rendering information. Examples: "spill-time", "spill-bytes".report(), passed to add_report_entry(). An entry names one or more stats and a Formatter that selects how those stats are rendered. When the entry covers a single stat, the report entry name and stat name are typically identical. Example: "spill" (aggregating "spill-bytes" and "spill-time").Formatters are a fixed, predefined set (see Statistics::Formatter).
Definition at line 71 of file statistics.hpp.
|
strong |
Identifies a predefined formatter used by report().
Each formatter consumes a fixed number of Stat entries and renders them into a human-readable string.
Available formatters (examples):
stream-delay is the wall-clock gap between CPU submission and GPU execution of the operation: "1.2 GiB | 2.5 ms | 480 GiB/s | avg-stream-delay 10 us"_Count is an internal sentinel — always keep it last.
| Enumerator | |
|---|---|
| _Count | Sentinel; must remain last. |
Definition at line 99 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, |
| std::shared_ptr< PinnedMemoryResource > | pinned_mr = PinnedMemoryResource::Disabled |
||
| ) |
Constructs a Statistics object with memory profiling enabled.
Automatically enables both statistics and memory profiling.
| mr | The RMM resource adaptor used for memory profiling. |
| pinned_mr | Optional pinned host memory resource for profiling; defaults to PinnedMemoryResource::Disabled. |
| 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::Bytes report entry named name if no report entry already exists under that 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::Duration report entry named name if no report entry already exists under that name, then adds seconds to the named statistic.
| name | Name of the statistic. |
| seconds | Duration in seconds to add. |
| void rapidsmpf::Statistics::add_report_entry | ( | std::string const & | report_entry_name, |
| std::initializer_list< std::string_view > | stat_names, | ||
| Formatter | formatter | ||
| ) |
Associate a formatter with one or more named statistics for report rendering.
First-wins: if a report entry is already registered under report_entry_name, this call has no effect. The entry appears in report() as a single line; if any stat it references is missing, the line reads "No data collected".
| report_entry_name | Report entry name. |
| stat_names | Names of the stats this entry aggregates. Caller is responsible for passing the number of stats the chosen formatter expects; a mismatch surfaces as std::out_of_range when report() renders the entry. |
| formatter | Predefined formatter to render the entry with. |
| void rapidsmpf::Statistics::add_report_entry | ( | std::string const & | report_entry_name, |
| std::vector< std::string > | stat_names, | ||
| Formatter | formatter | ||
| ) |
Associate a formatter with one or more named statistics for report rendering.
First-wins: if a report entry is already registered under report_entry_name, this call has no effect. The entry appears in report() as a single line; if any stat it references is missing, the line reads "No data collected".
| report_entry_name | Report entry name. |
| stat_names | Names of the stats this entry aggregates. Caller is responsible for passing the number of stats the chosen formatter expects; a mismatch surfaces as std::out_of_range when report() renders the entry. |
| formatter | Predefined formatter to render the entry with. |
Overload for callers whose stat names come from a runtime container (e.g. the Python bindings).
| 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. Does not associate any formatter with the stat — use add_report_entry() (or a helper like add_bytes_stat()) for that.
| name | Name of the statistic. |
| value | Value to add. |
| void rapidsmpf::Statistics::clear | ( | ) |
Clears all statistics.
| std::shared_ptr<Statistics> rapidsmpf::Statistics::copy | ( | ) | const |
Creates a deep copy of this Statistics object.
| 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 |
Deserializes a Statistics object from a binary byte vector.
| data | The serialized statistics data. |
| std::invalid_argument | If the data is malformed or truncated. |
|
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 170 of file statistics.hpp.
|
static |
Construct from configuration options.
| mr | The RMM resource adaptor used for memory profiling. |
| options | Configuration options. |
| pinned_mr | Optional pinned host memory resource for profiling; defaults to PinnedMemoryResource::Disabled. |
| 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.
|
static |
Merge a set of Statistics into a new instance.
For each stat name present across the inputs, the result contains the summed count, summed value, and the maximum of the recorded maxima. The result's enabled() is true if any input is enabled. Memory records are not merged.
Report entries are unified by name. If multiple inputs contain the same report-entry name, their Formatter and stat_names must match; otherwise, this function throws std::invalid_argument to prevent silent rendering inconsistencies (especially across serialize/deserialize boundaries).
| stats | Non-empty span of non-null Statistics instances to merge. |
Statistics instance containing the merged data.| std::invalid_argument | If stats is empty, contains a null pointer, or if inputs disagree on the formatter or stat-name set for a shared report entry. |
| 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. |
| std::string rapidsmpf::Statistics::report | ( | std::string const & | header = "Statistics:" | ) | const |
Generates a formatted report of all collected statistics.
Every registered report entry always produces a line. If all the stats it references have been recorded, the entry's Formatter renders the values; otherwise the line reads "No data collected". Statistics not covered by any report entry are shown with Formatter::Default (raw numeric value, optionally annotated with the count). 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. |
| std::vector<std::uint8_t> rapidsmpf::Statistics::serialize | ( | ) | const |
Serializes the stats and report entries to a binary byte vector.
| 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). Formatter metadata is not emitted — use report() for the human-readable rendering.
| 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). |