From 9797f4945628c5fb2cafbf5b40a016b347476d22 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 8 Jun 2017 01:16:45 +0300 Subject: [PATCH] Add Summary. --- CMakeLists.txt | 2 + src/App.cpp | 3 + src/Cpu.h | 1 + src/Options.h | 1 + src/Summary.cpp | 85 ++++++++++++++++++++++ utils/summary.h => src/Summary.h | 8 +- utils/summary.c | 121 ------------------------------- 7 files changed, 99 insertions(+), 122 deletions(-) create mode 100644 src/Summary.cpp rename utils/summary.h => src/Summary.h (95%) delete mode 100644 utils/summary.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e863e739..66200623 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ set(HEADERS src/Options.h src/Console.h src/Cpu.h + src/Summary.h src/version.h ) @@ -25,6 +26,7 @@ set(SOURCES src/net/Url.cpp src/Options.cpp src/Console.cpp + src/Summary.cpp src/xmrig.cpp ) diff --git a/src/App.cpp b/src/App.cpp index 3269f80e..e7cf1aa4 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -31,6 +31,7 @@ #include "net/Client.h" #include "net/Network.h" #include "Options.h" +#include "Summary.h" #include "version.h" @@ -60,6 +61,8 @@ App::exec() return 0; } + Summary::print(); + m_network->connect(); const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); diff --git a/src/Cpu.h b/src/Cpu.h index 7d9e6450..292c6c6c 100644 --- a/src/Cpu.h +++ b/src/Cpu.h @@ -39,6 +39,7 @@ public: static void setAffinity(int id, unsigned long mask); static inline bool hasAES() { return m_flags & AES; } + static inline bool isX64() { return m_flags & X86_64; } static inline const char *brand() { return m_brand; } static inline int cores() { return m_totalCores; } static inline int l2() { return m_l2_cache; } diff --git a/src/Options.h b/src/Options.h index 16733cca..0c1dcc6e 100644 --- a/src/Options.h +++ b/src/Options.h @@ -51,6 +51,7 @@ public: static inline Options* i() { return m_self; } static Options *parse(int argc, char **argv); + inline bool colors() const { return m_colors; } inline bool isReady() const { return m_ready; } inline bool keepAlive() const { return m_keepAlive; } inline const char *pass() const { return m_pass; } diff --git a/src/Summary.cpp b/src/Summary.cpp new file mode 100644 index 00000000..4e047360 --- /dev/null +++ b/src/Summary.cpp @@ -0,0 +1,85 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2016-2017 XMRig + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include + + +#include "Summary.h" +#include "Console.h" +#include "Cpu.h" +#include "Options.h" +#include "version.h" + + + +static void print_versions() +{ + char *buf = static_cast(malloc(16)); + +# ifdef __GNUC__ + snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +# else + buf[0] = '\0'; +# endif + + + if (Options::i()->colors()) { + Console::i()->text("\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s", APP_VERSION, uv_version_string(), buf); + } else { + Console::i()->text(" * VERSIONS: XMRig/%s libuv/%s%s", APP_VERSION, uv_version_string(), buf); + } + + free(buf); +} + + +static void print_cpu() +{ + if (Options::i()->colors()) { + Console::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI", + Cpu::brand(), + Cpu::sockets(), + Cpu::isX64() ? "\x1B[01;32m" : "\x1B[01;31m-", + Cpu::hasAES() ? "\x1B[01;32m" : "\x1B[01;31m-"); +# ifndef XMRIG_NO_LIBCPUID + Console::i()->text("\x1B[01;32m * \x1B[01;37mCPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); +# endif + } + else { + Console::i()->text(" * CPU: %s (%d) %sx64 %sAES-NI", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); +# ifndef XMRIG_NO_LIBCPUID + Console::i()->text(" * CPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); +# endif + } +} + + +void Summary::print() +{ + print_versions(); + print_cpu(); +} + + + diff --git a/utils/summary.h b/src/Summary.h similarity index 95% rename from utils/summary.h rename to src/Summary.h index 628c5304..3f64fd60 100644 --- a/utils/summary.h +++ b/src/Summary.h @@ -24,6 +24,12 @@ #ifndef __SUMMARY_H__ #define __SUMMARY_H__ -void print_summary(); + +class Summary +{ +public: + static void print(); +}; + #endif /* __SUMMARY_H__ */ diff --git a/utils/summary.c b/utils/summary.c deleted file mode 100644 index 65912bb0..00000000 --- a/utils/summary.c +++ /dev/null @@ -1,121 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "options.h" -#include "applog.h" -#include "version.h" -#include "persistent_memory.h" -#include "cpu.h" - - -static void print_memory() { - const char *t1 = (persistent_memory_flags & MEMORY_HUGEPAGES_AVAILABLE) ? OPT_COLOR(CL_LGR, "available") : OPT_COLOR(CL_LRD, "unavailable"); - const char *t2 = (persistent_memory_flags & MEMORY_HUGEPAGES_ENABLED) ? OPT_COLOR(CL_LGR, "enabled") : OPT_COLOR(CL_LRD, "disabled"); - - if (opt_colors) { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "HUGE PAGES: %s, %s", t1, t2); - } - else { - applog_notime(LOG_INFO, " * HUGE PAGES: %s, %s", t1, t2); - } -} - - -static void print_cpu() { - const char *t1 = (cpu_info.flags & CPU_FLAG_X86_64) ? OPT_COLOR(CL_LGR, "x86_64") : OPT_COLOR(CL_LRD, "-x86_64"); - const char *t2 = (cpu_info.flags & CPU_FLAG_AES) ? OPT_COLOR(CL_LGR, "AES-NI") : OPT_COLOR(CL_LRD, "-AES-NI"); - - if (opt_colors) { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "CPU: %s (%d)", cpu_info.brand, cpu_info.sockets); - } - else { - applog_notime(LOG_INFO, " * CPU: %s (%d)", cpu_info.brand, cpu_info.sockets); - } - - # ifndef XMRIG_NO_LIBCPUID - if (opt_colors) { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "CPU L2/L3: %.1f MB/%.1f MB", cpu_info.l2_cache / 1024.0, cpu_info.l3_cache / 1024.0); - } - else { - applog_notime(LOG_INFO, " * CPU L2/L3: %.1f MB/%.1f MB", cpu_info.l2_cache / 1024.0, cpu_info.l3_cache / 1024.0); - } - # endif - - if (opt_colors) { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "CPU FEATURES: %s %s", t1, t2); - } - else { - applog_notime(LOG_INFO, " * CPU FEATURES: %s %s", t1, t2); - } -} - - -static void print_threads() { - const char *extra = ""; - if (opt_nicehash) { - extra = ", nicehash"; - } - - if (opt_colors) { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "THREADS: " CL_WHT "%d" CL_WHT ", av=%d, %s, donate=%d%%%s", opt_n_threads, opt_algo_variant, get_current_algo_name(), opt_donate_level, extra); - } - else { - applog_notime(LOG_INFO, " * THREADS: %d, av=%d, %s, donate=%d%%%s", opt_n_threads, opt_algo_variant, get_current_algo_name(), opt_donate_level, extra); - } -} - - -static void print_stratum() { - if (opt_colors) { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "STRATUM URL: " CL_LCY "%s", opt_url); - - if (opt_backup_url) { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "FAILOVER URL: " CL_LCY "%s", opt_backup_url); - } - else { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT "FAILOVER URL: " CL_LRD "none"); - } - } - else { - applog_notime(LOG_INFO, " * STRATUM URL: %s", opt_url); - applog_notime(LOG_INFO, " * FAILOVER URL: %s", opt_backup_url ? opt_backup_url : "none"); - } -} - - -void print_summary() { - if (opt_colors) { - applog_notime(LOG_INFO, CL_LGR " * " CL_WHT APP_NAME " " APP_VERSION " " CL_LCY APP_SITE); - } - else { - applog_notime(LOG_INFO, " * " APP_NAME " " APP_VERSION " " APP_SITE); - } - - print_memory(); - print_cpu(); - print_threads(); - print_stratum(); -} - - -