From d20a0371259e6827e585dd91e0d1367624c8edf1 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 26 Nov 2017 16:11:07 +0300 Subject: [PATCH] Windows and RAM usage by current process --- Info.hpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/Info.hpp b/Info.hpp index 801c9e3..59e3cea 100644 --- a/Info.hpp +++ b/Info.hpp @@ -1,11 +1,25 @@ #include #include #include +#include #ifdef __linux__ #include #endif +#ifdef _WIN32 + #define COLUMBUS_PLATFORM_WINDOWS +#endif + +#ifdef _WIN64 + #define COLUMBUS_PLATFORM_WINDOWS +#endif + +#ifdef COLUMBUS_PLATFORM_WINDOWS + #include + #include +#endif + namespace Columbus { @@ -15,6 +29,8 @@ namespace Columbus float GetCPUTemperature(); unsigned long GetRAMSize(); unsigned long GetRAMFree(); + unsigned long GetRAMThis(); + int GetRAMUsage(); float GetGPUTemperature(); int GetCPUCount() @@ -35,6 +51,14 @@ namespace Columbus cpuinfo.close(); return counter; #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; + #endif + + return 0; } int GetCPUCacheSize() @@ -58,6 +82,12 @@ namespace Columbus cpuinfo.close(); return 0; #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + + #endif + + return 0; } int GetCPUUsage() @@ -67,6 +97,12 @@ namespace Columbus getloadavg(load, 3); return static_cast(load[0] * 100); #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + + #endif + + return 0; } float GetCPUTemperature() @@ -114,6 +150,12 @@ namespace Columbus return 0.0; #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + + #endif + + return 0; } unsigned long GetRAMSize() @@ -123,6 +165,15 @@ namespace Columbus if (sysinfo(&info) == -1) return 0; return info.totalram; #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(memInfo); + GlobalMemoryStatusEx(&memInfo); + return memInfo.ullTotalPhys / (1024 * 1024); + #endif + + return 0; } unsigned long GetRAMFree() @@ -132,6 +183,38 @@ namespace Columbus if (sysinfo(&info) == -1) return 0; return info.freeram; #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(memInfo); + GlobalMemoryStatusEx(&memInfo); + return memInfo.ullAvailPhys / (1024 * 1024); + #endif + + return 0; + } + + unsigned long GetRAMThis() + { + #ifdef COLUMBUS_PLATFORM_WINDOWS + PROCESS_MEMORY_COUNTERS meminfo; + GetProcessMemoryInfo(GetCurrentProcess(), &meminfo, sizeof(meminfo)); + return meminfo.WorkingSetSize / (1024 * 1024); + #endif + + return 0; + } + + int GetRAMUsage() + { + #ifdef COLUMBUS_PLATFORM_WINDOWS + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(memInfo); + GlobalMemoryStatusEx(&memInfo); + return memInfo.dwMemoryLoad; + #endif + + return 0; } float GetGPUTemperature() @@ -179,6 +262,8 @@ namespace Columbus return 0.0; #endif + + return 0; } }