Windows and RAM usage by current process
parent
9053916152
commit
d20a037125
85
Info.hpp
85
Info.hpp
|
|
@ -1,11 +1,25 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN64
|
||||||
|
#define COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#include <psapi.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Columbus
|
namespace Columbus
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -15,6 +29,8 @@ namespace Columbus
|
||||||
float GetCPUTemperature();
|
float GetCPUTemperature();
|
||||||
unsigned long GetRAMSize();
|
unsigned long GetRAMSize();
|
||||||
unsigned long GetRAMFree();
|
unsigned long GetRAMFree();
|
||||||
|
unsigned long GetRAMThis();
|
||||||
|
int GetRAMUsage();
|
||||||
float GetGPUTemperature();
|
float GetGPUTemperature();
|
||||||
|
|
||||||
int GetCPUCount()
|
int GetCPUCount()
|
||||||
|
|
@ -35,6 +51,14 @@ namespace Columbus
|
||||||
cpuinfo.close();
|
cpuinfo.close();
|
||||||
return counter;
|
return counter;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
SYSTEM_INFO sysinfo;
|
||||||
|
GetSystemInfo(&sysinfo);
|
||||||
|
return sysinfo.dwNumberOfProcessors;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetCPUCacheSize()
|
int GetCPUCacheSize()
|
||||||
|
|
@ -58,6 +82,12 @@ namespace Columbus
|
||||||
cpuinfo.close();
|
cpuinfo.close();
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetCPUUsage()
|
int GetCPUUsage()
|
||||||
|
|
@ -67,6 +97,12 @@ namespace Columbus
|
||||||
getloadavg(load, 3);
|
getloadavg(load, 3);
|
||||||
return static_cast<int>(load[0] * 100);
|
return static_cast<int>(load[0] * 100);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetCPUTemperature()
|
float GetCPUTemperature()
|
||||||
|
|
@ -114,6 +150,12 @@ namespace Columbus
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long GetRAMSize()
|
unsigned long GetRAMSize()
|
||||||
|
|
@ -123,6 +165,15 @@ namespace Columbus
|
||||||
if (sysinfo(&info) == -1) return 0;
|
if (sysinfo(&info) == -1) return 0;
|
||||||
return info.totalram;
|
return info.totalram;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
MEMORYSTATUSEX memInfo;
|
||||||
|
memInfo.dwLength = sizeof(memInfo);
|
||||||
|
GlobalMemoryStatusEx(&memInfo);
|
||||||
|
return memInfo.ullTotalPhys / (1024 * 1024);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long GetRAMFree()
|
unsigned long GetRAMFree()
|
||||||
|
|
@ -132,6 +183,38 @@ namespace Columbus
|
||||||
if (sysinfo(&info) == -1) return 0;
|
if (sysinfo(&info) == -1) return 0;
|
||||||
return info.freeram;
|
return info.freeram;
|
||||||
#endif
|
#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()
|
float GetGPUTemperature()
|
||||||
|
|
@ -179,6 +262,8 @@ namespace Columbus
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue