diff --git a/libraries/platform/src/platform/backend/LinuxPlatform.cpp b/libraries/platform/src/platform/backend/LinuxPlatform.cpp index bf94436778..5c39ac5a4f 100644 --- a/libraries/platform/src/platform/backend/LinuxPlatform.cpp +++ b/libraries/platform/src/platform/backend/LinuxPlatform.cpp @@ -8,25 +8,24 @@ #include "LinuxPlatform.h" #include "../PlatformKeys.h" -#include + #include +#include +#include +#include + using namespace platform; -static void getLCpuId( uint32_t* p, uint32_t ax ) -{ +void LinuxInstance::enumerateCpu() { + json cpu = {}; -#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) - __asm __volatile - ( "movl %%ebx, %%esi\n\t" - "cpuid\n\t" - "xchgl %%ebx, %%esi" - : "=a" (p[0]), "=S" (p[1]), - "=c" (p[2]), "=d" (p[3]) - : "0" (ax) - ); -#endif + cpu[keys::cpu::vendor] = CPUIdent::Vendor(); + cpu[keys::cpu::model] = CPUIdent::Brand(); + cpu[keys::cpu::numCores] = std::thread::hardware_concurrency(); + + _cpu.push_back(cpu); } - +/* void LinuxInstance::enumerateCpu() { json cpu = {}; @@ -57,6 +56,7 @@ void LinuxInstance::enumerateCpu() { _cpu.push_back(cpu); } +*/ void LinuxInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); diff --git a/libraries/platform/src/platform/backend/MACOSPlatform.cpp b/libraries/platform/src/platform/backend/MACOSPlatform.cpp index e8a05bf0c2..6859500531 100644 --- a/libraries/platform/src/platform/backend/MACOSPlatform.cpp +++ b/libraries/platform/src/platform/backend/MACOSPlatform.cpp @@ -10,8 +10,9 @@ #include "../PlatformKeys.h" #include -#include #include +#include +#include #ifdef Q_OS_MAC #include @@ -21,6 +22,16 @@ using namespace platform; +void MACOSInstance::enumerateCpu() { + json cpu = {}; + + cpu[keys::cpu::vendor] = CPUIdent::Vendor(); + cpu[keys::cpu::model] = CPUIdent::Brand(); + cpu[keys::cpu::numCores] = std::thread::hardware_concurrency(); + + _cpu.push_back(cpu); +} +/* static void getCpuId( uint32_t* p, uint32_t ax ) { #ifdef Q_OS_MAC @@ -65,7 +76,7 @@ void MACOSInstance::enumerateCpu() { _cpu.push_back(cpu); } - +*/ void MACOSInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); json gpu = {}; diff --git a/libraries/platform/src/platform/backend/WINPlatform.cpp b/libraries/platform/src/platform/backend/WINPlatform.cpp index 0c15b7979b..e34d87d853 100644 --- a/libraries/platform/src/platform/backend/WINPlatform.cpp +++ b/libraries/platform/src/platform/backend/WINPlatform.cpp @@ -8,51 +8,25 @@ #include "WINPlatform.h" #include "../PlatformKeys.h" -#include - -#ifdef Q_OS_WIN -#include -#include -#endif #include #include +#include +#include +#ifdef Q_OS_WIN +#include +#endif using namespace platform; void WINInstance::enumerateCpu() { json cpu = {}; -#ifdef Q_OS_WIN - int CPUInfo[4] = { -1 }; - unsigned nExIds; - unsigned int i = 0; - char CPUBrandString[16]; - char CPUModelString[16]; - char CPUClockString[16]; - // 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 - if (i == 0x80000002) { - memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo)); - } else if (i == 0x80000003) { - memcpy(CPUModelString, CPUInfo, sizeof(CPUInfo)); - } else if (i == 0x80000004) { - memcpy(CPUClockString, CPUInfo, sizeof(CPUInfo)); - } - } - - cpu[keys::cpu::vendor] = CPUBrandString; - cpu[keys::cpu::model] = CPUModelString; - cpu[keys::cpu::clockSpeed] = CPUClockString; + cpu[keys::cpu::vendor] = CPUIdent::Vendor(); + cpu[keys::cpu::model] = CPUIdent::Brand(); cpu[keys::cpu::numCores] = std::thread::hardware_concurrency(); -#endif - + _cpu.push_back(cpu); } @@ -73,12 +47,12 @@ void WINInstance::enumerateGpu() { void WINInstance::enumerateMemory() { json ram = {}; -#ifdef Q_OS_WINDOWS +#ifdef Q_OS_WIN MEMORYSTATUSEX statex; statex.dwLength = sizeof(statex); GlobalMemoryStatusEx(&statex); int totalRam = statex.ullTotalPhys / 1024 / 1024; - ram[keys.memTotal] = totalRam; + ram[platform::keys::memTotal] = totalRam; #endif _memory.push_back(ram); } diff --git a/libraries/shared/src/CPUIdent.cpp b/libraries/shared/src/CPUIdent.cpp index 718b01b196..2545f0c56b 100644 --- a/libraries/shared/src/CPUIdent.cpp +++ b/libraries/shared/src/CPUIdent.cpp @@ -10,7 +10,46 @@ #include "CPUIdent.h" +#include + + #ifdef Q_OS_WIN +#include +void getCPUID(int32_t* p, int32_t ax) { + __cpuid(p, ax); +} + +#elif defined(Q_OS_MAC) +void getCPUID(int32_t* p, int32_t ax) { + __asm __volatile + ("movl %%ebx, %%esi\n\t" + "cpuid\n\t" + "xchgl %%ebx, %%esi" + : "=a" (p[0]), "=S" (p[1]), + "=c" (p[2]), "=d" (p[3]) + : "0" (ax) + ); +} + +#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) +void getCPUID(int32_t* p, int32_t ax) { + __asm __volatile + ("movl %%ebx, %%esi\n\t" + "cpuid\n\t" + "xchgl %%ebx, %%esi" + : "=a" (p[0]), "=S" (p[1]), + "=c" (p[2]), "=d" (p[3]) + : "0" (ax) + ); +} +#else +void getCPUID(int32_t* p, int32_t ax) { + if (p) { + memset(p, 0, 4*4); + } +} +#endif + const CPUIdent::CPUIdent_Internal CPUIdent::CPU_Rep; @@ -72,4 +111,86 @@ std::vector CPUIdent::getAllFeatures() { return features; }; -#endif + +CPUIdent::CPUIdent_Internal::CPUIdent_Internal() + : nIds_{ 0 }, + nExIds_{ 0 }, + isIntel_{ false }, + isAMD_{ false }, + f_1_ECX_{ 0 }, + f_1_EDX_{ 0 }, + f_7_EBX_{ 0 }, + f_7_ECX_{ 0 }, + f_81_ECX_{ 0 }, + f_81_EDX_{ 0 }, + data_{}, + extdata_{} + { + //int cpuInfo[4] = {-1}; + std::array cpui; + + // Calling __cpuid with 0x0 as the function_id argument + // gets the number of the highest valid function ID. + getCPUID(cpui.data(), 0); + nIds_ = cpui[0]; + + for (int i = 0; i <= nIds_; ++i) { + __cpuidex(cpui.data(), i, 0); + data_.push_back(cpui); + } + + // Capture vendor string + char vendor[0x20]; + memset(vendor, 0, sizeof(vendor)); + *reinterpret_cast(vendor) = data_[0][1]; + *reinterpret_cast(vendor + 4) = data_[0][3]; + *reinterpret_cast(vendor + 8) = data_[0][2]; + vendor_ = vendor; + if (vendor_ == "GenuineIntel") { + isIntel_ = true; + } + else if (vendor_ == "AuthenticAMD") { + isAMD_ = true; + } + + // load bitset with flags for function 0x00000001 + if (nIds_ >= 1) { + f_1_ECX_ = data_[1][2]; + f_1_EDX_ = data_[1][3]; + } + + // load bitset with flags for function 0x00000007 + if (nIds_ >= 7) { + f_7_EBX_ = data_[7][1]; + f_7_ECX_ = data_[7][2]; + } + + // Calling __cpuid with 0x80000000 as the function_id argument + // gets the number of the highest valid extended ID. + __cpuid(cpui.data(), 0x80000000); + nExIds_ = cpui[0]; + + char brand[0x40]; + memset(brand, 0, sizeof(brand)); + + for (int i = 0x80000000; i <= nExIds_; ++i) { + __cpuidex(cpui.data(), i, 0); + extdata_.push_back(cpui); + } + + // load bitset with flags for function 0x80000001 + if (nExIds_ >= 0x80000001) { + f_81_ECX_ = extdata_[1][2]; + f_81_EDX_ = extdata_[1][3]; + } + + // Interpret CPU brand string if reported + if (nExIds_ >= 0x80000004) { + memcpy(brand, extdata_[2].data(), sizeof(cpui)); + memcpy(brand + 16, extdata_[3].data(), sizeof(cpui)); + memcpy(brand + 32, extdata_[4].data(), sizeof(cpui)); + brand_ = brand; + } +} + + diff --git a/libraries/shared/src/CPUIdent.h b/libraries/shared/src/CPUIdent.h index 32668149f4..68653f9287 100644 --- a/libraries/shared/src/CPUIdent.h +++ b/libraries/shared/src/CPUIdent.h @@ -18,17 +18,11 @@ #ifndef hifi_CPUIdent_h #define hifi_CPUIdent_h -#include - #include #include #include #include -#ifdef Q_OS_WIN - -#include - class CPUIdent { // forward declarations @@ -109,85 +103,7 @@ private: class CPUIdent_Internal { public: - CPUIdent_Internal() - : nIds_ { 0 }, - nExIds_ { 0 }, - isIntel_ { false }, - isAMD_ { false }, - f_1_ECX_ { 0 }, - f_1_EDX_ { 0 }, - f_7_EBX_ { 0 }, - f_7_ECX_ { 0 }, - f_81_ECX_ { 0 }, - f_81_EDX_ { 0 }, - data_ {}, - extdata_ {} - { - //int cpuInfo[4] = {-1}; - std::array cpui; - - // Calling __cpuid with 0x0 as the function_id argument - // gets the number of the highest valid function ID. - __cpuid(cpui.data(), 0); - nIds_ = cpui[0]; - - for (int i = 0; i <= nIds_; ++i) { - __cpuidex(cpui.data(), i, 0); - data_.push_back(cpui); - } - - // Capture vendor string - char vendor[0x20]; - memset(vendor, 0, sizeof(vendor)); - *reinterpret_cast(vendor) = data_[0][1]; - *reinterpret_cast(vendor + 4) = data_[0][3]; - *reinterpret_cast(vendor + 8) = data_[0][2]; - vendor_ = vendor; - if (vendor_ == "GenuineIntel") { - isIntel_ = true; - } else if (vendor_ == "AuthenticAMD") { - isAMD_ = true; - } - - // load bitset with flags for function 0x00000001 - if (nIds_ >= 1) { - f_1_ECX_ = data_[1][2]; - f_1_EDX_ = data_[1][3]; - } - - // load bitset with flags for function 0x00000007 - if (nIds_ >= 7) { - f_7_EBX_ = data_[7][1]; - f_7_ECX_ = data_[7][2]; - } - - // Calling __cpuid with 0x80000000 as the function_id argument - // gets the number of the highest valid extended ID. - __cpuid(cpui.data(), 0x80000000); - nExIds_ = cpui[0]; - - char brand[0x40]; - memset(brand, 0, sizeof(brand)); - - for (int i = 0x80000000; i <= nExIds_; ++i) { - __cpuidex(cpui.data(), i, 0); - extdata_.push_back(cpui); - } - - // load bitset with flags for function 0x80000001 - if (nExIds_ >= 0x80000001) { - f_81_ECX_ = extdata_[1][2]; - f_81_EDX_ = extdata_[1][3]; - } - - // Interpret CPU brand string if reported - if (nExIds_ >= 0x80000004) { - memcpy(brand, extdata_[2].data(), sizeof(cpui)); - memcpy(brand + 16, extdata_[3].data(), sizeof(cpui)); - memcpy(brand + 32, extdata_[4].data(), sizeof(cpui)); - brand_ = brand; - } - }; + CPUIdent_Internal(); int nIds_; int nExIds_; @@ -204,9 +120,6 @@ private: std::vector> data_; std::vector> extdata_; }; - }; -#endif - #endif // hifi_CPUIdent_h diff --git a/scripts/developer/utilities/render/platform.qml b/scripts/developer/utilities/render/platform.qml index 1f7000bc57..775ad8e106 100644 --- a/scripts/developer/utilities/render/platform.qml +++ b/scripts/developer/utilities/render/platform.qml @@ -43,6 +43,15 @@ Rectangle { cpu.populateFromObjectProps(JSON.parse(PlatformInfo.getCPU(0))) } } + Prop.PropGroup { + id: memory + label: "Memory" + isUnfold: true + + Component.onCompleted: { + memory.populateFromObjectProps(JSON.parse(PlatformInfo.getMemory())) + } + } Prop.PropGroup { id: gpu label: "GPU"