adding macos platform. Misisng display and cpu info

This commit is contained in:
amerhifi 2019-05-10 09:55:26 -07:00
parent b998008f01
commit edb3206a24
7 changed files with 73 additions and 93 deletions

View file

@ -2495,10 +2495,10 @@ void Application::initPlatform() {
platform::enumeratePlatform();
nlohmann::json test = platform::getGraphics(0);
nlohmann::json test1 = platform::getProcessor(0);
nlohmann::json test2 = platform::getMemory(0);
nlohmann::json test3 = platform::getDisplay(0);
const nlohmann::json* test = platform::getGraphics(0);
const nlohmann::json* test1 = platform::getProcessor(0);
const nlohmann::json* test2 = platform::getMemory(0);
//const nlohmann::json* test3 = platform::getDisplay(0);
}
void Application::updateVerboseLogging() {

View file

@ -7,11 +7,11 @@
//
#include "MACOSPlatform.h"
#include <intrin.h>
#include <thread>
#include <GPUIdent.h>
#include <string>
#include <unistd.h>
using namespace platform;
using namespace nlohmann;
@ -23,44 +23,26 @@ bool MACOSInstance::enumeratePlatform() {
return true;
}
void WINInstance::enumerateCpu() {
void MACOSInstance::enumerateCpu() {
json *cpu= new json();
int CPUInfo[4] = { -1 };
unsigned nExIds;
unsigned int i = 0;
char CPUBrandString[16];
char CPUModelString[16];
char CPUClockString[16];
// Get the information associated with each extended ID.
__cpuid(CPUInfo, 0x80000000);
nExIds = CPUInfo[0];
for (i = 0x80000000; i <= nExIds; ++i) {
__cpuid(CPUInfo, i);
// Interpret CPU brand string
if (i == 0x80000002) {
memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
} else if (i == 0x80000003) {
memcpy(CPUModelString, CPUInfo, sizeof(CPUInfo));
} else if (i == 0x80000004) {
memcpy(CPUClockString, CPUInfo, sizeof(CPUInfo));
}
}
(*cpu)["brand"] = CPUBrandString;
(*cpu)["model"] = CPUModelString;
(*cpu)["clockSpeed"] = CPUClockString;
(*cpu)["numCores"] = getNumLogicalCores();
// (*cpu)["brand"] = ident->getName();
// (*cpu)["model"] = CPUModelString;
// (*cpu)["clockSpeed"] = CPUClockString;
// (*cpu)["numCores"] = getNumLogicalCores();
_cpu.push_back(cpu);
}
unsigned int WINInstance::getNumLogicalCores() {
unsigned int MACOSInstance::getNumLogicalCores() {
return std::thread::hardware_concurrency();
}
void WINInstance::enumerateGpu() {
void MACOSInstance::enumerateGpu() {
GPUIdent* ident = GPUIdent::getInstance();
@ -73,14 +55,12 @@ void WINInstance::enumerateGpu() {
_display = ident->getOutput();
}
void WINInstance::enumerateRam() {
void MACOSInstance::enumerateRam() {
json* ram = new json();
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
int totalRam = statex.ullTotalPhys / 1024 / 1024;
(*ram)["totalMem"] = totalRam;
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
(*ram)["totalMem"] = pages * page_size;;
_memory.push_back(ram);
}

View file

@ -6,8 +6,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_WinPlatform_h
#define hifi_WinPlatform_h
#ifndef hifi_MACOSPlatform_h
#define hifi_MACOSPlatform_h
#include "platform.h"
#include <nlohmann/json.hpp>
@ -30,4 +30,4 @@ namespace platform {
} // namespace platform
#endif //hifi_winplatform_h
#endif //hifi_winplatform_h

View file

@ -7,8 +7,10 @@
//
#include "WINPlatform.h"
#ifdef Q_OS_WINDOWS
#include <intrin.h>
#include <Windows.h>
#endif
#include <thread>
#include <GPUIdent.h>
#include <string>
@ -33,6 +35,7 @@ void WINInstance::enumerateCpu() {
char CPUModelString[16];
char CPUClockString[16];
#ifdef Q_OS_WINDOWS
// Get the information associated with each extended ID.
__cpuid(CPUInfo, 0x80000000);
nExIds = CPUInfo[0];
@ -53,7 +56,7 @@ void WINInstance::enumerateCpu() {
(*cpu)["model"] = CPUModelString;
(*cpu)["clockSpeed"] = CPUClockString;
(*cpu)["numCores"] = getNumLogicalCores();
#endif
_cpu.push_back(cpu);
}
@ -76,12 +79,12 @@ void WINInstance::enumerateGpu() {
void WINInstance::enumerateRam() {
json* ram = new json();
#ifdef Q_OS_WINDOWS
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
int totalRam = statex.ullTotalPhys / 1024 / 1024;
(*ram)["totalMem"] = totalRam;
#endif
_memory.push_back(ram);
}

View file

@ -16,7 +16,7 @@
#endif
#ifdef Q_OS_MACOS
#include "MACPlatform.h"
#include "MACOSPlatform.h"
#endif
#ifdef Q_OS_LINUX
@ -31,7 +31,10 @@ void platform::create() {
#ifdef Q_OS_WIN
_instance =new WINInstance();
#elif Q_OS_MAC
#endif
#ifdef Q_OS_MAC
_instance = new MACOSInstance();
#endif
}
@ -39,45 +42,37 @@ void platform::destroy() {
delete _instance;
}
json Instance::getCPU(int index) {
assert(index < _cpu.size());
json result;
if (index >= _cpu.size())
return result;
json* Instance::getCPU(int index) {
assert(index <(int) _cpu.size());
if (index >= (int)_cpu.size())
return nullptr;
return _cpu.at(index);
}
//These are ripe for template.. will work on that next
json Instance::getMemory(int index) {
assert(index < _memory.size());
json result;
if(index>= _memory.size())
return result;
json* Instance::getMemory(int index) {
assert(index <(int) _memory.size());
if(index >= (int)_memory.size())
return nullptr;
return _memory.at(index);
}
json Instance::getGPU(int index) {
assert(index < _gpu.size());
json result;
if (index >= _gpu.size())
return result;
json* Instance::getGPU(int index) {
assert(index <(int) _gpu.size());
if (index >=(int) _gpu.size())
return nullptr;
return _gpu.at(index);
}
json Instance::getDisplay(int index) {
assert(index < _display.size());
json result;
if (index >= _display.size())
return result;
json* Instance::getDisplay(int index) {
assert(index <(int) _display.size());
if (index >=(int) _display.size())
return nullptr;
return _display.at(index);
}
@ -123,7 +118,7 @@ int platform::getNumProcessor() {
return _instance->getNumCPU();
}
json platform::getProcessor(int index) {
const json* platform::getProcessor(int index) {
return _instance->getCPU(index);
}
@ -131,7 +126,7 @@ int platform::getNumGraphics() {
return _instance->getNumGPU();
}
nlohmann::json platform::getGraphics(int index) {
const json* platform::getGraphics(int index) {
return _instance->getGPU(index);
}
@ -139,15 +134,17 @@ int platform::getNumDisplay() {
return _instance->getNumDisplay();
}
nlohmann::json platform::getDisplay(int index) {
const json* platform::getDisplay(int index) {
return _instance->getDisplay(index);
}
json platform::getMemory(int index) {
return _instance->getMemory(index);
}
int platform::getNumMemory() {
return _instance->getNumMemory();
}
const json* platform::getMemory(int index) {
return _instance->getMemory(index);
}

View file

@ -21,18 +21,18 @@ public:
bool virtual enumeratePlatform() = 0;
int getNumCPU() { return _cpu.size(); }
nlohmann::json getCPU(int index);
nlohmann::json* getCPU(int index);
int getNumGPU() { return _gpu.size(); }
nlohmann::json getGPU(int index);
nlohmann::json* getGPU(int index);
int getNumMemory() { return _memory.size(); }
nlohmann::json getMemory(int index);
nlohmann::json* getMemory(int index);
int getNumDisplay() { return _display.size(); }
nlohmann::json getDisplay(int index);
nlohmann::json* getDisplay(int index);
~Instance();
virtual ~Instance();
protected:
std::vector<nlohmann::json*> _cpu;
@ -49,17 +49,17 @@ void destroy();
bool enumeratePlatform();
int getNumProcessor();
nlohmann::json getProcessor(int index);
const nlohmann::json* getProcessor(int index);
int getNumGraphics();
nlohmann::json getGraphics(int index);
const nlohmann::json* getGraphics(int index);
int getNumDisplay();
nlohmann::json getDisplay(int index);
const nlohmann::json* getDisplay(int index);
int getNumMemory();
nlohmann::json getMemory(int index);
const nlohmann::json* getMemory(int index);
} // namespace platform
#endif // hifi_platform_h
#endif // hifi_platform_h

View file

@ -17,7 +17,7 @@
#include <cstdint>
#include <QString>
#include <memory>
#include <nlohmann\json.hpp>
#include <nlohmann/json.hpp>
#include <vector>
class GPUIdent