diff --git a/interface/src/scripting/PlatformInfoScriptingInterface.cpp b/interface/src/scripting/PlatformInfoScriptingInterface.cpp index 89d609810c..9a5a08503d 100644 --- a/interface/src/scripting/PlatformInfoScriptingInterface.cpp +++ b/interface/src/scripting/PlatformInfoScriptingInterface.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include + #ifdef Q_OS_WIN #include #elif defined Q_OS_MAC @@ -21,6 +24,17 @@ PlatformInfoScriptingInterface* PlatformInfoScriptingInterface::getInstance() { return &sharedInstance; } + +PlatformInfoScriptingInterface::PlatformInfoScriptingInterface() { + platform::create(); + if (!platform::enumeratePlatform()) { + } +} + +PlatformInfoScriptingInterface::~PlatformInfoScriptingInterface() { + platform::destroy(); +} + QString PlatformInfoScriptingInterface::getOperatingSystemType() { #ifdef Q_OS_WIN return "WINDOWS"; @@ -149,3 +163,52 @@ bool PlatformInfoScriptingInterface::isStandalone() { return qApp->property(hifi::properties::STANDALONE).toBool(); #endif } + +int PlatformInfoScriptingInterface::getNumCPUs() { + return platform::getNumCPUs(); +} + +QString PlatformInfoScriptingInterface::getCPU(int index) { + auto desc = platform::getCPU(index); + return QString(desc.dump().c_str()); +} + +int PlatformInfoScriptingInterface::getNumGPUs() { + return platform::getNumGPUs(); +} + +QString PlatformInfoScriptingInterface::getGPU(int index) { + auto desc = platform::getGPU(index); + return QString(desc.dump().c_str()); +} + +int PlatformInfoScriptingInterface::getNumDisplays() { + return platform::getNumDisplays(); +} + +QString PlatformInfoScriptingInterface::getDisplay(int index) { + auto desc = platform::getDisplay(index); + return QString(desc.dump().c_str()); +} + +QString PlatformInfoScriptingInterface::getMemory() { + auto desc = platform::getMemory(0); + return QString(desc.dump().c_str()); +} + +QString PlatformInfoScriptingInterface::getComputer() { + auto desc = platform::getComputer(); + return QString(desc.dump().c_str()); +} + + +PlatformInfoScriptingInterface::PlatformTier PlatformInfoScriptingInterface::getTierProfiled() { + return (PlatformInfoScriptingInterface::PlatformTier) platform::Profiler::profilePlatform(); +} + +QStringList PlatformInfoScriptingInterface::getPlatformTierNames() { + static const QStringList platformTierNames = { "UNKNWON", "LOW", "MID", "HIGH" }; + return platformTierNames; +} + + diff --git a/interface/src/scripting/PlatformInfoScriptingInterface.h b/interface/src/scripting/PlatformInfoScriptingInterface.h index c065f849f2..0ca9dbff1a 100644 --- a/interface/src/scripting/PlatformInfoScriptingInterface.h +++ b/interface/src/scripting/PlatformInfoScriptingInterface.h @@ -9,6 +9,7 @@ #ifndef hifi_PlatformInfoScriptingInterface_h #define hifi_PlatformInfoScriptingInterface_h +#include #include class QScriptValue; @@ -25,6 +26,20 @@ class QScriptValue; class PlatformInfoScriptingInterface : public QObject { Q_OBJECT + +public: + PlatformInfoScriptingInterface(); + virtual ~PlatformInfoScriptingInterface(); + + // Platform tier enum type + enum PlatformTier { + UNKNOWN = platform::Profiler::Tier::UNKNOWN, + LOW = platform::Profiler::Tier::LOW, + MID = platform::Profiler::Tier::MID, + HIGH = platform::Profiler::Tier::HIGH, + }; + Q_ENUM(PlatformTier); + public slots: /**jsdoc * @function PlatformInfo.getInstance @@ -98,6 +113,96 @@ public slots: * @returns {boolean} true if Interface is running on a stand-alone device, false if it isn't. */ bool isStandalone(); + + /**jsdoc + * Get the number of CPUs. + * @function PlatformInfo.getNumCPUs + * @returns {number} The number of CPUs detected on the hardware platform. + */ + int getNumCPUs(); + + /**jsdoc + * Get the description of the CPU at the index parameter + * expected fields are: + * - cpuVendor... + * @param index The index of the CPU of the platform + * @function PlatformInfo.getCPU + * @returns {string} The CPU description json field + */ + QString getCPU(int index); + + /**jsdoc + * Get the number of GPUs. + * @function PlatformInfo.getNumGPUs + * @returns {number} The number of GPUs detected on the hardware platform. + */ + int getNumGPUs(); + + /**jsdoc + * Get the description of the GPU at the index parameter + * expected fields are: + * - gpuVendor... + * @param index The index of the GPU of the platform + * @function PlatformInfo.getGPU + * @returns {string} The GPU description json field + */ + QString getGPU(int index); + + /**jsdoc + * Get the number of Displays. + * @function PlatformInfo.getNumDisplays + * @returns {number} The number of Displays detected on the hardware platform. + */ + int getNumDisplays(); + + /**jsdoc + * Get the description of the Display at the index parameter + * expected fields are: + * - DisplayVendor... + * @param index The index of the Display of the platform + * @function PlatformInfo.getDisplay + * @returns {string} The Display description json field + */ + QString getDisplay(int index); + + /**jsdoc + * Get the description of the Memory + * expected fields are: + * - MemoryVendor... + * @function PlatformInfo.getMemory + * @returns {string} The Memory description json field + */ + QString getMemory(); + + /**jsdoc + * Get the description of the Computer + * expected fields are: + * - ComputerVendor... + * @function PlatformInfo.getComputer + * @returns {string} The Computer description json field + */ + QString getComputer(); + + + /**jsdoc + * Get the Platform TIer profiled on startup of the Computer + * Platform Tier is an ineger/enum value: + * LOW = 0, MID = 1, HIGH = 2 + * @function PlatformInfo.getTierProfiled + * @returns {number} The Platform Tier profiled on startup. + */ + PlatformTier getTierProfiled(); + + /**jsdoc + * Get the Platform Tier possible Names as an array of strings + * Platform Tier is an ineger/enum value: + * LOW = 0, MID = 1, HIGH = 2 + * @function PlatformInfo.getPlatformTierNames + * @returns {string} The array of names matching the number returned from PlatformInfo.getTierProfiled + */ + QStringList getPlatformTierNames(); + + }; #endif // hifi_PlatformInfoScriptingInterface_h diff --git a/libraries/platform/CMakeLists.txt b/libraries/platform/CMakeLists.txt index 2d71babe6f..70f3157e1e 100644 --- a/libraries/platform/CMakeLists.txt +++ b/libraries/platform/CMakeLists.txt @@ -1,5 +1,7 @@ set(TARGET_NAME platform) -setup_hifi_library() +setup_hifi_library() link_hifi_libraries(shared) + +GroupSources("src") target_json() diff --git a/libraries/platform/src/platform.cpp b/libraries/platform/src/platform.cpp deleted file mode 100644 index 64bd536eee..0000000000 --- a/libraries/platform/src/platform.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// -// Created by Amer Cerkic 05/02/2019 -// Copyright 2019 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - - -#include "platform.h" - -#include - -#if defined(Q_OS_WIN) -#include "WINPlatform.h" -#elif defined(Q_OS_MAC) -#include "MACOSPlatform.h" -#elif defined(Q_OS_ANDROID) -#include "AndroidPlatform.h" -#elif defined(Q_OS_LINUX) -#include "LinuxPlatform.h" -#endif - -using namespace platform; - -Instance *_instance; - -void platform::create() { -#if defined(Q_OS_WIN) - _instance =new WINInstance(); -#elif defined(Q_OS_MAC) - _instance = new MACOSInstance(); -#elif defined(Q_OS_ANDROID) - _instance= new AndroidInstance(); -#elif defined(Q_OS_LINUX) - _instance= new LinuxInstance(); -#endif -} - -void platform::destroy() { - if(_instance) - delete _instance; -} - -bool platform::enumeratePlatform() { - return _instance->enumeratePlatform(); -} - -int platform::getNumCPU() { - return _instance->getNumCPU(); -} - -json platform::getCPU(int index) { - return _instance->getCPU(index); -} - -int platform::getNumGPU() { - return _instance->getNumGPU(); -} - -json platform::getGPU(int index) { - return _instance->getGPU(index); -} - -int platform::getNumDisplay() { - return _instance->getNumDisplay(); -} - -json platform::getDisplay(int index) { - return _instance->getDisplay(index); -} - -int platform::getNumMemory() { - return _instance->getNumMemory(); -} - -json platform::getMemory(int index) { - return _instance->getMemory(index); -} - -json platform::getComputer(){ - return _instance->getComputer(); -} diff --git a/libraries/platform/src/platform.h b/libraries/platform/src/platform/Platform.h similarity index 88% rename from libraries/platform/src/platform.h rename to libraries/platform/src/platform/Platform.h index 14ec5fa8b2..7f73ff4ff4 100644 --- a/libraries/platform/src/platform.h +++ b/libraries/platform/src/platform/Platform.h @@ -19,20 +19,20 @@ void create(); void destroy(); bool enumeratePlatform(); -int getNumCPU(); +int getNumCPUs(); json getCPU(int index); -int getNumGPU(); +int getNumGPUs(); json getGPU(int index); -int getNumDisplay(); +int getNumDisplays(); json getDisplay(int index); -int getNumMemory(); +int getNumMemories(); json getMemory(int index); json getComputer(); - + } // namespace platform #endif // hifi_platform_h diff --git a/libraries/platform/src/platform/PlatformKeys.h b/libraries/platform/src/platform/PlatformKeys.h new file mode 100644 index 0000000000..fd29b2ff7f --- /dev/null +++ b/libraries/platform/src/platform/PlatformKeys.h @@ -0,0 +1,57 @@ +// +// Created by Amer Cerkic 05/02/2019 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_platform_PlatformKeys_h +#define hifi_platform_PlatformKeys_h + +namespace platform { namespace keys{ + namespace cpu { + extern const char* vendor; + extern const char* vendor_Intel; + extern const char* vendor_AMD; + + extern const char* model; + extern const char* clockSpeed; + extern const char* numCores; + } + namespace gpu { + extern const char* vendor; + extern const char* vendor_NVIDIA; + extern const char* vendor_AMD; + extern const char* vendor_Intel; + + extern const char* model; + extern const char* videoMemory; + extern const char* driver; + } + namespace display { + extern const char* description; + extern const char* name; + extern const char* coordsLeft; + extern const char* coordsRight; + extern const char* coordsTop; + extern const char* coordsBottom; + } + extern const char* memTotal; + + namespace computer { + extern const char* OS; + extern const char* OS_WINDOWS; + extern const char* OS_MACOS; + extern const char* OS_LINUX; + extern const char* OS_ANDROID; + + extern const char* vendor; + extern const char* vendor_Apple; + + extern const char* model; + + extern const char* profileTier; + } + } } // namespace plaform::keys + +#endif diff --git a/libraries/platform/src/platform/Profiler.cpp b/libraries/platform/src/platform/Profiler.cpp new file mode 100644 index 0000000000..f77bbec46b --- /dev/null +++ b/libraries/platform/src/platform/Profiler.cpp @@ -0,0 +1,127 @@ +// +// Profiler.cpp +// libraries/platform/src/platform +// +// Created by Sam Gateau on 5/22/2019. +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "Profiler.h" + +#include "Platform.h" +#include "PlatformKeys.h" + +using namespace platform; + +const std::array Profiler::TierNames = {{ "UNKNOWN", "LOW", "MID", "HIGH" }}; + + +bool filterOnComputer(const platform::json& computer, Profiler::Tier& tier); +bool filterOnComputerMACOS(const platform::json& computer, Profiler::Tier& tier); +bool filterOnProcessors(const platform::json& computer, const platform::json& cpu, const platform::json& gpu, Profiler::Tier& tier); + +Profiler::Tier Profiler::profilePlatform() { + auto platformTier = Profiler::Tier::UNKNOWN; // unknown tier yet + + // first filter on the computer info and catch known models + auto computerInfo = platform::getComputer(); + if (filterOnComputer(computerInfo, platformTier)) { + return platformTier; + } + + // Not filtered yet, let s try to make sense of the cpu and gpu info + auto cpuInfo = platform::getCPU(0); + auto gpuInfo = platform::getGPU(0); + if (filterOnProcessors(computerInfo, cpuInfo, gpuInfo, platformTier)) { + return platformTier; + } + + // Default answer is + return Profiler::Tier::LOW; +} + +// tier filter on computer info +bool filterOnComputer(const platform::json& computer, Profiler::Tier& tier) { + if (computer.count(keys::computer::OS)) { + const auto os = computer[keys::computer::OS].get(); + if (os.compare(keys::computer::OS_MACOS) == 0) { + return filterOnComputerMACOS(computer, tier); + } + } + return false; +} + + +// tier filter on computer MACOS +bool filterOnComputerMACOS(const platform::json& computer, Profiler::Tier& tier) { + + // it s a macos computer, probably can tell from the model name: + if (computer.count(keys::computer::model)) { + const auto model = computer[keys::computer::model].get(); + if (model.find("MacBookAir") != std::string::npos) { + tier = Profiler::Tier::LOW; + return true; + } else if (model.find("MacBookPro") != std::string::npos) { + tier = Profiler::Tier::MID; + return true; + } else if (model.find("MacBook") != std::string::npos) { + tier = Profiler::Tier::LOW; + return true; + } + } + return false; +} + +bool filterOnProcessors(const platform::json& computer, const platform::json& cpu, const platform::json& gpu, Profiler::Tier& tier) { + // first filter on the number of cores, <= 4 means LOW + int numCores = 0; + std::string cpuVendor; + if (cpu.count(keys::cpu::numCores)) { + numCores = cpu[keys::cpu::numCores].get(); + if (numCores <= 4) { + tier = Profiler::Tier::LOW; + return true; + } + + cpuVendor = cpu[keys::cpu::vendor].get(); + } + + // enough cores to be mid or high + // let s look at the gpu + if (gpu.count(keys::gpu::vendor)) { + std::string gpuVendor = gpu[keys::gpu::vendor].get(); + std::string gpuModel = gpu[keys::gpu::model].get(); + + // intel integrated graphics + if (gpuVendor.find(keys::gpu::vendor_Intel) != std::string::npos) { + // go mid because GPU + tier = Profiler::Tier::MID; + return true; + } + // AMD gpu + else if (gpuVendor.find(keys::gpu::vendor_AMD) != std::string::npos) { + // TODO: Filter base on the model of AMD + // that is their integrated graphics, go low! + if (gpuModel.find("Vega 3") != std::string::npos) { + tier = Profiler::Tier::LOW; + return true; + } + + // go high because GPU + tier = Profiler::Tier::HIGH; + return true; + } + // NVIDIA gpu + else if (gpuVendor.find(keys::gpu::vendor_NVIDIA) != std::string::npos) { + // TODO: Filter base on the model of NV + // go high because GPU + tier = Profiler::Tier::HIGH; + return true; + } + } + + // Not able to profile + return false; +} \ No newline at end of file diff --git a/libraries/platform/src/platform/Profiler.h b/libraries/platform/src/platform/Profiler.h new file mode 100644 index 0000000000..fea0622c89 --- /dev/null +++ b/libraries/platform/src/platform/Profiler.h @@ -0,0 +1,34 @@ +// +// Profiler.h +// libraries/platform/src/platform +// +// Created by Sam Gateau on 5/22/2019. +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_platform_Profiler_h +#define hifi_platform_Profiler_h + +#include + +namespace platform { + +class Profiler { +public: + enum Tier { + UNKNOWN = 0, + LOW, + MID, + HIGH, + + NumTiers, // not a valid Tier + }; + static const std::array TierNames; + + static Tier profilePlatform(); +}; + +} +#endif diff --git a/libraries/platform/src/AndroidPlatform.cpp b/libraries/platform/src/platform/backend/AndroidPlatform.cpp similarity index 53% rename from libraries/platform/src/AndroidPlatform.cpp rename to libraries/platform/src/platform/backend/AndroidPlatform.cpp index f35674a984..49ac5079ee 100644 --- a/libraries/platform/src/AndroidPlatform.cpp +++ b/libraries/platform/src/platform/backend/AndroidPlatform.cpp @@ -7,38 +7,42 @@ // #include "AndroidPlatform.h" -#include "platformJsonKeys.h" +#include "../PlatformKeys.h" #include using namespace platform; void AndroidInstance::enumerateCpu() { json cpu; - cpu["cpuBrand"] = ""; - cpu["cpuModel"] = ""; - cpu["cpuClockSpeed"] = ""; - cpu["cpuNumCores"] = ""; + cpu[keys::cpu::vendor] = ""; + cpu[keys::cpu::model] = ""; + cpu[keys::cpu::clockSpeed] = ""; + cpu[keys::cpu::numCores] = 0; _cpu.push_back(cpu); } void AndroidInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); json gpu = {}; - gpu["gpuName"] = ident->getName().toUtf8().constData(); - gpu["gpuMemory"] = ident->getMemory(); - gpu["gpuDriver"] = ident->getDriver().toUtf8().constData(); - + gpu[keys::gpu::vendor] = ident->getName().toUtf8().constData(); + gpu[keys::gpu::model] = ident->getName().toUtf8().constData(); + gpu[keys::gpu::videoMemory] = ident->getMemory(); + gpu[keys::gpu::driver] = ident->getDriver().toUtf8().constData(); + _gpu.push_back(gpu); _display = ident->getOutput(); } void AndroidInstance::enumerateMemory() { json ram = {}; - ram["totalMemory"]=""; + ram[keys::memTotal]=0; _memory.push_back(ram); } void AndroidInstance::enumerateComputer(){ - //no implememntation at this time + _computer[keys::computer::OS] = keys::computer::OS_ANDROID; + _computer[keys::computer::vendor] = ""; + _computer[keys::computer::model] = ""; + } diff --git a/libraries/platform/src/AndroidPlatform.h b/libraries/platform/src/platform/backend/AndroidPlatform.h similarity index 95% rename from libraries/platform/src/AndroidPlatform.h rename to libraries/platform/src/platform/backend/AndroidPlatform.h index 66d80ca1ef..d1496383c0 100644 --- a/libraries/platform/src/AndroidPlatform.h +++ b/libraries/platform/src/platform/backend/AndroidPlatform.h @@ -9,7 +9,7 @@ #ifndef hifi_AndroidPlatform_h #define hifi_AndroidPlatform_h -#include "platformInstance.h" +#include "PlatformInstance.h" namespace platform { class AndroidInstance : public Instance { diff --git a/libraries/platform/src/LinuxPlatform.cpp b/libraries/platform/src/platform/backend/LinuxPlatform.cpp similarity index 71% rename from libraries/platform/src/LinuxPlatform.cpp rename to libraries/platform/src/platform/backend/LinuxPlatform.cpp index e376a45165..bf94436778 100644 --- a/libraries/platform/src/LinuxPlatform.cpp +++ b/libraries/platform/src/platform/backend/LinuxPlatform.cpp @@ -7,7 +7,7 @@ // #include "LinuxPlatform.h" -#include "platformJsonKeys.h" +#include "../PlatformKeys.h" #include #include using namespace platform; @@ -49,11 +49,11 @@ void LinuxInstance::enumerateCpu() { memcpy(CPUClockString, cpuInfo, sizeof(cpuInfo)); } } - - cpu["cpuBrand"] = CPUBrandString; - cpu["cpuModel"] = CPUModelString; - cpu["cpuClockSpeed"] = CPUClockString; - cpu["cpuNumCores"] = std::thread::hardware_concurrency(); + + cpu[keys::cpu::vendor] = CPUBrandString; + cpu[keys::cpu::model] = CPUModelString; + cpu[keys::cpu::clockSpeed] = CPUClockString; + cpu[keys::cpu::numCores] = std::thread::hardware_concurrency(); _cpu.push_back(cpu); } @@ -61,9 +61,10 @@ void LinuxInstance::enumerateCpu() { void LinuxInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); json gpu = {}; - gpu["gpuName"] = ident->getName().toUtf8().constData(); - gpu["gpuMemory"] = ident->getMemory(); - gpu["gpuDriver"] = ident->getDriver().toUtf8().constData(); + gpu[keys::gpu::vendor] = ident->getName().toUtf8().constData(); + gpu[keys::gpu::model] = ident->getName().toUtf8().constData(); + gpu[keys::gpu::videoMemory] = ident->getMemory(); + gpu[keys::gpu::driver] = ident->getDriver().toUtf8().constData(); _gpu.push_back(gpu); _display = ident->getOutput(); @@ -71,12 +72,16 @@ void LinuxInstance::enumerateGpu() { void LinuxInstance::enumerateMemory() { json ram = {}; - ram["totalMemory"]=""; + ram[keys::memTotal]=0; _memory.push_back(ram); } void LinuxInstance::enumerateComputer(){ + + _computer[keys::computer::OS] = keys::computer::OS_LINUX; + _computer[keys::computer::vendor] = ""; + _computer[keys::computer::model] = ""; //no implememntation at this time } diff --git a/libraries/platform/src/LinuxPlatform.h b/libraries/platform/src/platform/backend/LinuxPlatform.h similarity index 95% rename from libraries/platform/src/LinuxPlatform.h rename to libraries/platform/src/platform/backend/LinuxPlatform.h index 63db8557f0..1629101f41 100644 --- a/libraries/platform/src/LinuxPlatform.h +++ b/libraries/platform/src/platform/backend/LinuxPlatform.h @@ -9,7 +9,7 @@ #ifndef hifi_LinuxPlatform_h #define hifi_LinuxPlatform_h -#include "platformInstance.h" +#include "PlatformInstance.h" namespace platform { class LinuxInstance : public Instance { diff --git a/libraries/platform/src/MACOSPlatform.cpp b/libraries/platform/src/platform/backend/MACOSPlatform.cpp similarity index 74% rename from libraries/platform/src/MACOSPlatform.cpp rename to libraries/platform/src/platform/backend/MACOSPlatform.cpp index 7081044879..e8a05bf0c2 100644 --- a/libraries/platform/src/MACOSPlatform.cpp +++ b/libraries/platform/src/platform/backend/MACOSPlatform.cpp @@ -7,7 +7,7 @@ // #include "MACOSPlatform.h" -#include "platformJsonKeys.h" +#include "../PlatformKeys.h" #include #include @@ -58,10 +58,10 @@ void MACOSInstance::enumerateCpu() { } } - cpu["cpuBrand"] = CPUBrandString; - cpu["cpuModel"] = CPUModelString; - cpu["cpuClockSpeed"] = CPUClockString; - cpu["cpuNumCores"] = std::thread::hardware_concurrency(); + cpu[keys::cpu::vendor] = CPUBrandString; + cpu[keys::cpu::model] = CPUModelString; + cpu[keys::cpu::clockSpeed] = CPUClockString; + cpu[keys::cpu::numCores] = std::thread::hardware_concurrency(); _cpu.push_back(cpu); } @@ -69,9 +69,10 @@ void MACOSInstance::enumerateCpu() { void MACOSInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); json gpu = {}; - gpu["gpuName"] = ident->getName().toUtf8().constData(); - gpu["gpuMemory"] = ident->getMemory(); - gpu["gpuDriver"] = ident->getDriver().toUtf8().constData(); + gpu[keys::gpu::vendor] = ident->getName().toUtf8().constData(); + gpu[keys::gpu::model] = ident->getName().toUtf8().constData(); + gpu[keys::gpu::videoMemory] = ident->getMemory(); + gpu[keys::gpu::driver] = ident->getDriver().toUtf8().constData(); _gpu.push_back(gpu); _display = ident->getOutput(); @@ -84,21 +85,24 @@ void MACOSInstance::enumerateMemory() { #ifdef Q_OS_MAC long pages = sysconf(_SC_PHYS_PAGES); long page_size = sysconf(_SC_PAGE_SIZE); - ram["totalMemory"] = pages * page_size;; + ram[keys::memTotal] = pages * page_size; #endif _memory.push_back(ram); } void MACOSInstance::enumerateComputer(){ + _computer[keys::computer::OS] = keys::computer::OS_MACOS; + _computer[keys::computer::vendor] = keys::computer::vendor_Apple; + #ifdef Q_OS_MAC - + //get system name size_t len=0; sysctlbyname("hw.model",NULL, &len, NULL, 0); char* model = (char *) malloc(sizeof(char)*len+1); sysctlbyname("hw.model", model, &len, NULL,0); - _computer["computerModel"]=std::string(model); + _computer[keys::computer::model]=std::string(model); free(model); diff --git a/libraries/platform/src/MACOSPlatform.h b/libraries/platform/src/platform/backend/MACOSPlatform.h similarity index 95% rename from libraries/platform/src/MACOSPlatform.h rename to libraries/platform/src/platform/backend/MACOSPlatform.h index 04b8621698..1c66f5d742 100644 --- a/libraries/platform/src/MACOSPlatform.h +++ b/libraries/platform/src/platform/backend/MACOSPlatform.h @@ -9,7 +9,7 @@ #ifndef hifi_MACOSPlatform_h #define hifi_MACOSPlatform_h -#include "platformInstance.h" +#include "PlatformInstance.h" namespace platform { class MACOSInstance : public Instance { diff --git a/libraries/platform/src/platform/backend/Platform.cpp b/libraries/platform/src/platform/backend/Platform.cpp new file mode 100644 index 0000000000..8e9fda30ed --- /dev/null +++ b/libraries/platform/src/platform/backend/Platform.cpp @@ -0,0 +1,130 @@ +// +// Created by Amer Cerkic 05/02/2019 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#include "../Platform.h" +#include "../PlatformKeys.h" + +namespace platform { namespace keys { + namespace cpu { + const char* vendor = "vendor"; + const char* vendor_Intel = "Intel"; + const char* vendor_AMD = "AMD"; + + const char* model = "model"; + const char* clockSpeed = "clockSpeed"; + const char* numCores = "numCores"; + } + namespace gpu { + const char* vendor = "vendor"; + const char* vendor_NVIDIA = "NVIDIA"; + const char* vendor_AMD = "AMD"; + const char* vendor_Intel = "Intel"; + + const char* model = "model"; + const char* videoMemory = "videoMemory"; + const char* driver = "driver"; + } + namespace display { + const char* description = "description"; + const char* name = "deviceName"; + const char* coordsLeft = "coordinatesleft"; + const char* coordsRight = "coordinatesright"; + const char* coordsTop = "coordinatestop"; + const char* coordsBottom = "coordinatesbottom"; + } + const char* memTotal = "memTotal"; + + namespace computer { + const char* OS = "OS"; + const char* OS_WINDOWS = "WINDOWS"; + const char* OS_MACOS = "MACOS"; + const char* OS_LINUX = "LINUX"; + const char* OS_ANDROID = "ANDROID"; + + const char* vendor = "vendor"; + const char* vendor_Apple = "Apple"; + + const char* model = "model"; + + const char* profileTier = "profileTier"; + } +}} + +#include + +#if defined(Q_OS_WIN) +#include "WINPlatform.h" +#elif defined(Q_OS_MAC) +#include "MACOSPlatform.h" +#elif defined(Q_OS_ANDROID) +#include "AndroidPlatform.h" +#elif defined(Q_OS_LINUX) +#include "LinuxPlatform.h" +#endif + +using namespace platform; + +Instance *_instance; + +void platform::create() { +#if defined(Q_OS_WIN) + _instance =new WINInstance(); +#elif defined(Q_OS_MAC) + _instance = new MACOSInstance(); +#elif defined(Q_OS_ANDROID) + _instance= new AndroidInstance(); +#elif defined(Q_OS_LINUX) + _instance= new LinuxInstance(); +#endif +} + +void platform::destroy() { + if(_instance) + delete _instance; +} + +bool platform::enumeratePlatform() { + return _instance->enumeratePlatform(); +} + +int platform::getNumCPUs() { + return _instance->getNumCPUs(); +} + +json platform::getCPU(int index) { + return _instance->getCPU(index); +} + +int platform::getNumGPUs() { + return _instance->getNumGPUs(); +} + +json platform::getGPU(int index) { + return _instance->getGPU(index); +} + +int platform::getNumDisplays() { + return _instance->getNumDisplays(); +} + +json platform::getDisplay(int index) { + return _instance->getDisplay(index); +} + +int platform::getNumMemories() { + return _instance->getNumMemories(); +} + +json platform::getMemory(int index) { + return _instance->getMemory(index); +} + +json platform::getComputer(){ + return _instance->getComputer(); +} diff --git a/libraries/platform/src/platformInstance.cpp b/libraries/platform/src/platform/backend/PlatformInstance.cpp similarity index 51% rename from libraries/platform/src/platformInstance.cpp rename to libraries/platform/src/platform/backend/PlatformInstance.cpp index 5859577748..8c1f20d2d8 100644 --- a/libraries/platform/src/platformInstance.cpp +++ b/libraries/platform/src/platform/backend/PlatformInstance.cpp @@ -7,8 +7,10 @@ // -#include "platformInstance.h" -#include +#include "PlatformInstance.h" + +#include "../PlatformKeys.h" +#include "../Profiler.h" using namespace platform; @@ -17,6 +19,11 @@ bool Instance::enumeratePlatform() { enumerateCpu(); enumerateGpu(); enumerateMemory(); + + // And profile the platform and put the tier in "computer" + _computer[keys::computer::profileTier] = Profiler::TierNames[Profiler::profilePlatform()]; + + _computer["keys"] = listAllKeys(); return true; } @@ -72,3 +79,44 @@ Instance::~Instance() { _display.clear(); } } + + +json Instance::listAllKeys() { + json allKeys; + allKeys.array({{ + keys::cpu::vendor, + keys::cpu::vendor_Intel, + keys::cpu::vendor_AMD, + keys::cpu::model, + keys::cpu::clockSpeed, + keys::cpu::numCores, + + keys::gpu::vendor, + keys::gpu::vendor_NVIDIA, + keys::gpu::vendor_AMD, + keys::gpu::vendor_Intel, + keys::gpu::model, + keys::gpu::videoMemory, + keys::gpu::driver, + + keys::display::description, + keys::display::name, + keys::display::coordsLeft, + keys::display::coordsRight, + keys::display::coordsTop, + keys::display::coordsBottom, + + keys::memTotal, + + keys::computer::OS, + keys::computer::OS_WINDOWS, + keys::computer::OS_MACOS, + keys::computer::OS_LINUX, + keys::computer::OS_ANDROID, + keys::computer::vendor, + keys::computer::vendor_Apple, + keys::computer::model, + keys::computer::profileTier + }}); + return allKeys; +} diff --git a/libraries/platform/src/platformInstance.h b/libraries/platform/src/platform/backend/PlatformInstance.h similarity index 80% rename from libraries/platform/src/platformInstance.h rename to libraries/platform/src/platform/backend/PlatformInstance.h index 8d0a181e3d..52fa9ec3f2 100644 --- a/libraries/platform/src/platformInstance.h +++ b/libraries/platform/src/platform/backend/PlatformInstance.h @@ -19,16 +19,16 @@ class Instance { public: bool virtual enumeratePlatform(); - int getNumCPU() { return (int)_cpu.size(); } + int getNumCPUs() { return (int)_cpu.size(); } json getCPU(int index); - int getNumGPU() { return (int)_gpu.size(); } + int getNumGPUs() { return (int)_gpu.size(); } json getGPU(int index); - int getNumMemory() { return (int)_memory.size(); } + int getNumMemories() { return (int)_memory.size(); } json getMemory(int index); - int getNumDisplay() { return (int)_display.size(); } + int getNumDisplays() { return (int)_display.size(); } json getDisplay(int index); @@ -41,6 +41,8 @@ public: virtual ~Instance(); + static json listAllKeys(); + protected: std::vector _cpu; std::vector _memory; diff --git a/libraries/platform/src/WINPlatform.cpp b/libraries/platform/src/platform/backend/WINPlatform.cpp similarity index 70% rename from libraries/platform/src/WINPlatform.cpp rename to libraries/platform/src/platform/backend/WINPlatform.cpp index 8b37aa4e77..0c15b7979b 100644 --- a/libraries/platform/src/WINPlatform.cpp +++ b/libraries/platform/src/platform/backend/WINPlatform.cpp @@ -7,15 +7,15 @@ // #include "WINPlatform.h" -#include "platformJsonKeys.h" +#include "../PlatformKeys.h" +#include -#ifdef Q_OS_WINDOWS +#ifdef Q_OS_WIN #include #include #endif #include -#include #include @@ -24,7 +24,7 @@ using namespace platform; void WINInstance::enumerateCpu() { json cpu = {}; -#ifdef Q_OS_WINDOWS +#ifdef Q_OS_WIN int CPUInfo[4] = { -1 }; unsigned nExIds; unsigned int i = 0; @@ -47,10 +47,10 @@ void WINInstance::enumerateCpu() { } } - cpu["cpuBrand"] = CPUBrandString; - cpu["cpuModel"] = CPUModelString; - cpu["cpuClockSpeed"] = CPUClockString; - cpu["cpuNumCores"] = std::thread::hardware_concurrency(); + cpu[keys::cpu::vendor] = CPUBrandString; + cpu[keys::cpu::model] = CPUModelString; + cpu[keys::cpu::clockSpeed] = CPUClockString; + cpu[keys::cpu::numCores] = std::thread::hardware_concurrency(); #endif _cpu.push_back(cpu); @@ -61,9 +61,10 @@ void WINInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); json gpu = {}; - gpu["gpuName"] = ident->getName().toUtf8().constData(); - gpu["gpuMemory"] = ident->getMemory(); - gpu["gpuDriver"] = ident->getDriver().toUtf8().constData(); + gpu[keys::gpu::vendor] = ident->getName().toUtf8().constData(); + gpu[keys::gpu::model] = ident->getName().toUtf8().constData(); + gpu[keys::gpu::videoMemory] = ident->getMemory(); + gpu[keys::gpu::driver] = ident->getDriver().toUtf8().constData(); _gpu.push_back(gpu); _display = ident->getOutput(); @@ -77,12 +78,15 @@ void WINInstance::enumerateMemory() { statex.dwLength = sizeof(statex); GlobalMemoryStatusEx(&statex); int totalRam = statex.ullTotalPhys / 1024 / 1024; - ram["totalMemory"] = totalRam; + ram[keys.memTotal] = totalRam; #endif _memory.push_back(ram); } void WINInstance::enumerateComputer(){ - //no implememntation at this time + _computer[keys::computer::OS] = keys::computer::OS_WINDOWS; + _computer[keys::computer::vendor] = ""; + _computer[keys::computer::model] = ""; + } diff --git a/libraries/platform/src/WINPlatform.h b/libraries/platform/src/platform/backend/WINPlatform.h similarity index 95% rename from libraries/platform/src/WINPlatform.h rename to libraries/platform/src/platform/backend/WINPlatform.h index 828d27ffc3..e540335d94 100644 --- a/libraries/platform/src/WINPlatform.h +++ b/libraries/platform/src/platform/backend/WINPlatform.h @@ -9,7 +9,7 @@ #ifndef hifi_WinPlatform_h #define hifi_WinPlatform_h -#include "platformInstance.h" +#include "PlatformInstance.h" namespace platform { class WINInstance : public Instance { diff --git a/libraries/platform/src/platformJsonKeys.h b/libraries/platform/src/platformJsonKeys.h deleted file mode 100644 index 31d81a829c..0000000000 --- a/libraries/platform/src/platformJsonKeys.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// Created by Amer Cerkic 05/02/2019 -// Copyright 2019 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -#pragma once -#ifndef hifi_PlatformJsonKeys_h -#define hifi_PlatformJsonKeys_h - -namespace platform { - namespace jsonKeys{ -#if 0 - static const char* cpuBrand { "cpuBrand"}; - static const char* cpuModel {"cpuModel"}; - static const char* cpuClockSpeed {"clockSpeed"}; - static const char* cpuNumCores { "numCores"}; - static const char* gpuName {"GpuName"}; - static const char* gpuMemory {"gpuMemory"}; - static const char* gpuDriver {"gpuDriver"}; - static const char* totalMemory {"totalMem"}; - static const char* displayDescription { "description"}; - static const char* displayName {"deviceName"}; - static const char* displayCoordsLeft {"coordinatesleft"}; - static const char* displayCoordsRight { "coordinatesright"}; - static const char* displayCoordsTop { "coordinatestop"}; - static const char* displayCoordsBottom { "coordinatesbottom"}; - static const char* computerModel { "computerModel"}; - -#endif - - } - -} // namespace plaform::jsonKeys - -#endif