Measure peak RAM in benchmarks (#6995)

This commit is contained in:
Siarhei Fedartsou
2024-07-25 21:27:37 +02:00
committed by GitHub
parent 43afec3b39
commit 7802f86bd6
2 changed files with 21 additions and 5 deletions
+14 -4
View File
@@ -2,6 +2,7 @@
#define MEMINFO_HPP
#include "util/log.hpp"
#include <cstddef>
#ifndef _WIN32
#include <sys/resource.h>
@@ -10,22 +11,31 @@
namespace osrm::util
{
inline void DumpMemoryStats()
inline size_t PeakRAMUsedInBytes()
{
#ifndef _WIN32
rusage usage;
getrusage(RUSAGE_SELF, &usage);
#ifdef __linux__
// Under linux, ru.maxrss is in kb
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss * 1024;
return usage.ru_maxrss * 1024;
#else // __linux__
// Under BSD systems (OSX), it's in bytes
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss;
return usage.ru_maxrss;
#endif // __linux__
#else // _WIN32
return 0;
#endif // _WIN32
}
inline void DumpMemoryStats()
{
#ifndef _WIN32
util::Log() << "RAM: peak bytes used: " << PeakRAMUsedInBytes();
#else // _WIN32
util::Log() << "RAM: peak bytes used: <not implemented on Windows>";
#endif // _WIN32
}
} // namespace osrm::util
#endif
#endif