13 #include <unordered_map>
71 struct MemoryStatistics {
74 int64_t count_malloc_ = 0;
75 int64_t count_free_ = 0;
76 std::unordered_map<void*, size_t> active_allocations_;
84 bool print_at_program_end_ =
true;
87 bool print_at_malloc_free_ =
false;
89 std::mutex statistics_mutex_;
90 std::map<Device, MemoryStatistics> statistics_;
@ None
No statistics are printed.
@ All
Statistics for all used devices are printed.
MemoryManagerStatistic & operator=(MemoryManagerStatistic &)=delete
void SetPrintAtMallocFree(bool print)
Enables or disables printing at each malloc and free.
~MemoryManagerStatistic()
void Print() const
Prints statistics for all recorded devices depending on the print level.
void SetPrintLevel(PrintLevel level)
Sets the level of provided information for printing.
void Reset()
Resets the statistics.
void CountFree(void *ptr, const Device &device)
static MemoryManagerStatistic & GetInstance()
void CountMalloc(void *ptr, size_t byte_size, const Device &device)
Adds the given allocation to the statistics.
MemoryManagerStatistic(const MemoryManagerStatistic &)=delete
void SetPrintAtProgramEnd(bool print)
Generic file read and write utility for python interface.