mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Add getMemoryInfo helper function
This commit is contained in:
parent
1fa274a527
commit
0393777b03
2 changed files with 35 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "CPUIdent.h"
|
||||
#include <Psapi.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -843,3 +844,27 @@ void printSystemInformation() {
|
|||
(envVariables.contains(env) ? " = " + envVariables.value(env) : " NOT FOUND");
|
||||
}
|
||||
}
|
||||
|
||||
bool getMemoryInfo(MemoryInfo& info) {
|
||||
#ifdef Q_OS_WIN
|
||||
MEMORYSTATUSEX ms;
|
||||
ms.dwLength = sizeof(ms);
|
||||
if (!GlobalMemoryStatusEx(&ms)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
info.totalMemoryBytes = ms.ullTotalPhys;
|
||||
info.availMemoryBytes = ms.ullAvailPhys;
|
||||
info.usedMemoryBytes = ms.ullTotalPhys - ms.ullAvailPhys;
|
||||
|
||||
|
||||
PROCESS_MEMORY_COUNTERS_EX pmc;
|
||||
if (!GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmc), sizeof(pmc))) {
|
||||
return false;
|
||||
}
|
||||
info.processUsedMemoryBytes = pmc.PrivateUsage;
|
||||
info.processPeakUsedMemoryBytes = pmc.PeakPagefileUsage;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
|
@ -204,4 +204,14 @@ void disableQtBearerPoll();
|
|||
|
||||
void printSystemInformation();
|
||||
|
||||
struct MemoryInfo {
|
||||
uint64_t totalMemoryBytes;
|
||||
uint64_t availMemoryBytes;
|
||||
uint64_t usedMemoryBytes;
|
||||
uint64_t processUsedMemoryBytes;
|
||||
uint64_t processPeakUsedMemoryBytes;
|
||||
};
|
||||
|
||||
bool getMemoryInfo(MemoryInfo& info);
|
||||
|
||||
#endif // hifi_SharedUtil_h
|
||||
|
|
Loading…
Reference in a new issue