82 lines
1.9 KiB
C++
82 lines
1.9 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "Host/SystemInfo.hpp"
|
|
#include "Base/Logger.hpp"
|
|
#include <iostream>
|
|
#include <Windows.h>
|
|
#include <Psapi.h>
|
|
|
|
namespace openVulkanoCpp
|
|
{
|
|
namespace
|
|
{
|
|
enum class SYS_MEM_TYPE { TOTAL_PHYS, AVAIL_PHYS };
|
|
|
|
size_t ReadSystemMemInfo(SYS_MEM_TYPE type)
|
|
{
|
|
MEMORYSTATUSEX status;
|
|
status.dwLength = sizeof(status);
|
|
if (GlobalMemoryStatusEx(&status))
|
|
{
|
|
switch (type)
|
|
{
|
|
case SYS_MEM_TYPE::TOTAL_PHYS: return status.ullTotalPhys;
|
|
case SYS_MEM_TYPE::AVAIL_PHYS: return status.ullAvailPhys;
|
|
}
|
|
}
|
|
Logger::PERF->error("Failed to get system RAM info");
|
|
return 0;
|
|
}
|
|
|
|
enum class APP_MEM_TYPE { VM_MAX, USED };
|
|
|
|
size_t ReadAppMemInfo(APP_MEM_TYPE type)
|
|
{
|
|
PROCESS_MEMORY_COUNTERS_EX counters;
|
|
if (GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&counters), sizeof(counters)))
|
|
{
|
|
switch(type)
|
|
{
|
|
case APP_MEM_TYPE::VM_MAX return counters.PeakWorkingSetSize;
|
|
case APP_MEM_TYPE::USED: return counters.PrivateUsage;
|
|
}
|
|
}
|
|
Logger::PERF->error("Failed to get process memory info");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
size_t SystemInfo::GetSystemRam()
|
|
{
|
|
return ReadSystemMemInfo(MEM_TYPE::TOTAL_PHYS);
|
|
}
|
|
|
|
size_t SystemInfo::GetSystemRamAvailable()
|
|
{
|
|
return ReadSystemMemInfo(MEM_TYPE::AVAIL_PHYS);
|
|
}
|
|
|
|
size_t SystemInfo::GetAppRamMax()
|
|
{
|
|
return std::min(GetSystemRam(), GetAppVirtualMemoryMax());
|
|
}
|
|
|
|
size_t SystemInfo::GetAppRamAvailable()
|
|
{
|
|
return std::min(GetSystemRamAvailable(), GetAppVirtualMemoryMax() - GetAppRamUsed());
|
|
}
|
|
|
|
size_t SystemInfo::GetAppRamUsed()
|
|
{
|
|
return ReadAppMemInfo(APP_MEM_TYPE::USED);
|
|
}
|
|
|
|
size_t SystemInfo::GetAppVirtualMemoryMax()
|
|
{
|
|
return ReadAppMemInfo(APP_MEM_TYPE::VM_MAX);
|
|
}
|
|
} |