Added method to get total system memory in MB.

This commit is contained in:
NissimHadar 2018-12-29 21:59:18 -08:00
parent 3a9214747a
commit 6debd996c5
2 changed files with 24 additions and 12 deletions

View file

@ -7,6 +7,8 @@
//
#include "PlatformInfoScriptingInterface.h"
# include <thread>
#ifdef Q_OS_WIN
#include <Windows.h>
#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

View file

@ -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