diff --git a/src/backend/cpu/Cpu.cpp b/src/backend/cpu/Cpu.cpp index 603ce6348..d32b2d8e9 100644 --- a/src/backend/cpu/Cpu.cpp +++ b/src/backend/cpu/Cpu.cpp @@ -27,6 +27,7 @@ #include "backend/cpu/Cpu.h" +#include "rapidjson/document.h" #if defined(XMRIG_FEATURE_HWLOC) @@ -41,6 +42,18 @@ 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() { 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(i->L2()), allocator); + cpu.AddMember("l3", static_cast(i->L3()), allocator); + cpu.AddMember("cores", static_cast(i->cores()), allocator); + cpu.AddMember("threads", static_cast(i->threads()), allocator); + cpu.AddMember("packages", static_cast(i->packages()), allocator); + cpu.AddMember("nodes", static_cast(i->nodes()), allocator); + cpu.AddMember("backend", StringRef(backend()), allocator); + + return cpu; +} + + void xmrig::Cpu::init() { assert(cpuInfo == nullptr); diff --git a/src/backend/cpu/Cpu.h b/src/backend/cpu/Cpu.h index 23cf37e6b..4638b568c 100644 --- a/src/backend/cpu/Cpu.h +++ b/src/backend/cpu/Cpu.h @@ -35,7 +35,9 @@ namespace xmrig { class Cpu { public: + static const char *backend(); static ICpuInfo *info(); + static rapidjson::Value toJSON(rapidjson::Document &doc); static void init(); static void release(); diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index d0bfa78fa..526c4fbfb 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -130,16 +130,10 @@ public: using namespace rapidjson; 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(Cpu::info()->packages()), allocator); - reply.AddMember("version", APP_VERSION, allocator); reply.AddMember("kind", APP_KIND, allocator); reply.AddMember("ua", StringRef(Platform::userAgent()), allocator); - reply.AddMember("cpu", cpu, allocator); + reply.AddMember("cpu", Cpu::toJSON(doc), allocator); if (version == 1) { reply.AddMember("hugepages", false, allocator);