mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
87 lines
2.2 KiB
C++
87 lines
2.2 KiB
C++
//
|
|
// 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 "WINPlatform.h"
|
|
#include <intrin.h>
|
|
#include <Windows.h>
|
|
#include <thread>
|
|
#include <GPUIdent.h>
|
|
#include <string>
|
|
|
|
|
|
using namespace platform;
|
|
using namespace nlohmann;
|
|
|
|
bool WINInstance::enumeratePlatform() {
|
|
enumerateCpu();
|
|
enumerateGpu();
|
|
enumerateRam();
|
|
return true;
|
|
}
|
|
|
|
void WINInstance::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.push_back(cpu);
|
|
}
|
|
|
|
unsigned int WINInstance::getNumLogicalCores() {
|
|
return std::thread::hardware_concurrency();
|
|
}
|
|
|
|
void WINInstance::enumerateGpu() {
|
|
|
|
GPUIdent* ident = GPUIdent::getInstance();
|
|
|
|
json *gpu = new json();
|
|
(*gpu)["name"] = ident->getName().toUtf8().constData();
|
|
(*gpu)["memory"] = ident->getMemory();
|
|
(*gpu)["driver"] = ident->getDriver().toUtf8().constData();
|
|
|
|
_gpu.push_back(gpu);
|
|
_display = ident->getOutput();
|
|
}
|
|
|
|
void WINInstance::enumerateRam() {
|
|
json* ram = new json();
|
|
|
|
MEMORYSTATUSEX statex;
|
|
statex.dwLength = sizeof(statex);
|
|
GlobalMemoryStatusEx(&statex);
|
|
int totalRam = statex.ullTotalPhys / 1024 / 1024;
|
|
(*ram)["totalMem"] = totalRam;
|
|
|
|
_memory.push_back(ram);
|
|
}
|