Updating the platform lib, implementing the first version of the profiler and exposing all these through the PlatformInfoScriptingInterface

This commit is contained in:
Sam Gateau 2019-05-25 15:53:54 -07:00
parent 3ce790b459
commit 5001a04326
20 changed files with 646 additions and 181 deletions

View file

@ -10,6 +10,9 @@
#include <shared/GlobalAppProperties.h>
#include <thread>
#include <platform/Platform.h>
#include <platform/Profiler.h>
#ifdef Q_OS_WIN
#include <Windows.h>
#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;
}

View file

@ -9,6 +9,7 @@
#ifndef hifi_PlatformInfoScriptingInterface_h
#define hifi_PlatformInfoScriptingInterface_h
#include <platform/Profiler.h>
#include <QtCore/QObject>
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} <code>true</code> if Interface is running on a stand-alone device, <code>false</code> 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

View file

@ -1,5 +1,7 @@
set(TARGET_NAME platform)
setup_hifi_library()
setup_hifi_library()
link_hifi_libraries(shared)
GroupSources("src")
target_json()

View file

@ -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 <qglobal.h>
#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();
}

View file

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

View file

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

View file

@ -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<const char*, Profiler::Tier::NumTiers> 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<std::string>();
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<std::string>();
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<int>();
if (numCores <= 4) {
tier = Profiler::Tier::LOW;
return true;
}
cpuVendor = cpu[keys::cpu::vendor].get<std::string>();
}
// 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>();
std::string gpuModel = gpu[keys::gpu::model].get<std::string>();
// 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;
}

View file

@ -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 <array>
namespace platform {
class Profiler {
public:
enum Tier {
UNKNOWN = 0,
LOW,
MID,
HIGH,
NumTiers, // not a valid Tier
};
static const std::array<const char*, Tier::NumTiers> TierNames;
static Tier profilePlatform();
};
}
#endif

View file

@ -7,38 +7,42 @@
//
#include "AndroidPlatform.h"
#include "platformJsonKeys.h"
#include "../PlatformKeys.h"
#include <GPUIdent.h>
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] = "";
}

View file

@ -9,7 +9,7 @@
#ifndef hifi_AndroidPlatform_h
#define hifi_AndroidPlatform_h
#include "platformInstance.h"
#include "PlatformInstance.h"
namespace platform {
class AndroidInstance : public Instance {

View file

@ -7,7 +7,7 @@
//
#include "LinuxPlatform.h"
#include "platformJsonKeys.h"
#include "../PlatformKeys.h"
#include <GPUIdent.h>
#include <thread>
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
}

View file

@ -9,7 +9,7 @@
#ifndef hifi_LinuxPlatform_h
#define hifi_LinuxPlatform_h
#include "platformInstance.h"
#include "PlatformInstance.h"
namespace platform {
class LinuxInstance : public Instance {

View file

@ -7,7 +7,7 @@
//
#include "MACOSPlatform.h"
#include "platformJsonKeys.h"
#include "../PlatformKeys.h"
#include <thread>
#include <GPUIdent.h>
@ -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);

View file

@ -9,7 +9,7 @@
#ifndef hifi_MACOSPlatform_h
#define hifi_MACOSPlatform_h
#include "platformInstance.h"
#include "PlatformInstance.h"
namespace platform {
class MACOSInstance : public Instance {

View file

@ -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 <qglobal.h>
#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();
}

View file

@ -7,8 +7,10 @@
//
#include "platformInstance.h"
#include <QtGlobal>
#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;
}

View file

@ -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<json> _cpu;
std::vector<json> _memory;

View file

@ -7,15 +7,15 @@
//
#include "WINPlatform.h"
#include "platformJsonKeys.h"
#include "../PlatformKeys.h"
#include <GPUIdent.h>
#ifdef Q_OS_WINDOWS
#ifdef Q_OS_WIN
#include <intrin.h>
#include <Windows.h>
#endif
#include <thread>
#include <GPUIdent.h>
#include <string>
@ -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] = "";
}

View file

@ -9,7 +9,7 @@
#ifndef hifi_WinPlatform_h
#define hifi_WinPlatform_h
#include "platformInstance.h"
#include "PlatformInstance.h"
namespace platform {
class WINInstance : public Instance {

View file

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