Windows
parent
9e3612558f
commit
ef9dc92d4d
|
|
@ -1,9 +1,16 @@
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
#define COLUMBUS_PLATFORM_LINUX
|
#define COLUMBUS_PLATFORM_LINUX
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
namespace Columbus
|
namespace Columbus
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -11,6 +18,7 @@ namespace Columbus
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static unsigned int getCPUCount();
|
static unsigned int getCPUCount();
|
||||||
|
static unsigned int getCPUSpeed();
|
||||||
|
|
||||||
static unsigned long getRAMSize();
|
static unsigned long getRAMSize();
|
||||||
static unsigned long getRAMFree();
|
static unsigned long getRAMFree();
|
||||||
|
|
@ -22,6 +30,35 @@ namespace Columbus
|
||||||
#ifdef COLUMBUS_PLATFORM_LINUX
|
#ifdef COLUMBUS_PLATFORM_LINUX
|
||||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
SYSTEM_INFO sysinfo;
|
||||||
|
GetSystemInfo(&sysinfo);
|
||||||
|
return sysinfo.dwNumberOfProcessors;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Info::getCPUSpeed()
|
||||||
|
{
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
wchar_t Buffer[_MAX_PATH];
|
||||||
|
DWORD BufSize = _MAX_PATH;
|
||||||
|
DWORD dwMHz = _MAX_PATH;
|
||||||
|
HKEY hKey;
|
||||||
|
|
||||||
|
long lError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||||
|
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey);
|
||||||
|
|
||||||
|
if (lError != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lError, 0, Buffer, _MAX_PATH, 0);
|
||||||
|
wprintf(Buffer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
RegQueryValueEx(hKey, L"~MHz", NULL, NULL, (LPBYTE)&dwMHz, &BufSize);
|
||||||
|
return dwMHz;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long Info::getRAMSize()
|
unsigned long Info::getRAMSize()
|
||||||
|
|
@ -31,6 +68,13 @@ namespace Columbus
|
||||||
if (sysinfo(&info) == -1) return 0;
|
if (sysinfo(&info) == -1) return 0;
|
||||||
return info.totalram / (1024 * 1024);
|
return info.totalram / (1024 * 1024);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
MEMORYSTATUSEX memInfo;
|
||||||
|
memInfo.dwLength = sizeof(memInfo);
|
||||||
|
GlobalMemoryStatusEx(&memInfo);
|
||||||
|
return memInfo.ullTotalPhys / (1024 * 1024);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long Info::getRAMFree()
|
unsigned long Info::getRAMFree()
|
||||||
|
|
@ -40,6 +84,13 @@ namespace Columbus
|
||||||
if (sysinfo(&info) == -1) return 0;
|
if (sysinfo(&info) == -1) return 0;
|
||||||
return info.freeram / (1024 * 1024);
|
return info.freeram / (1024 * 1024);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
MEMORYSTATUSEX memInfo;
|
||||||
|
memInfo.dwLength = sizeof(memInfo);
|
||||||
|
GlobalMemoryStatusEx(&memInfo);
|
||||||
|
return memInfo.ullAvailPhys / (1024 * 1024);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int Info::getRAMUsage()
|
int Info::getRAMUsage()
|
||||||
|
|
@ -50,11 +101,21 @@ namespace Columbus
|
||||||
float usage = static_cast<float>(getRAMFree()) / static_cast<float>(getRAMSize());
|
float usage = static_cast<float>(getRAMFree()) / static_cast<float>(getRAMSize());
|
||||||
return static_cast<int>(100 - usage * 100);
|
return static_cast<int>(100 - usage * 100);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLUMBUS_PLATFORM_WINDOWS
|
||||||
|
MEMORYSTATUSEX memInfo;
|
||||||
|
memInfo.dwLength = sizeof(memInfo);
|
||||||
|
GlobalMemoryStatusEx(&memInfo);
|
||||||
|
return memInfo.dwMemoryLoad;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#undef COLUMBUS_PLATFORM_WINDOWS
|
||||||
#undef COLUMBUS_PLATFORM_LINUX
|
#undef COLUMBUS_PLATFORM_LINUX
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue