moved instance to own file. moved functions based on comments in pr

This commit is contained in:
amerhifi 2019-05-13 17:07:25 -07:00
parent 804d171102
commit 95e3eede5f
8 changed files with 154 additions and 132 deletions

View file

@ -19,13 +19,6 @@
using namespace platform;
bool MACOSInstance::enumeratePlatform() {
enumerateCpu();
enumerateGpu();
enumerateRam();
return true;
}
static void getCpuId( uint32_t* p, uint32_t ax )
{
#ifdef Q_OS_MAC
@ -65,15 +58,11 @@ void MACOSInstance::enumerateCpu() {
cpu["brand"] = CPUBrandString;
cpu["model"] = CPUModelString;
cpu["clockSpeed"] = CPUClockString;
cpu["numCores"] = getNumLogicalCores();
cpu["numCores"] = std::thread::hardware_concurrency();
_cpu.push_back(cpu);
}
unsigned int MACOSInstance::getNumLogicalCores() {
return std::thread::hardware_concurrency();
}
void MACOSInstance::enumerateGpu() {
GPUIdent* ident = GPUIdent::getInstance();
json gpu = {};
@ -85,7 +74,7 @@ void MACOSInstance::enumerateGpu() {
_display = ident->getOutput();
}
void MACOSInstance::enumerateRam() {
void MACOSInstance::enumerateMemory() {
json ram = {};
#ifdef Q_OS_MAC

View file

@ -9,19 +9,15 @@
#ifndef hifi_MACOSPlatform_h
#define hifi_MACOSPlatform_h
#include "platform.h"
#include "platformInstance.h"
namespace platform {
class MACOSInstance : public Instance {
public:
bool enumeratePlatform() override;
private:
unsigned int getNumLogicalCores();
void enumerateCpu();
void enumerateRam();
void enumerateGpu();
public:
void enumerateCpu() override;
void enumerateMemory() override;
void enumerateGpu() override;
};
} // namespace platform

View file

@ -20,13 +20,6 @@
using namespace platform;
bool WINInstance::enumeratePlatform() {
enumerateCpu();
enumerateGpu();
enumerateRam();
return true;
}
void WINInstance::enumerateCpu() {
json cpu = {};
@ -56,16 +49,12 @@ void WINInstance::enumerateCpu() {
cpu["brand"] = CPUBrandString;
cpu["model"] = CPUModelString;
cpu["clockSpeed"] = CPUClockString;
cpu["numCores"] = getNumLogicalCores();
cpu["numCores"] = std::thread::hardware_concurrency();
#endif
_cpu.push_back(cpu);
}
unsigned int WINInstance::getNumLogicalCores() {
return std::thread::hardware_concurrency();
}
void WINInstance::enumerateGpu() {
GPUIdent* ident = GPUIdent::getInstance();
@ -79,8 +68,9 @@ void WINInstance::enumerateGpu() {
_display = ident->getOutput();
}
void WINInstance::enumerateRam() {
void WINInstance::enumerateMemory() {
json ram = {};
#ifdef Q_OS_WINDOWS
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
@ -88,6 +78,5 @@ void WINInstance::enumerateRam() {
int totalRam = statex.ullTotalPhys / 1024 / 1024;
ram["totalMem"] = totalRam;
#endif
_memory.push_back(ram);
}

View file

@ -9,19 +9,16 @@
#ifndef hifi_WinPlatform_h
#define hifi_WinPlatform_h
#include "platform.h"
#include "platformInstance.h"
namespace platform {
class WINInstance : public Instance {
public:
bool enumeratePlatform() override;
void enumerateCpu() override;
void enumerateMemory() override;
void enumerateGpu() override;
private:
unsigned int getNumLogicalCores();
void enumerateCpu();
void enumerateRam();
void enumerateGpu();
};
} // namespace platform

View file

@ -27,14 +27,11 @@ using namespace platform;
Instance *_instance;
void platform::create() {
#ifdef Q_OS_WIN
_instance =new WINInstance();
#endif
#ifdef Q_OS_MAC
#ifdef Q_OS_WIN
_instance =new WINInstance();
#elseif defined(Q_OS_MAC)
_instance = new MACOSInstance();
#endif
#endif
}
void platform::destroy() {
@ -42,61 +39,6 @@ void platform::destroy() {
delete _instance;
}
json Instance::getCPU(int index) {
assert(index <(int) _cpu.size());
if (index >= (int)_cpu.size())
return json();
return _cpu.at(index);
}
//These are ripe for template.. will work on that next
json Instance::getMemory(int index) {
assert(index <(int) _memory.size());
if(index >= (int)_memory.size())
return json();
return _memory.at(index);
}
json Instance::getGPU(int index) {
assert(index <(int) _gpu.size());
if (index >=(int) _gpu.size())
return json();
return _gpu.at(index);
}
json Instance::getDisplay(int index) {
assert(index <(int) _display.size());
if (index >=(int) _display.size())
return json();
return _display.at(index);
}
Instance::~Instance() {
if (_cpu.size() > 0) {
_cpu.clear();
}
if (_memory.size() > 0) {
_memory.clear();
}
if (_gpu.size() > 0) {
_gpu.clear();
}
if (_display.size() > 0) {
_display.clear();
}
}
bool platform::enumeratePlatform() {
return _instance->enumeratePlatform();
}

View file

@ -9,41 +9,15 @@
#ifndef hifi_Platform_h
#define hifi_Platform_h
#include "platformInstance.h"
#include <vector>
#include <nlohmann/json.hpp>
namespace platform {
using json = nlohmann::json;
class Instance {
public:
bool virtual enumeratePlatform() = 0;
int getNumCPU() { return (int)_cpu.size(); }
json getCPU(int index);
int getNumGPU() { return (int)_gpu.size(); }
json getGPU(int index);
int getNumMemory() { return (int)_memory.size(); }
json getMemory(int index);
int getNumDisplay() { return (int)_display.size(); }
json getDisplay(int index);
virtual ~Instance();
protected:
std::vector<json> _cpu;
std::vector<json> _memory;
std::vector<json> _gpu;
std::vector<json> _display;
};
//Platform level functions
void create();
void destroy();
bool enumeratePlatform();
int getNumCPU();

View file

@ -0,0 +1,86 @@
//
// 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 <QtGlobal>
#ifdef Q_OS_WIN
#include "WINPlatform.h"
#endif
#ifdef Q_OS_MACOS
#include "MACOSPlatform.h"
#endif
#ifdef Q_OS_LINUX
#endif
using namespace platform;
bool Instance::enumeratePlatform() {
enumerateCpu();
enumerateGpu();
enumerateMemory();
return true;
}
json Instance::getCPU(int index) {
assert(index <(int) _cpu.size());
if (index >= (int)_cpu.size())
return json();
return _cpu.at(index);
}
//These are ripe for template.. will work on that next
json Instance::getMemory(int index) {
assert(index <(int) _memory.size());
if(index >= (int)_memory.size())
return json();
return _memory.at(index);
}
json Instance::getGPU(int index) {
assert(index <(int) _gpu.size());
if (index >=(int) _gpu.size())
return json();
return _gpu.at(index);
}
json Instance::getDisplay(int index) {
assert(index <(int) _display.size());
if (index >=(int) _display.size())
return json();
return _display.at(index);
}
Instance::~Instance() {
if (_cpu.size() > 0) {
_cpu.clear();
}
if (_memory.size() > 0) {
_memory.clear();
}
if (_gpu.size() > 0) {
_gpu.clear();
}
if (_display.size() > 0) {
_display.clear();
}
}

View file

@ -0,0 +1,49 @@
//
// 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_PlatformInstance_h
#define hifi_PlatformInstance_h
#include <vector>
#include <nlohmann/json.hpp>
namespace platform {
using json = nlohmann::json;
class Instance {
public:
bool virtual enumeratePlatform();
int getNumCPU() { return (int)_cpu.size(); }
json getCPU(int index);
int getNumGPU() { return (int)_gpu.size(); }
json getGPU(int index);
int getNumMemory() { return (int)_memory.size(); }
json getMemory(int index);
int getNumDisplay() { return (int)_display.size(); }
json getDisplay(int index);
void virtual enumerateCpu()=0;
void virtual enumerateMemory()=0;
void virtual enumerateGpu()=0;
virtual ~Instance();
protected:
std::vector<json> _cpu;
std::vector<json> _memory;
std::vector<json> _gpu;
std::vector<json> _display;
};
} // namespace platform
#endif // hifi_platform_h