From 6debd996c5a7d02c8e19bec3e28146661e064955 Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Sat, 29 Dec 2018 21:59:18 -0800 Subject: [PATCH] Added method to get total system memory in MB. --- .../PlatformInfoScriptingInterface.cpp | 21 ++++++++++++------- .../PlatformInfoScriptingInterface.h | 15 +++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/interface/src/scripting/PlatformInfoScriptingInterface.cpp b/interface/src/scripting/PlatformInfoScriptingInterface.cpp index 647262c547..3ffb00e4b8 100644 --- a/interface/src/scripting/PlatformInfoScriptingInterface.cpp +++ b/interface/src/scripting/PlatformInfoScriptingInterface.cpp @@ -7,6 +7,8 @@ // #include "PlatformInfoScriptingInterface.h" +# include + #ifdef Q_OS_WIN #include #endif @@ -34,6 +36,7 @@ QString PlatformInfoScriptingInterface::getCPUBrand() { // Get the information associated with each extended ID. __cpuid(CPUInfo, 0x80000000); nExIds = CPUInfo[0]; + for (i = 0x80000000; i <= nExIds; ++i) { __cpuid(CPUInfo, i); // Interpret CPU brand string @@ -51,16 +54,18 @@ QString PlatformInfoScriptingInterface::getCPUBrand() { return "NOT IMPLEMENTED"; #endif } - ////MEMORYSTATUSEX statex; - ////statex.dwLength = sizeof (statex); - ////GlobalMemoryStatusEx(&statex); - ////cout << "Total System Memory: " << (statex.ullTotalPhys / 1024) / 1024 << "MB" << endl; -int PlatformInfoScriptingInterface::getNumCores() { +unsigned int PlatformInfoScriptingInterface::getNumLogicalCores() { + + return std::thread::hardware_concurrency(); +} + +int PlatformInfoScriptingInterface::getTotalSystemMemoryMB() { #ifdef Q_OS_WIN - SYSTEM_INFO sysInfo; - GetSystemInfo(&sysInfo); - return sysInfo.dwNumberOfProcessors; + MEMORYSTATUSEX statex; + statex.dwLength = sizeof (statex); + GlobalMemoryStatusEx(&statex); + return statex.ullTotalPhys / 1024 / 1024; #else return -1; #endif diff --git a/interface/src/scripting/PlatformInfoScriptingInterface.h b/interface/src/scripting/PlatformInfoScriptingInterface.h index 47c8401455..f0b8122fa5 100644 --- a/interface/src/scripting/PlatformInfoScriptingInterface.h +++ b/interface/src/scripting/PlatformInfoScriptingInterface.h @@ -34,11 +34,18 @@ public slots: QString getCPUBrand(); /**jsdoc - * Returns the number of CPU cores - *function PlatformInfo.getNumCores() - * @returns {int} number of CPU cores + * Returns the number of logical CPU cores + *function PlatformInfo.getNumLogicalCores() + * @returns {int} number of logical CPU cores */ - int getNumCores(); + unsigned int getNumLogicalCores(); + + /**jsdoc + * Returns the total system memory in megabyte + *function PlatformInfo.getTotalSystemMemory() + * @returns {int} size of memory in megabytes + */ + int getTotalSystemMemoryMB(); }; #endif // hifi_PlatformInfoScriptingInterface_h