CbmRoot
Loading...
Searching...
No Matches
MemoryLogger.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer] */
4
5#include "MemoryLogger.h"
6
8#include "System.h"
9
10using namespace cbm::algo;
11
12template<typename T>
14{
15 return bytes / (1024 * 1024);
16}
17
19{
20 size_t currentRSS = GetCurrentRSS();
21 size_t peakRSS = GetPeakRSS();
22
23 ptrdiff_t deltaRSS = currentRSS - mLastRSS;
24 float deltaPercent = 100.0f * deltaRSS / currentRSS;
25
26 L_(debug) << "Current memory usage: " << BytesToMB(currentRSS) << "MB (delta " << BytesToMB(deltaRSS) << "MB / "
27 << deltaPercent << "%)"
28 << ", peak: " << BytesToMB(peakRSS) << "MB";
29
30 mLastRSS = currentRSS;
31}
#define L_(level)
Memory logging.
System functions.
void Log()
Log the current memory usage.
T BytesToMB(T bytes) const
size_t GetCurrentRSS()
Get the current resident set size (pyhysical memory usage) of the process.
Definition System.cxx:15
size_t GetPeakRSS()
Get the peak resident set size (pyhysical memory usage) of the process.
Definition System.cxx:35