mirror of
https://github.com/lubosz/overte.git
synced 2025-04-17 00:57:44 +02:00
added ability to extract cpu info on osx
This commit is contained in:
parent
684d71fc5b
commit
81c0d195e3
1 changed files with 37 additions and 5 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <GPUIdent.h>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <cpuid.h>
|
||||
|
||||
using namespace platform;
|
||||
|
||||
|
@ -22,13 +23,44 @@ bool MACOSInstance::enumeratePlatform() {
|
|||
return true;
|
||||
}
|
||||
|
||||
static void getCpuId( uint32_t* p, uint32_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 MACOSInstance::enumerateCpu() {
|
||||
json *cpu= new json();
|
||||
|
||||
// (*cpu)["brand"] = ident->getName();
|
||||
// (*cpu)["model"] = CPUModelString;
|
||||
// (*cpu)["clockSpeed"] = CPUClockString;
|
||||
// (*cpu)["numCores"] = getNumLogicalCores();
|
||||
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)["brand"] = ident->getName();
|
||||
(*cpu)["model"] = CPUModelString;
|
||||
(*cpu)["clockSpeed"] = CPUClockString;
|
||||
(*cpu)["numCores"] = getNumLogicalCores();
|
||||
|
||||
_cpu.push_back(cpu);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue