Added Cpu::toJSON
This commit is contained in:
parent
91f732794b
commit
73558a0eaa
3 changed files with 42 additions and 7 deletions
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "backend/cpu/Cpu.h"
|
#include "backend/cpu/Cpu.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(XMRIG_FEATURE_HWLOC)
|
#if defined(XMRIG_FEATURE_HWLOC)
|
||||||
|
@ -41,6 +42,18 @@
|
||||||
static xmrig::ICpuInfo *cpuInfo = nullptr;
|
static xmrig::ICpuInfo *cpuInfo = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
const char *xmrig::Cpu::backend()
|
||||||
|
{
|
||||||
|
# if defined(XMRIG_FEATURE_HWLOC)
|
||||||
|
return "hwloc";
|
||||||
|
# elif defined(XMRIG_FEATURE_LIBCPUID)
|
||||||
|
return "libcpuid";
|
||||||
|
# else
|
||||||
|
return "basic";
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
xmrig::ICpuInfo *xmrig::Cpu::info()
|
xmrig::ICpuInfo *xmrig::Cpu::info()
|
||||||
{
|
{
|
||||||
assert(cpuInfo != nullptr);
|
assert(cpuInfo != nullptr);
|
||||||
|
@ -49,6 +62,32 @@ xmrig::ICpuInfo *xmrig::Cpu::info()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::Cpu::toJSON(rapidjson::Document &doc)
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
ICpuInfo *i = info();
|
||||||
|
Value cpu(kObjectType);
|
||||||
|
Assembly assembly(i->assembly());
|
||||||
|
|
||||||
|
cpu.AddMember("brand", StringRef(i->brand()), allocator);
|
||||||
|
cpu.AddMember("aes", i->hasAES(), allocator);
|
||||||
|
cpu.AddMember("avx2", i->hasAVX2(), allocator);
|
||||||
|
cpu.AddMember("x64", i->isX64(), allocator);
|
||||||
|
cpu.AddMember("assembly", StringRef(assembly.toString()), allocator);
|
||||||
|
cpu.AddMember("l2", static_cast<uint64_t>(i->L2()), allocator);
|
||||||
|
cpu.AddMember("l3", static_cast<uint64_t>(i->L3()), allocator);
|
||||||
|
cpu.AddMember("cores", static_cast<uint64_t>(i->cores()), allocator);
|
||||||
|
cpu.AddMember("threads", static_cast<uint64_t>(i->threads()), allocator);
|
||||||
|
cpu.AddMember("packages", static_cast<uint64_t>(i->packages()), allocator);
|
||||||
|
cpu.AddMember("nodes", static_cast<uint64_t>(i->nodes()), allocator);
|
||||||
|
cpu.AddMember("backend", StringRef(backend()), allocator);
|
||||||
|
|
||||||
|
return cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Cpu::init()
|
void xmrig::Cpu::init()
|
||||||
{
|
{
|
||||||
assert(cpuInfo == nullptr);
|
assert(cpuInfo == nullptr);
|
||||||
|
|
|
@ -35,7 +35,9 @@ namespace xmrig {
|
||||||
class Cpu
|
class Cpu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static const char *backend();
|
||||||
static ICpuInfo *info();
|
static ICpuInfo *info();
|
||||||
|
static rapidjson::Value toJSON(rapidjson::Document &doc);
|
||||||
static void init();
|
static void init();
|
||||||
static void release();
|
static void release();
|
||||||
|
|
||||||
|
|
|
@ -130,16 +130,10 @@ public:
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
Value cpu(kObjectType);
|
|
||||||
cpu.AddMember("brand", StringRef(Cpu::info()->brand()), allocator);
|
|
||||||
cpu.AddMember("aes", Cpu::info()->hasAES(), allocator);
|
|
||||||
cpu.AddMember("x64", Cpu::info()->isX64(), allocator);
|
|
||||||
cpu.AddMember("sockets", static_cast<uint64_t>(Cpu::info()->packages()), allocator);
|
|
||||||
|
|
||||||
reply.AddMember("version", APP_VERSION, allocator);
|
reply.AddMember("version", APP_VERSION, allocator);
|
||||||
reply.AddMember("kind", APP_KIND, allocator);
|
reply.AddMember("kind", APP_KIND, allocator);
|
||||||
reply.AddMember("ua", StringRef(Platform::userAgent()), allocator);
|
reply.AddMember("ua", StringRef(Platform::userAgent()), allocator);
|
||||||
reply.AddMember("cpu", cpu, allocator);
|
reply.AddMember("cpu", Cpu::toJSON(doc), allocator);
|
||||||
|
|
||||||
if (version == 1) {
|
if (version == 1) {
|
||||||
reply.AddMember("hugepages", false, allocator);
|
reply.AddMember("hugepages", false, allocator);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue