From f6bcba49c39a1309df7a3f5be7d45f942a7ead58 Mon Sep 17 00:00:00 2001 From: Milad Nazari Date: Wed, 15 Nov 2017 23:58:38 +0100 Subject: [PATCH] added verbosity levels option --- src/App.cpp | 13 +++++++------ src/App.h | 1 - src/Options.cpp | 18 ++++++++++++++++-- src/Options.h | 2 ++ src/Summary.cpp | 14 +++++++++++++- src/Summary.h | 1 + src/log/ConsoleLog.cpp | 3 +-- src/log/ConsoleLog.h | 3 +-- src/log/Log.cpp | 13 ++++++------- src/log/Log.h | 5 +++-- 10 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 1aae7ae0..3fe7071f 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -69,18 +69,15 @@ App::App(int argc, char **argv) : if (!m_options) { return; } - - Log::init(); + Log::init(m_options->verbosity()); if (!m_options->background()) { Log::add(new ConsoleLog(m_options->colors())); m_console = new Console(this); } - if (m_options->logFile()) { Log::add(new FileLog(m_options->logFile())); } - # ifdef HAVE_SYSLOG_H if (m_options->syslog()) { Log::add(new SysLog()); @@ -126,7 +123,12 @@ int App::exec() } Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash(), m_options->hugePages()); - Summary::print(); + if(m_options->verbosity() == 2) { + Summary::printVerbose(); + } + else if(m_options->verbosity() == 1) { + Summary::print(); + } # ifndef XMRIG_NO_API Api::start(); @@ -138,7 +140,6 @@ int App::exec() # endif Workers::start(m_options->affinity(), m_options->priority()); - m_network->connect(); const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); diff --git a/src/App.h b/src/App.h index 781f78f2..4d17d4de 100644 --- a/src/App.h +++ b/src/App.h @@ -53,7 +53,6 @@ private: void close(); static void onSignal(uv_signal_t *handle, int signum); - static App *m_self; Console *m_console; diff --git a/src/Options.cpp b/src/Options.cpp index b1197223..40c65a63 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -62,6 +62,7 @@ Options:\n\ -p, --pass=PASSWORD password for mining server\n\ -t, --threads=N number of miner threads\n\ -v, --av=N algorithm variation, 0 auto select\n\ + -b, --verbosity=N verbosity level of logs (0-2), 2 auto select\n\ -k, --keepalive send keepalived for prevent timeout (need pool support)\n\ -r, --retries=N number of times to retry before switch to backup server (default: 5)\n\ -R, --retry-pause=N time to pause between retries (default: 5)\n\ @@ -91,12 +92,13 @@ Options:\n\ "; -static char const short_options[] = "a:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S"; +static char const short_options[] = "a:b:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S"; static struct option const options[] = { { "algo", 1, nullptr, 'a' }, { "av", 1, nullptr, 'v' }, + { "verbosity", 1, nullptr, 'b' }, { "background", 0, nullptr, 'B' }, { "config", 1, nullptr, 'c' }, { "cpu-affinity", 1, nullptr, 1020 }, @@ -131,6 +133,7 @@ static struct option const options[] = { static struct option const config_options[] = { { "algo", 1, nullptr, 'a' }, { "av", 1, nullptr, 'v' }, + { "verbosity", 1, nullptr, 'b' }, { "background", 0, nullptr, 'B' }, { "colors", 0, nullptr, 2000 }, { "cpu-affinity", 1, nullptr, 1020 }, @@ -210,6 +213,7 @@ Options::Options(int argc, char **argv) : m_userAgent(nullptr), m_algo(0), m_algoVariant(0), + m_verbosity(2), m_apiPort(0), m_donateLevel(kDonateLevel), m_maxCpuUsage(75), @@ -367,6 +371,7 @@ bool Options::parseArg(int key, const char *arg) case 'r': /* --retries */ case 'R': /* --retry-pause */ case 'v': /* --av */ + case 'b': /* --verbosity */ case 1003: /* --donate-level */ case 1004: /* --max-cpu-usage */ case 1007: /* --print-time */ @@ -414,7 +419,7 @@ bool Options::parseArg(int key, const char *arg) free(m_userAgent); m_userAgent = strdup(arg); break; - + default: showUsage(1); return false; @@ -462,6 +467,15 @@ bool Options::parseArg(int key, uint64_t arg) m_algoVariant = (int) arg; break; + + case 'b': /* --verbosity */ + if(arg < 0 || arg > 2) { + showUsage(1); + return false; + } + + m_verbosity = (int) arg; + break; case 1003: /* --donate-level */ if (arg < 1 || arg > 99) { diff --git a/src/Options.h b/src/Options.h index 06b86f38..7d91bef8 100644 --- a/src/Options.h +++ b/src/Options.h @@ -68,6 +68,7 @@ public: inline const std::vector &pools() const { return m_pools; } inline int algo() const { return m_algo; } inline int algoVariant() const { return m_algoVariant; } + inline int verbosity() const { return m_verbosity; } inline int apiPort() const { return m_apiPort; } inline int donateLevel() const { return m_donateLevel; } inline int printTime() const { return m_printTime; } @@ -127,6 +128,7 @@ private: int m_retries; int m_retryPause; int m_threads; + int m_verbosity; int64_t m_affinity; std::vector m_pools; }; diff --git a/src/Summary.cpp b/src/Summary.cpp index c6c53341..65a2d6b0 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -34,7 +34,6 @@ #include "Summary.h" #include "version.h" - static void print_versions() { char buf[16]; @@ -158,6 +157,19 @@ void Summary::print() print_threads(); print_pools(); +# ifndef XMRIG_NO_API + print_api(); +# endif +} + +void Summary::printVerbose() +{ + print_versions(); + print_memory(); + print_cpu(); + print_threads(); + print_pools(); + # ifndef XMRIG_NO_API print_api(); # endif diff --git a/src/Summary.h b/src/Summary.h index 3f64fd60..bde9fbe7 100644 --- a/src/Summary.h +++ b/src/Summary.h @@ -29,6 +29,7 @@ class Summary { public: static void print(); + static void printVerbose(); }; diff --git a/src/log/ConsoleLog.cpp b/src/log/ConsoleLog.cpp index ef8516eb..e8cab33b 100644 --- a/src/log/ConsoleLog.cpp +++ b/src/log/ConsoleLog.cpp @@ -62,7 +62,6 @@ ConsoleLog::ConsoleLog(bool colors) : # endif } - void ConsoleLog::message(int level, const char* fmt, va_list args) { if (!isWritable()) { @@ -113,7 +112,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) m_colors ? color : "", fmt, m_colors ? Log::kCL_N : "" - ); + ); print(args); } diff --git a/src/log/ConsoleLog.h b/src/log/ConsoleLog.h index a04a27c5..125e00f1 100644 --- a/src/log/ConsoleLog.h +++ b/src/log/ConsoleLog.h @@ -27,9 +27,8 @@ #include - #include "interfaces/ILogBackend.h" - +#include "App.h" class ConsoleLog : public ILogBackend { diff --git a/src/log/Log.cpp b/src/log/Log.cpp index 3e5d5671..656cb491 100644 --- a/src/log/Log.cpp +++ b/src/log/Log.cpp @@ -35,17 +35,17 @@ Log *Log::m_self = nullptr; - void Log::message(Log::Level level, const char* fmt, ...) { va_list args; va_list copy; va_start(args, fmt); - - for (ILogBackend *backend : m_backends) { - va_copy(copy, args); - backend->message(level, fmt, copy); - va_end(copy); + if(verbosity == 2) { + for (ILogBackend *backend : m_backends) { + va_copy(copy, args); + backend->message(level, fmt, copy); + va_end(copy); + } } } @@ -65,7 +65,6 @@ void Log::text(const char* fmt, ...) va_end(args); } - Log::~Log() { for (auto backend : m_backends) { diff --git a/src/log/Log.h b/src/log/Log.h index fd944d80..075ea24e 100644 --- a/src/log/Log.h +++ b/src/log/Log.h @@ -56,18 +56,19 @@ public: static inline Log* i() { return m_self; } static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); } - static inline void init() { if (!m_self) { m_self = new Log();} } + static inline void init(int verbosityL) { if (!m_self) {m_self = new Log(verbosityL);}} static inline void release() { delete m_self; } void message(Level level, const char* fmt, ...); void text(const char* fmt, ...); private: - inline Log() {} + inline Log(int verbosityL): verbosity(verbosityL) {} ~Log(); static Log *m_self; std::vector m_backends; + int verbosity; };