From f8865b1498db7d911934be4dd3e2fc7e3689a550 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 21:46:11 +0700 Subject: [PATCH] Added "verbose" option. --- src/base/io/log/Log.cpp | 7 +- src/base/io/log/Log.h | 19 ++-- src/base/kernel/config/BaseConfig.cpp | 134 +++++++++++--------------- src/base/kernel/config/BaseConfig.h | 2 + src/config.json | 1 + src/core/config/Config.cpp | 1 + src/crypto/rx/Rx_linux.cpp | 2 + src/crypto/rx/Rx_win.cpp | 16 +++ 8 files changed, 94 insertions(+), 88 deletions(-) diff --git a/src/base/io/log/Log.cpp b/src/base/io/log/Log.cpp index 2cd37242..49e08fc4 100644 --- a/src/base/io/log/Log.cpp +++ b/src/base/io/log/Log.cpp @@ -195,9 +195,10 @@ private: }; -bool Log::background = false; -bool Log::colors = true; -LogPrivate *Log::d = new LogPrivate(); +bool Log::background = false; +bool Log::colors = true; +LogPrivate *Log::d = new LogPrivate(); +uint32_t Log::verbose = 0; } /* namespace xmrig */ diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index c7e0c3f4..7b391412 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -27,6 +27,9 @@ #define XMRIG_LOG_H +#include + + namespace xmrig { @@ -56,6 +59,7 @@ public: static bool background; static bool colors; + static uint32_t verbose; private: static LogPrivate *d; @@ -119,13 +123,14 @@ private: #define CYAN_BG_BOLD(x) CYAN_BG_BOLD_S x CLEAR -#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__) -#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__) -#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__) -#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__) -#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) -#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) -#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) +#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__) +#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__) +#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__) +#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__) +#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) +#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) +#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) +#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } #ifdef APP_DEBUG # define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__) diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 76056449..07de7947 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -23,10 +23,18 @@ */ -#include -#include -#include -#include +#include "base/kernel/config/BaseConfig.h" +#include "base/io/json/Json.h" +#include "base/io/log/Log.h" +#include "base/kernel/interfaces/IJsonReader.h" +#include "rapidjson/document.h" +#include "version.h" + + +#include +#include +#include +#include #include @@ -38,80 +46,6 @@ # include "backend/cpu/Cpu.h" #endif -#ifdef XMRIG_AMD_PROJECT -# if defined(__APPLE__) -# include -# else -# include "3rdparty/CL/cl.h" -# endif -#endif - - -#ifdef XMRIG_NVIDIA_PROJECT -# include "nvidia/cryptonight.h" -#endif - - -#include "base/io/json/Json.h" -#include "base/io/log/Log.h" -#include "base/kernel/config/BaseConfig.h" -#include "base/kernel/interfaces/IJsonReader.h" -#include "donate.h" -#include "rapidjson/document.h" -#include "rapidjson/filewritestream.h" -#include "rapidjson/prettywriter.h" -#include "version.h" - - -void xmrig::BaseConfig::printVersions() -{ - char buf[256] = { 0 }; - -# if defined(__clang__) - snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); -# elif defined(__GNUC__) - snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# elif defined(_MSC_VER) - snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION); -# endif - - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf); - -# if defined(XMRIG_AMD_PROJECT) -# if CL_VERSION_2_0 - const char *ocl = "2.0"; -# elif CL_VERSION_1_2 - const char *ocl = "1.2"; -# elif CL_VERSION_1_1 - const char *ocl = "1.1"; -# elif CL_VERSION_1_0 - const char *ocl = "1.0"; -# else - const char *ocl = "0.0"; -# endif - int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl); -# elif defined(XMRIG_NVIDIA_PROJECT) - const int cudaVersion = cuda_get_runtime_version(); - int length = snprintf(buf, sizeof buf, "CUDA/%d.%d ", cudaVersion / 1000, cudaVersion % 100); -# endif - - std::string libs; - -# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT) - { - constexpr const char *v = OPENSSL_VERSION_TEXT + 8; - snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast(strchr(v, ' ') - v), v); - libs += buf; - } -# endif - -# if defined(XMRIG_FEATURE_HWLOC) - libs += Cpu::info()->backend(); -# endif - - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str()); -} - bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) { @@ -132,6 +66,7 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) m_version = reader.getUint("version"); setPrintTime(reader.getUint("print-time", 60)); + setVerbose(reader.getValue("verbose")); const rapidjson::Value &api = reader.getObject("api"); if (api.IsObject()) { @@ -162,3 +97,46 @@ bool xmrig::BaseConfig::save() return false; } + + +void xmrig::BaseConfig::printVersions() +{ + char buf[256] = { 0 }; + +# if defined(__clang__) + snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); +# elif defined(__GNUC__) + snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +# elif defined(_MSC_VER) + snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION); +# endif + + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf); + + std::string libs; + +# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT) + { + constexpr const char *v = OPENSSL_VERSION_TEXT + 8; + snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast(strchr(v, ' ') - v), v); + libs += buf; + } +# endif + +# if defined(XMRIG_FEATURE_HWLOC) + libs += Cpu::info()->backend(); +# endif + + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str()); +} + + +void xmrig::BaseConfig::setVerbose(const rapidjson::Value &value) +{ + if (value.IsBool()) { + Log::verbose = value.GetBool() ? 1 : 0; + } + else if (value.IsUint()) { + Log::verbose = value.GetUint(); + } +} diff --git a/src/base/kernel/config/BaseConfig.h b/src/base/kernel/config/BaseConfig.h index c700d109..7be81828 100644 --- a/src/base/kernel/config/BaseConfig.h +++ b/src/base/kernel/config/BaseConfig.h @@ -82,6 +82,8 @@ protected: private: inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } } + + void setVerbose(const rapidjson::Value &value); }; diff --git a/src/config.json b/src/config.json index 7156e905..a973ff2c 100644 --- a/src/config.json +++ b/src/config.json @@ -75,5 +75,6 @@ "retry-pause": 5, "syslog": false, "user-agent": null, + "verbose": 0, "watch": true } diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index a445961f..b0c92463 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -246,5 +246,6 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("retry-pause", m_pools.retryPause(), allocator); doc.AddMember("syslog", isSyslog(), allocator); doc.AddMember("user-agent", m_userAgent.toJSON(), allocator); + doc.AddMember("verbose", Log::verbose, allocator); doc.AddMember("watch", m_watch, allocator); } diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index 23d9d51f..3b3a0f1f 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -152,6 +152,8 @@ static bool wrmsr(const MsrItems &preset, bool save) if (save) { for (const auto &i : preset) { auto item = rdmsr(i.reg()); + LOG_VERBOSE(CLEAR "%s" CYAN_BOLD("0x%08" PRIx32) CYAN(":0x%016" PRIx64) CYAN_BOLD(" -> 0x%016" PRIx64), tag, i.reg(), item.value(), i.value()); + if (item.isValid()) { savedState.emplace_back(item); } diff --git a/src/crypto/rx/Rx_win.cpp b/src/crypto/rx/Rx_win.cpp index 30b76ae3..bfd923ab 100644 --- a/src/crypto/rx/Rx_win.cpp +++ b/src/crypto/rx/Rx_win.cpp @@ -134,6 +134,20 @@ static HANDLE wrmsr_install_driver() SERVICE_STATUS status; const auto rc = QueryServiceStatus(hService, &status); + if (rc && Log::verbose) { + DWORD dwBytesNeeded; + + QueryServiceConfigA(hService, nullptr, 0, &dwBytesNeeded); + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + std::vector buffer(dwBytesNeeded); + auto config = reinterpret_cast(buffer.data()); + + if (QueryServiceConfigA(hService, config, buffer.size(), &dwBytesNeeded)) { + LOG_INFO(CLEAR "%s" YELLOW("service path: ") YELLOW_BOLD("\"%s\""), tag, config->lpBinaryPathName); + } + } + } + if (rc && status.dwCurrentState == SERVICE_RUNNING) { reuseDriver = true; } @@ -246,6 +260,8 @@ static bool wrmsr(const MsrItems &preset, bool save) if (save) { for (const auto &i : preset) { auto item = rdmsr(driver, i.reg()); + LOG_VERBOSE(CLEAR "%s" CYAN_BOLD("0x%08" PRIx32) CYAN(":0x%016" PRIx64) CYAN_BOLD(" -> 0x%016" PRIx64), tag, i.reg(), item.value(), i.value()); + if (item.isValid()) { savedState.emplace_back(item); }