From 1cb4d73fe3f1a39da46a6353d4e619b2acd0d956 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 1 Nov 2019 00:09:28 +0700 Subject: [PATCH] Added manual (e key) health reports. --- src/App.cpp | 25 ++---------- src/Summary.cpp | 6 +-- src/backend/common/interfaces/IBackend.h | 1 + src/backend/cpu/CpuBackend.h | 2 + src/backend/cuda/CudaBackend.cpp | 49 +++++++++++++++++++++++- src/backend/cuda/CudaBackend.h | 1 + src/backend/opencl/OclBackend.h | 2 + src/core/Miner.cpp | 28 ++++++++++++++ src/core/Miner.h | 1 + 9 files changed, 89 insertions(+), 26 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 7db2ace28..04b054515 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -98,29 +98,12 @@ int xmrig::App::exec() void xmrig::App::onConsoleCommand(char command) { - switch (command) { - case 'h': - case 'H': - m_controller->miner()->printHashrate(true); - break; - - case 'p': - case 'P': - m_controller->miner()->setEnabled(false); - break; - - case 'r': - case 'R': - m_controller->miner()->setEnabled(true); - break; - - case 3: + if (command == 3) { LOG_WARN("Ctrl+C received, exiting"); close(); - break; - - default: - break; + } + else { + m_controller->miner()->execCommand(command); } } diff --git a/src/Summary.cpp b/src/Summary.cpp index 2b8939a7a..2055e972a 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -126,9 +126,9 @@ static void print_threads(Config *config) static void print_commands(Config *) { if (Log::colors) { - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") - MAGENTA_BOLD("p") WHITE_BOLD("ause, ") - MAGENTA_BOLD("r") WHITE_BOLD("esume")); + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BG(WHITE_BOLD_S "h") WHITE_BOLD("ashrate, ") + MAGENTA_BG(WHITE_BOLD_S "p") WHITE_BOLD("ause, ") + MAGENTA_BG(WHITE_BOLD_S "r") WHITE_BOLD("esume")); } else { Log::print(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); diff --git a/src/backend/common/interfaces/IBackend.h b/src/backend/common/interfaces/IBackend.h index f90732293..c6e05bcfb 100644 --- a/src/backend/common/interfaces/IBackend.h +++ b/src/backend/common/interfaces/IBackend.h @@ -53,6 +53,7 @@ public: virtual const Hashrate *hashrate() const = 0; virtual const String &profileName() const = 0; virtual const String &type() const = 0; + virtual void execCommand(char command) = 0; virtual void prepare(const Job &nextJob) = 0; virtual void printHashrate(bool details) = 0; virtual void setJob(const Job &job) = 0; diff --git a/src/backend/cpu/CpuBackend.h b/src/backend/cpu/CpuBackend.h index d5d9fbf6c..d0e2267a2 100644 --- a/src/backend/cpu/CpuBackend.h +++ b/src/backend/cpu/CpuBackend.h @@ -50,6 +50,8 @@ public: ~CpuBackend() override; protected: + inline void execCommand(char) override {} + bool isEnabled() const override; bool isEnabled(const Algorithm &algorithm) const override; const Hashrate *hashrate() const override; diff --git a/src/backend/cuda/CudaBackend.cpp b/src/backend/cuda/CudaBackend.cpp index 6abd79b50..6bc0d81ca 100644 --- a/src/backend/cuda/CudaBackend.cpp +++ b/src/backend/cuda/CudaBackend.cpp @@ -165,8 +165,11 @@ public: if (NvmlLib::init(cuda.nvmlLoader())) { NvmlLib::assign(devices); - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") WHITE_BOLD("%s") "/" GREEN_BOLD("%s"), kNvmlLabel, - NvmlLib::version(), NvmlLib::driverVersion()); + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") WHITE_BOLD("%s") "/" GREEN_BOLD("%s") " press " MAGENTA_BG(WHITE_BOLD_S "e") " for health report", + kNvmlLabel, + NvmlLib::version(), + NvmlLib::driverVersion() + ); } else { printDisabled(kLabel, RED_S " (failed to load NVML)"); @@ -230,6 +233,38 @@ public: } +# ifdef XMRIG_FEATURE_NVML + void printHealth() + { + for (const auto &device : devices) { + const auto health = NvmlLib::health(device.nvmlDevice()); + + std::string clocks; + if (health.clock && health.memClock) { + clocks += " " + std::to_string(health.clock) + "/" + std::to_string(health.memClock) + " MHz"; + } + + std::string fans; + if (!health.fanSpeed.empty()) { + for (uint32_t i = 0; i < health.fanSpeed.size(); ++i) { + fans += " fan" + std::to_string(i) + ":" CYAN_BOLD_S + std::to_string(health.fanSpeed[i]) + "%" CLEAR; + } + } + + LOG_INFO(CYAN_BOLD("#%u") YELLOW(" %s") MAGENTA_BOLD("%4uW") CSI "1;%um %2uC" CLEAR WHITE_BOLD("%s") "%s", + device.index(), + device.topology().toString().data(), + health.power, + health.temperature < 60 ? 32 : (health.temperature > 85 ? 31 : 33), + health.temperature, + clocks.c_str(), + fans.c_str() + ); + } + } +# endif + + Algorithm algo; Controller *controller; CudaLaunchStatus status; @@ -300,6 +335,16 @@ const xmrig::String &xmrig::CudaBackend::type() const } +void xmrig::CudaBackend::execCommand(char command) +{ +# ifdef XMRIG_FEATURE_NVML + if (command == 'e' || command == 'E') { + d_ptr->printHealth(); + } +# endif +} + + void xmrig::CudaBackend::prepare(const Job &) { } diff --git a/src/backend/cuda/CudaBackend.h b/src/backend/cuda/CudaBackend.h index 0d2a2395d..cf0bb6217 100644 --- a/src/backend/cuda/CudaBackend.h +++ b/src/backend/cuda/CudaBackend.h @@ -56,6 +56,7 @@ protected: const Hashrate *hashrate() const override; const String &profileName() const override; const String &type() const override; + void execCommand(char command) override; void prepare(const Job &nextJob) override; void printHashrate(bool details) override; void setJob(const Job &job) override; diff --git a/src/backend/opencl/OclBackend.h b/src/backend/opencl/OclBackend.h index 57f5db38d..59bea0aa5 100644 --- a/src/backend/opencl/OclBackend.h +++ b/src/backend/opencl/OclBackend.h @@ -51,6 +51,8 @@ public: ~OclBackend() override; protected: + inline void execCommand(char) override {} + bool isEnabled() const override; bool isEnabled(const Algorithm &algorithm) const override; const Hashrate *hashrate() const override; diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 762539c1a..a28ccbbfe 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -328,6 +328,34 @@ xmrig::Job xmrig::Miner::job() const } +void xmrig::Miner::execCommand(char command) +{ + switch (command) { + case 'h': + case 'H': + printHashrate(true); + break; + + case 'p': + case 'P': + setEnabled(false); + break; + + case 'r': + case 'R': + setEnabled(true); + break; + + default: + break; + } + + for (auto backend : d_ptr->backends) { + backend->execCommand(command); + } +} + + void xmrig::Miner::pause() { d_ptr->active = false; diff --git a/src/core/Miner.h b/src/core/Miner.h index 6f4149c30..f40e37f69 100644 --- a/src/core/Miner.h +++ b/src/core/Miner.h @@ -59,6 +59,7 @@ public: const Algorithms &algorithms() const; const std::vector &backends() const; Job job() const; + void execCommand(char command); void pause(); void printHashrate(bool details); void setEnabled(bool enabled);