util: support get_peak_rss on windows

This commit is contained in:
Tyler Wilding
2024-06-15 15:41:40 -04:00
parent 86979e3d06
commit d209766078
2 changed files with 17 additions and 6 deletions
+17 -5
View File
@@ -3,17 +3,29 @@
#include "common/common_types.h"
#include "common/log/log.h"
#ifdef __linux__
#ifdef _WIN32
// clang-format off
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <psapi.h>
// clang-format on
size_t get_peak_rss() {
HANDLE hProcess = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) {
return pmc.PeakWorkingSetSize;
} else {
return 0;
}
}
#else
#include <sys/resource.h>
size_t get_peak_rss() {
rusage x;
getrusage(RUSAGE_SELF, &x);
return x.ru_maxrss * 1024;
}
#else
size_t get_peak_rss() {
return 0;
}
-1
View File
@@ -3,7 +3,6 @@
#include <cstddef>
#include <string>
// Note: these are not implemented on windows and will return zero.
size_t get_peak_rss();
void setup_cpu_info();