diff --git a/include/util/meminfo.hpp b/include/util/meminfo.hpp index e20599751..deae3b8b7 100644 --- a/include/util/meminfo.hpp +++ b/include/util/meminfo.hpp @@ -2,6 +2,7 @@ #define MEMINFO_HPP #include "util/log.hpp" +#include #ifndef _WIN32 #include @@ -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: "; #endif // _WIN32 } } // namespace osrm::util -#endif +#endif \ No newline at end of file diff --git a/src/benchmarks/bench.cpp b/src/benchmarks/bench.cpp index 019ff6456..86b263a6b 100644 --- a/src/benchmarks/bench.cpp +++ b/src/benchmarks/bench.cpp @@ -16,8 +16,8 @@ #include "osrm/osrm.hpp" #include "osrm/status.hpp" +#include "util/meminfo.hpp" #include - #include #include #include @@ -655,6 +655,12 @@ try std::cerr << "Unknown benchmark: " << benchmarkToRun << std::endl; return EXIT_FAILURE; } + + std::cout << "Peak RAM: " << std::setprecision(3) + << static_cast(osrm::util::PeakRAMUsedInBytes()) / + static_cast((1024 * 1024)) + << "MB" << std::endl; + return EXIT_SUCCESS; } catch (const std::exception &e)