From edb3206a24e71a47fe994dce3569649356eec055 Mon Sep 17 00:00:00 2001 From: amerhifi Date: Fri, 10 May 2019 09:55:26 -0700 Subject: [PATCH] adding macos platform. Misisng display and cpu info --- interface/src/Application.cpp | 8 +-- libraries/platform/src/MACOSPlatform.cpp | 56 +++++++------------- libraries/platform/src/MACOSPlatform.h | 6 +-- libraries/platform/src/WINPlatform.cpp | 9 ++-- libraries/platform/src/platform.cpp | 65 +++++++++++------------- libraries/platform/src/platform.h | 20 ++++---- libraries/shared/src/GPUIdent.h | 2 +- 7 files changed, 73 insertions(+), 93 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 48c3ae594a..14a92adc7a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2495,10 +2495,10 @@ void Application::initPlatform() { platform::enumeratePlatform(); - nlohmann::json test = platform::getGraphics(0); - nlohmann::json test1 = platform::getProcessor(0); - nlohmann::json test2 = platform::getMemory(0); - nlohmann::json test3 = platform::getDisplay(0); + const nlohmann::json* test = platform::getGraphics(0); + const nlohmann::json* test1 = platform::getProcessor(0); + const nlohmann::json* test2 = platform::getMemory(0); + //const nlohmann::json* test3 = platform::getDisplay(0); } void Application::updateVerboseLogging() { diff --git a/libraries/platform/src/MACOSPlatform.cpp b/libraries/platform/src/MACOSPlatform.cpp index 775d996c39..fb83de1951 100644 --- a/libraries/platform/src/MACOSPlatform.cpp +++ b/libraries/platform/src/MACOSPlatform.cpp @@ -7,11 +7,11 @@ // #include "MACOSPlatform.h" -#include + #include #include #include - +#include using namespace platform; using namespace nlohmann; @@ -23,44 +23,26 @@ bool MACOSInstance::enumeratePlatform() { return true; } -void WINInstance::enumerateCpu() { +void MACOSInstance::enumerateCpu() { json *cpu= new json(); - 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)["brand"] = CPUBrandString; - (*cpu)["model"] = CPUModelString; - (*cpu)["clockSpeed"] = CPUClockString; - (*cpu)["numCores"] = getNumLogicalCores(); + + // (*cpu)["brand"] = ident->getName(); + // (*cpu)["model"] = CPUModelString; + // (*cpu)["clockSpeed"] = CPUClockString; + // (*cpu)["numCores"] = getNumLogicalCores(); _cpu.push_back(cpu); } -unsigned int WINInstance::getNumLogicalCores() { + + +unsigned int MACOSInstance::getNumLogicalCores() { return std::thread::hardware_concurrency(); } -void WINInstance::enumerateGpu() { +void MACOSInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); @@ -73,14 +55,12 @@ void WINInstance::enumerateGpu() { _display = ident->getOutput(); } -void WINInstance::enumerateRam() { +void MACOSInstance::enumerateRam() { json* ram = new json(); - - MEMORYSTATUSEX statex; - statex.dwLength = sizeof(statex); - GlobalMemoryStatusEx(&statex); - int totalRam = statex.ullTotalPhys / 1024 / 1024; - (*ram)["totalMem"] = totalRam; + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + + (*ram)["totalMem"] = pages * page_size;; _memory.push_back(ram); } diff --git a/libraries/platform/src/MACOSPlatform.h b/libraries/platform/src/MACOSPlatform.h index 66b74f2122..ff1a4818be 100644 --- a/libraries/platform/src/MACOSPlatform.h +++ b/libraries/platform/src/MACOSPlatform.h @@ -6,8 +6,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_WinPlatform_h -#define hifi_WinPlatform_h +#ifndef hifi_MACOSPlatform_h +#define hifi_MACOSPlatform_h #include "platform.h" #include @@ -30,4 +30,4 @@ namespace platform { } // namespace platform -#endif //hifi_winplatform_h \ No newline at end of file +#endif //hifi_winplatform_h diff --git a/libraries/platform/src/WINPlatform.cpp b/libraries/platform/src/WINPlatform.cpp index 21997a6fbe..0c7f3db9f6 100644 --- a/libraries/platform/src/WINPlatform.cpp +++ b/libraries/platform/src/WINPlatform.cpp @@ -7,8 +7,10 @@ // #include "WINPlatform.h" +#ifdef Q_OS_WINDOWS #include #include +#endif #include #include #include @@ -33,6 +35,7 @@ void WINInstance::enumerateCpu() { char CPUModelString[16]; char CPUClockString[16]; +#ifdef Q_OS_WINDOWS // Get the information associated with each extended ID. __cpuid(CPUInfo, 0x80000000); nExIds = CPUInfo[0]; @@ -53,7 +56,7 @@ void WINInstance::enumerateCpu() { (*cpu)["model"] = CPUModelString; (*cpu)["clockSpeed"] = CPUClockString; (*cpu)["numCores"] = getNumLogicalCores(); - +#endif _cpu.push_back(cpu); } @@ -76,12 +79,12 @@ void WINInstance::enumerateGpu() { void WINInstance::enumerateRam() { json* ram = new json(); - +#ifdef Q_OS_WINDOWS MEMORYSTATUSEX statex; statex.dwLength = sizeof(statex); GlobalMemoryStatusEx(&statex); int totalRam = statex.ullTotalPhys / 1024 / 1024; (*ram)["totalMem"] = totalRam; - +#endif _memory.push_back(ram); } diff --git a/libraries/platform/src/platform.cpp b/libraries/platform/src/platform.cpp index f0ff3a988a..7fd8e4f8ad 100644 --- a/libraries/platform/src/platform.cpp +++ b/libraries/platform/src/platform.cpp @@ -16,7 +16,7 @@ #endif #ifdef Q_OS_MACOS -#include "MACPlatform.h" +#include "MACOSPlatform.h" #endif #ifdef Q_OS_LINUX @@ -31,7 +31,10 @@ void platform::create() { #ifdef Q_OS_WIN _instance =new WINInstance(); - #elif Q_OS_MAC + #endif + + #ifdef Q_OS_MAC + _instance = new MACOSInstance(); #endif } @@ -39,45 +42,37 @@ void platform::destroy() { delete _instance; } -json Instance::getCPU(int index) { - assert(index < _cpu.size()); - - json result; - if (index >= _cpu.size()) - return result; + json* Instance::getCPU(int index) { + assert(index <(int) _cpu.size()); + if (index >= (int)_cpu.size()) + return nullptr; return _cpu.at(index); } //These are ripe for template.. will work on that next -json Instance::getMemory(int index) { - - assert(index < _memory.size()); - - json result; - if(index>= _memory.size()) - return result; +json* Instance::getMemory(int index) { + assert(index <(int) _memory.size()); + if(index >= (int)_memory.size()) + return nullptr; return _memory.at(index); } -json Instance::getGPU(int index) { - assert(index < _gpu.size()); - - json result; - if (index >= _gpu.size()) - return result; +json* Instance::getGPU(int index) { + assert(index <(int) _gpu.size()); + if (index >=(int) _gpu.size()) + return nullptr; return _gpu.at(index); } -json Instance::getDisplay(int index) { - assert(index < _display.size()); - - json result; - if (index >= _display.size()) - return result; +json* Instance::getDisplay(int index) { + assert(index <(int) _display.size()); + + if (index >=(int) _display.size()) + return nullptr; return _display.at(index); } @@ -123,7 +118,7 @@ int platform::getNumProcessor() { return _instance->getNumCPU(); } -json platform::getProcessor(int index) { +const json* platform::getProcessor(int index) { return _instance->getCPU(index); } @@ -131,7 +126,7 @@ int platform::getNumGraphics() { return _instance->getNumGPU(); } -nlohmann::json platform::getGraphics(int index) { +const json* platform::getGraphics(int index) { return _instance->getGPU(index); } @@ -139,15 +134,17 @@ int platform::getNumDisplay() { return _instance->getNumDisplay(); } -nlohmann::json platform::getDisplay(int index) { +const json* platform::getDisplay(int index) { return _instance->getDisplay(index); } -json platform::getMemory(int index) { - return _instance->getMemory(index); -} - int platform::getNumMemory() { return _instance->getNumMemory(); } +const json* platform::getMemory(int index) { + return _instance->getMemory(index); +} + + + diff --git a/libraries/platform/src/platform.h b/libraries/platform/src/platform.h index db78502fa4..9a5267211a 100644 --- a/libraries/platform/src/platform.h +++ b/libraries/platform/src/platform.h @@ -21,18 +21,18 @@ public: bool virtual enumeratePlatform() = 0; int getNumCPU() { return _cpu.size(); } - nlohmann::json getCPU(int index); + nlohmann::json* getCPU(int index); int getNumGPU() { return _gpu.size(); } - nlohmann::json getGPU(int index); + nlohmann::json* getGPU(int index); int getNumMemory() { return _memory.size(); } - nlohmann::json getMemory(int index); + nlohmann::json* getMemory(int index); int getNumDisplay() { return _display.size(); } - nlohmann::json getDisplay(int index); + nlohmann::json* getDisplay(int index); - ~Instance(); + virtual ~Instance(); protected: std::vector _cpu; @@ -49,17 +49,17 @@ void destroy(); bool enumeratePlatform(); int getNumProcessor(); -nlohmann::json getProcessor(int index); +const nlohmann::json* getProcessor(int index); int getNumGraphics(); -nlohmann::json getGraphics(int index); +const nlohmann::json* getGraphics(int index); int getNumDisplay(); -nlohmann::json getDisplay(int index); +const nlohmann::json* getDisplay(int index); int getNumMemory(); -nlohmann::json getMemory(int index); +const nlohmann::json* getMemory(int index); } // namespace platform -#endif // hifi_platform_h \ No newline at end of file +#endif // hifi_platform_h diff --git a/libraries/shared/src/GPUIdent.h b/libraries/shared/src/GPUIdent.h index 8bb3a33d44..eff215ca25 100644 --- a/libraries/shared/src/GPUIdent.h +++ b/libraries/shared/src/GPUIdent.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include class GPUIdent