13 #include <rapidsmpf/rmm_resource_adaptor.hpp>
14 #include <rapidsmpf/utils.hpp>
64 : enabled_(o.enabled_), stats_{std::move(o.stats_)} {}
73 enabled_ = o.enabled_;
74 stats_ = std::move(o.stats_);
93 std::string
report(std::string
const& header =
"Statistics:")
const;
101 using Formatter = std::function<void(std::ostream&, std::size_t,
double)>;
133 return count_ == o.count() && value_ == o.value();
146 return value_ +=
value;
154 [[nodiscard]] std::size_t
count() const noexcept {
163 [[nodiscard]]
double value() const noexcept {
177 std::size_t count_{0};
201 std::string
const& name,
317 mutable std::mutex mutex_;
319 std::map<std::string, Stat> stats_;
320 std::unordered_map<std::string, MemoryRecord> memory_records_;
347 #define RAPIDSMPF_MEMORY_PROFILE(...) \
348 RAPIDSMPF_OVERLOAD_BY_ARG_COUNT( \
349 __VA_ARGS__, RAPIDSMPF_MEMORY_PROFILE_2, RAPIDSMPF_MEMORY_PROFILE_1 \
354 #define RAPIDSMPF_MEMORY_PROFILE_1(stats) RAPIDSMPF_MEMORY_PROFILE_2(stats, __func__)
357 #define RAPIDSMPF_MEMORY_PROFILE_2(stats, funcname) \
358 auto const RAPIDSMPF_CONCAT(_rapidsmpf_memory_recorder_, __LINE__) = \
359 ((rapidsmpf::detail::to_pointer(stats) \
360 && rapidsmpf::detail::to_pointer(stats) -> is_memory_profiling_enabled()) \
361 ? rapidsmpf::detail::to_pointer(stats)->create_memory_recorder( \
362 std::string(__FILE__) + ":" + RAPIDSMPF_STRINGIFY(__LINE__) + "(" \
363 + std::string(funcname) + ")" \
365 : rapidsmpf::Statistics::MemoryRecorder{})
A RMM memory resource adaptor tailored to RapidsMPF.
RAII-style object for scoped memory usage tracking.
MemoryRecorder(Statistics *stats, RmmResourceAdaptor *mr, std::string name)
Constructs an active MemoryRecorder.
MemoryRecorder(MemoryRecorder const &)=delete
Deleted copy and move constructors/assignments.
~MemoryRecorder()
Destructor.
MemoryRecorder()=default
Constructs a no-op MemoryRecorder (disabled state).
Represents a single tracked statistic.
Formatter const & formatter() const noexcept
Returns the formatter used by this statistic.
std::size_t count() const noexcept
Returns the number of updates applied to this statistic.
Stat(Formatter formatter)
Constructs a Stat with a specified formatter.
double add(double value)
Adds a value to this statistic.
double value() const noexcept
Returns the total accumulated value.
bool operator==(Stat const &o) const noexcept
Equality operator for Stat objects.
Track statistics across rapidsmpf operations.
std::string report(std::string const &header="Statistics:") const
Generates a formatted report of all collected statistics.
bool is_memory_profiling_enabled() const
Checks whether memory profiling is enabled.
Stat get_stat(std::string const &name) const
Retrieves a statistic by name.
double add_stat(std::string const &name, double value, Formatter const &formatter=FormatterDefault)
Adds a numeric value to the named statistic.
void clear()
Clears all statistics.
MemoryRecorder create_memory_recorder(std::string name)
Creates a scoped memory recorder for the given name.
static std::shared_ptr< Statistics > disabled()
Returns a shared pointer to a disabled (no-op) Statistics instance.
Statistics(RmmResourceAdaptor *mr)
Constructs a Statistics object with memory profiling enabled.
std::vector< std::string > list_stat_names() const
Get the names of all statistics.
Statistics(bool enabled=true)
Constructs a Statistics object without memory profiling.
static void FormatterDefault(std::ostream &os, std::size_t count, double val)
Default formatter for statistics output (implements Formatter).
std::size_t add_bytes_stat(std::string const &name, std::size_t nbytes)
Adds a byte count to the named statistic.
Duration add_duration_stat(std::string const &name, Duration seconds)
Adds a duration to the named statistic.
bool enabled() const noexcept
Checks if statistics tracking is enabled.
Statistics & operator=(Statistics &&o) noexcept
Move assignment operator.
std::function< void(std::ostream &, std::size_t, double)> Formatter
Type alias for a statistics formatting function.
std::unordered_map< std::string, MemoryRecord > const & get_memory_records() const
Retrieves all memory profiling records stored by this instance.
Memory statistics for a specific scope.
Holds memory profiling information for a named scope.
std::int64_t global_peak
Peak global memory usage during the scope.
ScopedMemoryRecord scoped
Scoped memory stats.
std::uint64_t num_calls
Number of times the scope was invoked.