osrm-backend/include/util/meminfo.hpp

41 lines
778 B
C++
Raw Permalink Normal View History

#ifndef MEMINFO_HPP
#define MEMINFO_HPP
#include "util/log.hpp"
2024-07-25 15:27:37 -04:00
#include <cstddef>
#ifndef _WIN32
#include <sys/resource.h>
#endif
namespace osrm::util
{
2024-07-25 15:27:37 -04:00
inline size_t PeakRAMUsedInBytes()
{
#ifndef _WIN32
rusage usage;
getrusage(RUSAGE_SELF, &usage);
#ifdef __linux__
// Under linux, ru.maxrss is in kb
2024-07-25 15:27:37 -04:00
return usage.ru_maxrss * 1024;
#else // __linux__
// Under BSD systems (OSX), it's in bytes
2024-07-25 15:27:37 -04:00
return usage.ru_maxrss;
#endif // __linux__
2024-07-25 15:27:37 -04:00
#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
}
2022-12-20 12:00:11 -05:00
} // namespace osrm::util
2024-07-25 15:27:37 -04:00
#endif