scoped_memory_record.hpp
1 
6 #pragma once
7 
8 #include <cstdint>
9 #include <type_traits>
10 
11 namespace rapidsmpf {
12 
24  [[nodiscard]] std::int64_t num_total_allocs() const noexcept;
25 
31  [[nodiscard]] std::int64_t num_current_allocs() const noexcept;
32 
40  [[nodiscard]] std::int64_t current() const noexcept;
41 
49  [[nodiscard]] std::int64_t total() const noexcept;
50 
59  [[nodiscard]] std::int64_t peak() const noexcept;
60 
66  [[nodiscard]] std::int64_t max() const noexcept;
67 
78  void record_allocation(std::int64_t nbytes);
79 
89  void record_deallocation(std::int64_t nbytes);
90 
113 
130 
131  private:
132  std::int64_t num_current_allocs_{0};
133  std::int64_t num_total_allocs_{0};
134  std::int64_t current_{0};
135  std::int64_t total_{0};
136  std::int64_t peak_{0};
137  std::int64_t max_{0};
138 };
139 
140 static_assert(
141  std::is_trivially_copyable_v<ScopedMemoryRecord>,
142  "ScopedMemoryRecord must be trivially copyable"
143 );
144 
145 } // namespace rapidsmpf
RAPIDS Multi-Processor interfaces.
Definition: backend.hpp:14
Memory statistics for a specific scope.
std::int64_t current() const noexcept
Returns the current memory usage in bytes.
ScopedMemoryRecord & add_subscope(ScopedMemoryRecord const &subscope)
Merge the memory statistics of a subscope into this record.
std::int64_t max() const noexcept
Returns the size of the largest single allocation (in bytes).
ScopedMemoryRecord & add_scope(ScopedMemoryRecord const &scope)
Merge the memory statistics of another scope into this one.
std::int64_t peak() const noexcept
Returns the peak memory usage (in bytes).
std::int64_t num_total_allocs() const noexcept
Returns the total number of allocations performed.
void record_allocation(std::int64_t nbytes)
Records a memory allocation event.
std::int64_t num_current_allocs() const noexcept
Returns the number of currently active (non-deallocated) allocations.
std::int64_t total() const noexcept
Returns the total number of bytes allocated.
void record_deallocation(std::int64_t nbytes)
Records a memory deallocation event.