From 5001a04326762542071e1746eab958d8befbfc07 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sat, 25 May 2019 15:53:54 -0700 Subject: [PATCH 01/10] Updating the platform lib, implementing the first version of the profiler and exposing all these through the PlatformInfoScriptingInterface --- .../PlatformInfoScriptingInterface.cpp | 63 +++++++++ .../PlatformInfoScriptingInterface.h | 105 ++++++++++++++ libraries/platform/CMakeLists.txt | 4 +- libraries/platform/src/platform.cpp | 83 ----------- .../src/{platform.h => platform/Platform.h} | 10 +- .../platform/src/platform/PlatformKeys.h | 57 ++++++++ libraries/platform/src/platform/Profiler.cpp | 127 +++++++++++++++++ libraries/platform/src/platform/Profiler.h | 34 +++++ .../backend}/AndroidPlatform.cpp | 26 ++-- .../{ => platform/backend}/AndroidPlatform.h | 2 +- .../{ => platform/backend}/LinuxPlatform.cpp | 25 ++-- .../{ => platform/backend}/LinuxPlatform.h | 2 +- .../{ => platform/backend}/MACOSPlatform.cpp | 26 ++-- .../{ => platform/backend}/MACOSPlatform.h | 2 +- .../src/platform/backend/Platform.cpp | 130 ++++++++++++++++++ .../backend/PlatformInstance.cpp} | 52 ++++++- .../backend/PlatformInstance.h} | 10 +- .../{ => platform/backend}/WINPlatform.cpp | 30 ++-- .../src/{ => platform/backend}/WINPlatform.h | 2 +- libraries/platform/src/platformJsonKeys.h | 37 ----- 20 files changed, 646 insertions(+), 181 deletions(-) delete mode 100644 libraries/platform/src/platform.cpp rename libraries/platform/src/{platform.h => platform/Platform.h} (88%) create mode 100644 libraries/platform/src/platform/PlatformKeys.h create mode 100644 libraries/platform/src/platform/Profiler.cpp create mode 100644 libraries/platform/src/platform/Profiler.h rename libraries/platform/src/{ => platform/backend}/AndroidPlatform.cpp (53%) rename libraries/platform/src/{ => platform/backend}/AndroidPlatform.h (95%) rename libraries/platform/src/{ => platform/backend}/LinuxPlatform.cpp (71%) rename libraries/platform/src/{ => platform/backend}/LinuxPlatform.h (95%) rename libraries/platform/src/{ => platform/backend}/MACOSPlatform.cpp (74%) rename libraries/platform/src/{ => platform/backend}/MACOSPlatform.h (95%) create mode 100644 libraries/platform/src/platform/backend/Platform.cpp rename libraries/platform/src/{platformInstance.cpp => platform/backend/PlatformInstance.cpp} (51%) rename libraries/platform/src/{platformInstance.h => platform/backend/PlatformInstance.h} (80%) rename libraries/platform/src/{ => platform/backend}/WINPlatform.cpp (70%) rename libraries/platform/src/{ => platform/backend}/WINPlatform.h (95%) delete mode 100644 libraries/platform/src/platformJsonKeys.h 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 From 546639fdfe9e0d492f433aaacd637d8dcd16b6dd Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sun, 26 May 2019 12:30:50 -0700 Subject: [PATCH 02/10] Adding a script and ui to check the values returned by the PlatformInfo ui --- interface/src/Application.cpp | 2 + .../utilities/lib/prop/PropGroup.qml | 26 ++++++++ .../developer/utilities/lib/prop/PropItem.qml | 4 ++ .../utilities/lib/prop/PropScalar.qml | 13 ++-- .../utilities/lib/prop/PropString.qml | 41 ++++++++++++ scripts/developer/utilities/lib/prop/qmldir | 1 + .../utilities/lib/prop/style/Global.qml | 1 + scripts/developer/utilities/render/luci.qml | 6 +- .../developer/utilities/render/platform.js | 46 +++++++++++++ .../developer/utilities/render/platform.qml | 66 +++++++++++++++++++ 10 files changed, 195 insertions(+), 11 deletions(-) create mode 100644 scripts/developer/utilities/lib/prop/PropString.qml create mode 100644 scripts/developer/utilities/render/platform.js create mode 100644 scripts/developer/utilities/render/platform.qml diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a0cb790958..a962e7602a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3322,6 +3322,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { surfaceContext->setContextProperty("HMD", DependencyManager::get().data()); surfaceContext->setContextProperty("Scene", DependencyManager::get().data()); surfaceContext->setContextProperty("Render", RenderScriptingInterface::getInstance()); + surfaceContext->setContextProperty("PlatformInfo", PlatformInfoScriptingInterface::getInstance()); surfaceContext->setContextProperty("Workload", _gameWorkload._engine->getConfiguration().get()); surfaceContext->setContextProperty("Reticle", getApplicationCompositor().getReticleInterface()); surfaceContext->setContextProperty("Snapshot", DependencyManager::get().data()); @@ -3445,6 +3446,7 @@ void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditiona surfaceContext->setContextProperty("HiFiAbout", AboutUtil::getInstance()); surfaceContext->setContextProperty("WalletScriptingInterface", DependencyManager::get().data()); surfaceContext->setContextProperty("ResourceRequestObserver", DependencyManager::get().data()); + surfaceContext->setContextProperty("PlatformInfo", PlatformInfoScriptingInterface::getInstance()); } } diff --git a/scripts/developer/utilities/lib/prop/PropGroup.qml b/scripts/developer/utilities/lib/prop/PropGroup.qml index 384b50ecad..22facb71c6 100644 --- a/scripts/developer/utilities/lib/prop/PropGroup.qml +++ b/scripts/developer/utilities/lib/prop/PropGroup.qml @@ -38,6 +38,15 @@ PropFolderPanel { proItem['type'] = typeof(proItem.object[proItem.property]) } switch(proItem.type) { + case 'string': + case 'PropString': { + var component = Qt.createComponent("PropString.qml"); + component.createObject(propItemsContainer, { + "label": proItem.property, + "object": proItem.object, + "property": proItem.property + }) + } break; case 'boolean': case 'PropBool': { var component = Qt.createComponent("PropBool.qml"); @@ -57,6 +66,7 @@ PropFolderPanel { "min": (proItem["min"] !== undefined ? proItem.min : 0.0), "max": (proItem["max"] !== undefined ? proItem.max : 1.0), "integer": (proItem["integral"] !== undefined ? proItem.integral : false), + "readOnly": (proItem["readOnly"] !== undefined ? proItem["readOnly"] : false), }) } break; case 'PropEnum': { @@ -97,6 +107,22 @@ PropFolderPanel { } } } + + function populateFromObjectProps(object) { + var propsModel = [] + var props = Object.keys(object); + + for (var p in props) { + var o = {}; + o["object"] = object + o["property"] = props[p]; + // o["readOnly"] = true; + o["type"] = "string"; + propsModel.push(o) + } + root.updatePropItems(root.propItemsPanel, propsModel); + } + Component.onCompleted: { } } diff --git a/scripts/developer/utilities/lib/prop/PropItem.qml b/scripts/developer/utilities/lib/prop/PropItem.qml index 339ff10422..03eabae39b 100644 --- a/scripts/developer/utilities/lib/prop/PropItem.qml +++ b/scripts/developer/utilities/lib/prop/PropItem.qml @@ -18,12 +18,16 @@ Item { // Prop item is designed to author an object[property]: property var object: {} property string property: "" + property bool readOnly: false // value is accessed through the "valueVarSetter" and "valueVarGetter" // By default, these just go get or set the value from the object[property] // function defaultGet() { return root.object[root.property]; } function defaultSet(value) { root.object[root.property] = value; } + // function defaultSetReadOnly(value) { log ( "read only " + property + ", NOT setting to " + value); } + // function defaultSetReadOnly(value) {} + // property var valueVarSetter: (root.readOnly ? defaultSetReadOnly : defaultSet) property var valueVarSetter: defaultSet property var valueVarGetter: defaultGet diff --git a/scripts/developer/utilities/lib/prop/PropScalar.qml b/scripts/developer/utilities/lib/prop/PropScalar.qml index 684dd4fed4..4c569eb57e 100644 --- a/scripts/developer/utilities/lib/prop/PropScalar.qml +++ b/scripts/developer/utilities/lib/prop/PropScalar.qml @@ -20,16 +20,12 @@ PropItem { property bool integral: false property var numDigits: 2 - property alias valueVar : sliderControl.value property alias min: sliderControl.minimumValue property alias max: sliderControl.maximumValue - - property bool showValue: true - - + signal valueChanged(real value) Component.onCompleted: { @@ -42,11 +38,11 @@ PropItem { anchors.left: root.splitter.right anchors.verticalCenter: root.verticalCenter - width: root.width * global.valueAreaWidthScale + width: root.width * (root.readOnly ? 1.0 : global.valueAreaWidthScale) horizontalAlignment: global.valueTextAlign height: global.slimHeight - text: sliderControl.value.toFixed(root.integral ? 0 : root.numDigits) + text: root.valueVarGetter().toFixed(root.integral ? 0 : root.numDigits) background: Rectangle { color: global.color @@ -58,12 +54,13 @@ PropItem { HifiControls.Slider { id: sliderControl + visible: !root.readOnly stepSize: root.integral ? 1.0 : 0.0 anchors.left: valueLabel.right anchors.right: root.right anchors.verticalCenter: root.verticalCenter - onValueChanged: { root.valueVarSetter(value) } + onValueChanged: { if (!root.readOnly) { root.valueVarSetter(value)} } } diff --git a/scripts/developer/utilities/lib/prop/PropString.qml b/scripts/developer/utilities/lib/prop/PropString.qml new file mode 100644 index 0000000000..7b7cbc4c91 --- /dev/null +++ b/scripts/developer/utilities/lib/prop/PropString.qml @@ -0,0 +1,41 @@ +// +// PropItem.qml +// +// Created by Sam Gateau on 3/2/2019 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// + +import QtQuick 2.7 + +import controlsUit 1.0 as HifiControls + +PropItem { + Global { id: global } + id: root + + // Scalar Prop + property bool integral: false + property var numDigits: 2 + + PropLabel { + id: valueLabel + + anchors.left: root.splitter.right + anchors.right: root.right + anchors.verticalCenter: root.verticalCenter + horizontalAlignment: global.valueTextAlign + height: global.slimHeight + + text: root.valueVarGetter(); + + background: Rectangle { + color: global.color + border.color: global.colorBorderLight + border.width: global.valueBorderWidth + radius: global.valueBorderRadius + } + } +} diff --git a/scripts/developer/utilities/lib/prop/qmldir b/scripts/developer/utilities/lib/prop/qmldir index c67ab6a41a..e09785846d 100644 --- a/scripts/developer/utilities/lib/prop/qmldir +++ b/scripts/developer/utilities/lib/prop/qmldir @@ -10,5 +10,6 @@ PropFolderPanel 1.0 style/PiFolderPanel.qml PropItem 1.0 PropItem.qml PropScalar 1.0 PropScalar.qml +PropString 1.0 PropString.qml PropEnum 1.0 PropEnum.qml PropColor 1.0 PropColor.qml diff --git a/scripts/developer/utilities/lib/prop/style/Global.qml b/scripts/developer/utilities/lib/prop/style/Global.qml index 4cdee70244..bbc8acfa0b 100644 --- a/scripts/developer/utilities/lib/prop/style/Global.qml +++ b/scripts/developer/utilities/lib/prop/style/Global.qml @@ -24,6 +24,7 @@ Item { readonly property real horizontalMargin: 4 readonly property color color: hifi.colors.baseGray + readonly property color colorBack: hifi.colors.baseGray readonly property color colorBackShadow: hifi.colors.baseGrayShadow readonly property color colorBackHighlight: hifi.colors.baseGrayHighlight readonly property color colorBorderLight: hifi.colors.lightGray diff --git a/scripts/developer/utilities/render/luci.qml b/scripts/developer/utilities/render/luci.qml index a904ec52fc..2dc8fda081 100644 --- a/scripts/developer/utilities/render/luci.qml +++ b/scripts/developer/utilities/render/luci.qml @@ -31,7 +31,7 @@ Rectangle { clip: true Column { - width: render.width + width: parent.width Prop.PropFolderPanel { label: "Shading Model" panelFrameData: Component { @@ -87,14 +87,14 @@ Rectangle { } } } - Jet.TaskPropView { + /* Jet.TaskPropView { id: "le" jobPath: "" label: "Le Render Engine" // anchors.left: parent.left // anchors.right: parent.right - } + }*/ } } } \ No newline at end of file diff --git a/scripts/developer/utilities/render/platform.js b/scripts/developer/utilities/render/platform.js new file mode 100644 index 0000000000..b51c9614ba --- /dev/null +++ b/scripts/developer/utilities/render/platform.js @@ -0,0 +1,46 @@ +// Test key commands +PlatformInfo.getComputer() +// {"OS":"WINDOWS","keys":null,"model":"","profileTier":"HIGH","vendor":""} +PlatformInfo.getNumCPUs() +// 1 +PlatformInfo.getCPU(0) +//{"clockSpeed":" 4.00GHz","model":") i7-6700K CPU @ 4.00GHz","numCores":8,"vendor":"Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz"} +PlatformInfo.getNumGPUs() +// 1 +PlatformInfo.getGPU(0) +// {"driver":"25.21.14.1967","model":"NVIDIA GeForce GTX 1080","vendor":"NVIDIA GeForce GTX 1080","videoMemory":8079} + +var Page = Script.require('./luci/Page.js'); + + +function openView() { + var pages = new Pages(); + function fromQml(message) { + if (pages.open(message.method)) { + return; + } + } + + var platformWindow + + function closeLuciWindow() { + if (luciWindow !== undefined) { + activeWindow.fromQml.disconnect(fromQml); + } + luciWindow = {}; + + Controller.mousePressEvent.disconnect(onMousePressEvent); + Controller.mouseReleaseEvent.disconnect(onMouseReleaseEvent); + Controller.mouseMoveEvent.disconnect(onMouseMoveEvent); + pages.clear(); + } + + pages.addPage('Platform', 'Platform', '../platform.qml', 350, 700); + pages.open('Platform'); + + + return pages; +} + + +openView(); diff --git a/scripts/developer/utilities/render/platform.qml b/scripts/developer/utilities/render/platform.qml new file mode 100644 index 0000000000..1f7000bc57 --- /dev/null +++ b/scripts/developer/utilities/render/platform.qml @@ -0,0 +1,66 @@ +// +// platform.qml +// +// Created by Sam Gateau on 5/25/2019 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 + +import controlsUit 1.0 as HifiControls + +import "../lib/prop" as Prop + +Rectangle { + anchors.fill: parent + id: platform; + + Prop.Global { id: global;} + color: global.colorBack + + Column { + width: parent.width + + Prop.PropGroup { + id: computer + label: "Computer" + isUnfold: true + + Component.onCompleted: { + computer.populateFromObjectProps(JSON.parse(PlatformInfo.getComputer())) + } + } + Prop.PropGroup { + id: cpu + label: "CPU" + isUnfold: true + + Component.onCompleted: { + cpu.populateFromObjectProps(JSON.parse(PlatformInfo.getCPU(0))) + } + } + Prop.PropGroup { + id: gpu + label: "GPU" + isUnfold: true + + Component.onCompleted: { + gpu.populateFromObjectProps(JSON.parse(PlatformInfo.getGPU(0))) + } + } + Prop.PropGroup { + id: display + label: "Display" + isUnfold: true + + Component.onCompleted: { + display.populateFromObjectProps(JSON.parse(PlatformInfo.getDisplay(0))) + } + } + } +} + From 42d1b340cd6d4346b091f04406ad1e05844bfd68 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 28 May 2019 00:00:45 -0700 Subject: [PATCH 03/10] Trying to unify the getCPUID function in CPUIdent --- .../src/platform/backend/LinuxPlatform.cpp | 28 ++-- .../src/platform/backend/MACOSPlatform.cpp | 15 ++- .../src/platform/backend/WINPlatform.cpp | 46 ++----- libraries/shared/src/CPUIdent.cpp | 123 +++++++++++++++++- libraries/shared/src/CPUIdent.h | 89 +------------ .../developer/utilities/render/platform.qml | 9 ++ 6 files changed, 169 insertions(+), 141 deletions(-) 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" From 99f8b61727dbe33fbd69b24f4b0b7043eeee3b47 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 28 May 2019 00:14:50 -0700 Subject: [PATCH 04/10] Trying to unify the getCPUID function in CPUIdent --- libraries/shared/src/CPUIdent.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libraries/shared/src/CPUIdent.cpp b/libraries/shared/src/CPUIdent.cpp index 2545f0c56b..81a2a8a869 100644 --- a/libraries/shared/src/CPUIdent.cpp +++ b/libraries/shared/src/CPUIdent.cpp @@ -18,6 +18,9 @@ void getCPUID(int32_t* p, int32_t ax) { __cpuid(p, ax); } +void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { + __cpuidex(p, ax, ecx); +} #elif defined(Q_OS_MAC) void getCPUID(int32_t* p, int32_t ax) { @@ -30,6 +33,9 @@ void getCPUID(int32_t* p, int32_t ax) { : "0" (ax) ); } +void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { + getCPUID(p, ax, ecx); +} #elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) void getCPUID(int32_t* p, int32_t ax) { @@ -42,12 +48,20 @@ void getCPUID(int32_t* p, int32_t ax) { : "0" (ax) ); } +void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { + getCPUID(p, ax, ecx); +} + #else void getCPUID(int32_t* p, int32_t ax) { if (p) { memset(p, 0, 4*4); } } +void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { + getCPUID(p, ax, ecx); +} + #endif @@ -135,7 +149,7 @@ CPUIdent::CPUIdent_Internal::CPUIdent_Internal() nIds_ = cpui[0]; for (int i = 0; i <= nIds_; ++i) { - __cpuidex(cpui.data(), i, 0); + getCPUIDEX(cpui.data(), i, 0); data_.push_back(cpui); } @@ -167,14 +181,14 @@ CPUIdent::CPUIdent_Internal::CPUIdent_Internal() // Calling __cpuid with 0x80000000 as the function_id argument // gets the number of the highest valid extended ID. - __cpuid(cpui.data(), 0x80000000); + getCPUID(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); + getCPUIDEX(cpui.data(), i, 0); extdata_.push_back(cpui); } From 6f7409803234f5cf77a188b2ffb3d1eed1b84001 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 28 May 2019 00:26:30 -0700 Subject: [PATCH 05/10] Fixing the getCPUIDEX --- libraries/shared/src/CPUIdent.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/shared/src/CPUIdent.cpp b/libraries/shared/src/CPUIdent.cpp index 81a2a8a869..6211e75bf1 100644 --- a/libraries/shared/src/CPUIdent.cpp +++ b/libraries/shared/src/CPUIdent.cpp @@ -34,7 +34,7 @@ void getCPUID(int32_t* p, int32_t ax) { ); } void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { - getCPUID(p, ax, ecx); + getCPUID(p, ax); } #elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) @@ -49,7 +49,7 @@ void getCPUID(int32_t* p, int32_t ax) { ); } void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { - getCPUID(p, ax, ecx); + getCPUID(p, ax); } #else @@ -59,7 +59,7 @@ void getCPUID(int32_t* p, int32_t ax) { } } void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { - getCPUID(p, ax, ecx); + getCPUID(p, ax); } #endif From a7293696559abba84be522d7383ee94bbea62a52 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 28 May 2019 00:32:02 -0700 Subject: [PATCH 06/10] REmoving the keys list from the OCOmputer info, not needed --- libraries/platform/src/platform/backend/PlatformInstance.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/platform/src/platform/backend/PlatformInstance.cpp b/libraries/platform/src/platform/backend/PlatformInstance.cpp index 8c1f20d2d8..164fdb924f 100644 --- a/libraries/platform/src/platform/backend/PlatformInstance.cpp +++ b/libraries/platform/src/platform/backend/PlatformInstance.cpp @@ -22,8 +22,7 @@ bool Instance::enumeratePlatform() { // And profile the platform and put the tier in "computer" _computer[keys::computer::profileTier] = Profiler::TierNames[Profiler::profilePlatform()]; - - _computer["keys"] = listAllKeys(); + return true; } From e3fe20ae6acba741b4e38b280dc0e12d9ac56a42 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 28 May 2019 00:53:03 -0700 Subject: [PATCH 07/10] adding stdio.h for memset and memcpy on linux --- libraries/shared/src/CPUIdent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/CPUIdent.cpp b/libraries/shared/src/CPUIdent.cpp index 6211e75bf1..9df9a89a0f 100644 --- a/libraries/shared/src/CPUIdent.cpp +++ b/libraries/shared/src/CPUIdent.cpp @@ -11,7 +11,7 @@ #include "CPUIdent.h" #include - +#include #ifdef Q_OS_WIN #include From 2d1b06a1ba01f9dd647ef03d4f26edfdb6b04d50 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 28 May 2019 01:00:51 -0700 Subject: [PATCH 08/10] adding string.h (instead of stdio.h) for memset and memcpy on linux --- libraries/shared/src/CPUIdent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/CPUIdent.cpp b/libraries/shared/src/CPUIdent.cpp index 9df9a89a0f..2d04b0867c 100644 --- a/libraries/shared/src/CPUIdent.cpp +++ b/libraries/shared/src/CPUIdent.cpp @@ -11,7 +11,7 @@ #include "CPUIdent.h" #include -#include +#include #ifdef Q_OS_WIN #include From a168109588ac56a46725b820ce975f0e6ca88657 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 28 May 2019 12:27:26 -0700 Subject: [PATCH 09/10] trying to clean up the asm for linux and macos --- .../src/platform/backend/AndroidPlatform.cpp | 1 - .../src/platform/backend/LinuxPlatform.cpp | 33 ---------- .../src/platform/backend/MACOSPlatform.cpp | 45 ------------- libraries/shared/src/CPUIdent.cpp | 64 ++++++++++--------- libraries/shared/src/CPUIdent.h | 8 +-- .../developer/utilities/render/platform.js | 38 ++--------- 6 files changed, 44 insertions(+), 145 deletions(-) diff --git a/libraries/platform/src/platform/backend/AndroidPlatform.cpp b/libraries/platform/src/platform/backend/AndroidPlatform.cpp index 49ac5079ee..ee5a7e39b9 100644 --- a/libraries/platform/src/platform/backend/AndroidPlatform.cpp +++ b/libraries/platform/src/platform/backend/AndroidPlatform.cpp @@ -43,6 +43,5 @@ void AndroidInstance::enumerateComputer(){ _computer[keys::computer::OS] = keys::computer::OS_ANDROID; _computer[keys::computer::vendor] = ""; _computer[keys::computer::model] = ""; - } diff --git a/libraries/platform/src/platform/backend/LinuxPlatform.cpp b/libraries/platform/src/platform/backend/LinuxPlatform.cpp index 5c39ac5a4f..356df27e0a 100644 --- a/libraries/platform/src/platform/backend/LinuxPlatform.cpp +++ b/libraries/platform/src/platform/backend/LinuxPlatform.cpp @@ -25,38 +25,6 @@ void LinuxInstance::enumerateCpu() { _cpu.push_back(cpu); } -/* -void LinuxInstance::enumerateCpu() { - json cpu = {}; - - uint32_t cpuInfo[4]={0,0,0,0}; - char CPUBrandString[16]; - char CPUModelString[16]; - char CPUClockString[16]; - uint32_t nExIds; - getLCpuId(cpuInfo, 0x80000000); - nExIds = cpuInfo[0]; - - for (uint32_t i = 0x80000000; i <= nExIds; ++i) { - getLCpuId(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::numCores] = std::thread::hardware_concurrency(); - - _cpu.push_back(cpu); -} -*/ void LinuxInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); @@ -82,6 +50,5 @@ 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/platform/backend/MACOSPlatform.cpp b/libraries/platform/src/platform/backend/MACOSPlatform.cpp index 6859500531..2607c47d5b 100644 --- a/libraries/platform/src/platform/backend/MACOSPlatform.cpp +++ b/libraries/platform/src/platform/backend/MACOSPlatform.cpp @@ -31,52 +31,7 @@ void MACOSInstance::enumerateCpu() { _cpu.push_back(cpu); } -/* -static void getCpuId( uint32_t* p, uint32_t ax ) -{ -#ifdef Q_OS_MAC - __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 -} - -void MACOSInstance::enumerateCpu() { - json cpu = {}; - uint32_t cpuInfo[4]={0,0,0,0}; - char CPUBrandString[16]; - char CPUModelString[16]; - char CPUClockString[16]; - uint32_t nExIds; - getCpuId(cpuInfo, 0x80000000); - nExIds = cpuInfo[0]; - - for (uint32_t i = 0x80000000; i <= nExIds; ++i) { - getCpuId(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::numCores] = std::thread::hardware_concurrency(); - - _cpu.push_back(cpu); -} -*/ void MACOSInstance::enumerateGpu() { GPUIdent* ident = GPUIdent::getInstance(); json gpu = {}; diff --git a/libraries/shared/src/CPUIdent.cpp b/libraries/shared/src/CPUIdent.cpp index 2d04b0867c..ea27cfb3da 100644 --- a/libraries/shared/src/CPUIdent.cpp +++ b/libraries/shared/src/CPUIdent.cpp @@ -15,51 +15,57 @@ #ifdef Q_OS_WIN #include -void getCPUID(int32_t* p, int32_t ax) { - __cpuid(p, ax); +void getCPUID(uint32_t* p, uint32_t eax) { + __cpuid((int*) p, (int) eax); } -void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { - __cpuidex(p, ax, ecx); +void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) { + __cpuidex((int*) p, (int) eax, (int) ecx); } #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) +void getCPUID(uint32_t* p, uint32_t eax) { + __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" (eax) ); } -void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { - getCPUID(p, ax); +void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) { + getCPUID(p, eax); } #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) +void getCPUID(uint32_t* p, uint32_t eax) { + __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" (eax) ); } -void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { - getCPUID(p, ax); +void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) { + getCPUID(p, eax); } #else -void getCPUID(int32_t* p, int32_t ax) { +void getCPUID(uint32_t* p, uint32_t eax) { if (p) { - memset(p, 0, 4*4); + p[0] = 0; + p[1] = 0; + p[2] = 0; + p[3] = 0; } } -void getCPUIDEX(int32_t* p, int32_t ax, int32_t ecx) { - getCPUID(p, ax); +void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) { + if (p) { + p[0] = 0; + p[1] = 0; + p[2] = 0; + p[3] = 0; + } } #endif @@ -141,7 +147,7 @@ CPUIdent::CPUIdent_Internal::CPUIdent_Internal() extdata_{} { //int cpuInfo[4] = {-1}; - std::array cpui; + std::array cpui; // Calling __cpuid with 0x0 as the function_id argument // gets the number of the highest valid function ID. diff --git a/libraries/shared/src/CPUIdent.h b/libraries/shared/src/CPUIdent.h index 68653f9287..dbf0c3ea91 100644 --- a/libraries/shared/src/CPUIdent.h +++ b/libraries/shared/src/CPUIdent.h @@ -105,8 +105,8 @@ private: public: CPUIdent_Internal(); - int nIds_; - int nExIds_; + uint32_t nIds_; + uint32_t nExIds_; std::string vendor_; std::string brand_; bool isIntel_; @@ -117,8 +117,8 @@ private: std::bitset<32> f_7_ECX_; std::bitset<32> f_81_ECX_; std::bitset<32> f_81_EDX_; - std::vector> data_; - std::vector> extdata_; + std::vector> data_; + std::vector> extdata_; }; }; diff --git a/scripts/developer/utilities/render/platform.js b/scripts/developer/utilities/render/platform.js index b51c9614ba..9678bf3ff1 100644 --- a/scripts/developer/utilities/render/platform.js +++ b/scripts/developer/utilities/render/platform.js @@ -10,37 +10,9 @@ PlatformInfo.getNumGPUs() PlatformInfo.getGPU(0) // {"driver":"25.21.14.1967","model":"NVIDIA GeForce GTX 1080","vendor":"NVIDIA GeForce GTX 1080","videoMemory":8079} -var Page = Script.require('./luci/Page.js'); +var window = Desktop.createWindow(Script.resolvePath('./platform.qml'), { + title: "Platform", + presentationMode: Desktop.PresentationMode.NATIVE, + size: {x: 350, y: 700} +}); - -function openView() { - var pages = new Pages(); - function fromQml(message) { - if (pages.open(message.method)) { - return; - } - } - - var platformWindow - - function closeLuciWindow() { - if (luciWindow !== undefined) { - activeWindow.fromQml.disconnect(fromQml); - } - luciWindow = {}; - - Controller.mousePressEvent.disconnect(onMousePressEvent); - Controller.mouseReleaseEvent.disconnect(onMouseReleaseEvent); - Controller.mouseMoveEvent.disconnect(onMouseMoveEvent); - pages.clear(); - } - - pages.addPage('Platform', 'Platform', '../platform.qml', 350, 700); - pages.open('Platform'); - - - return pages; -} - - -openView(); From 3af8f37df5daec1dea0eb93d931bad41989cae6f Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 28 May 2019 13:52:32 -0700 Subject: [PATCH 10/10] THe real correct pltform agnostic cpuidex was in cpudetect... --- libraries/shared/src/CPUIdent.cpp | 60 +++---------------------------- 1 file changed, 5 insertions(+), 55 deletions(-) diff --git a/libraries/shared/src/CPUIdent.cpp b/libraries/shared/src/CPUIdent.cpp index ea27cfb3da..b11ba8950d 100644 --- a/libraries/shared/src/CPUIdent.cpp +++ b/libraries/shared/src/CPUIdent.cpp @@ -13,64 +13,14 @@ #include #include -#ifdef Q_OS_WIN -#include +#include "CPUDetect.h" void getCPUID(uint32_t* p, uint32_t eax) { - __cpuid((int*) p, (int) eax); + cpuidex((int*) p, (int) eax, 0); } void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) { - __cpuidex((int*) p, (int) eax, (int) ecx); + cpuidex((int*) p, (int) eax, (int) ecx); } -#elif defined(Q_OS_MAC) -void getCPUID(uint32_t* p, uint32_t eax) { - __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" (eax) - ); -} -void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) { - getCPUID(p, eax); -} - -#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) -void getCPUID(uint32_t* p, uint32_t eax) { - __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" (eax) - ); -} -void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) { - getCPUID(p, eax); -} - -#else -void getCPUID(uint32_t* p, uint32_t eax) { - if (p) { - p[0] = 0; - p[1] = 0; - p[2] = 0; - p[3] = 0; - } -} -void getCPUIDEX(uint32_t* p, uint32_t eax, uint32_t ecx) { - if (p) { - p[0] = 0; - p[1] = 0; - p[2] = 0; - p[3] = 0; - } -} - -#endif - - const CPUIdent::CPUIdent_Internal CPUIdent::CPU_Rep; std::vector CPUIdent::getAllFeatures() { @@ -154,7 +104,7 @@ CPUIdent::CPUIdent_Internal::CPUIdent_Internal() getCPUID(cpui.data(), 0); nIds_ = cpui[0]; - for (int i = 0; i <= nIds_; ++i) { + for (uint32_t i = 0; i <= nIds_; ++i) { getCPUIDEX(cpui.data(), i, 0); data_.push_back(cpui); } @@ -193,7 +143,7 @@ CPUIdent::CPUIdent_Internal::CPUIdent_Internal() char brand[0x40]; memset(brand, 0, sizeof(brand)); - for (int i = 0x80000000; i <= nExIds_; ++i) { + for (uint32_t i = 0x80000000; i <= nExIds_; ++i) { getCPUIDEX(cpui.data(), i, 0); extdata_.push_back(cpui); }