diff --git a/ColumbusInfo.hpp b/ColumbusInfo.hpp new file mode 100644 index 0000000..62c7bfc --- /dev/null +++ b/ColumbusInfo.hpp @@ -0,0 +1,65 @@ +#ifdef __linux + #define COLUMBUS_PLATFORM_LINUX + #include + #include +#endif + +#include + +namespace Columbus +{ + + class Info + { + public: + static unsigned int getCPUCount(); + + static unsigned long getRAMSize(); + static unsigned long getRAMFree(); + static int getRAMUsage(); + }; + + unsigned int Info::getCPUCount() + { + #ifdef COLUMBUS_PLATFORM_LINUX + return sysconf(_SC_NPROCESSORS_ONLN); + #endif + } + + unsigned long Info::getRAMSize() + { + #ifdef COLUMBUS_PLATFORM_LINUX + struct sysinfo info; + if (sysinfo(&info) == -1) return 0; + return info.totalram / (1024 * 1024); + #endif + } + + unsigned long Info::getRAMFree() + { + #ifdef COLUMBUS_PLATFORM_LINUX + struct sysinfo info; + if (sysinfo(&info) == -1) return 0; + return info.freeram / (1024 * 1024); + #endif + } + + int Info::getRAMUsage() + { + #ifdef COLUMBUS_PLATFORM_LINUX + struct sysinfo info; + if (sysinfo(&info) == -1) return 0; + float usage = static_cast(getRAMFree()) / static_cast(getRAMSize()); + return static_cast(100 - usage * 100); + #endif + } + +} + + +#undef COLUMBUS_PLATFORM_LINUX + + + + +