xmrig/src/Summary.cpp

223 lines
6.9 KiB
C++
Raw Normal View History

2017-06-07 22:16:45 +00:00
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <support@xmrig.com>
2017-06-07 22:16:45 +00:00
*
* 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 <http://www.gnu.org/licenses/>.
*/
2019-10-21 16:01:30 +00:00
#include <cinttypes>
#include <cstdio>
2017-06-07 22:16:45 +00:00
#include <uv.h>
#include "backend/cpu/Cpu.h"
2019-03-26 18:29:37 +00:00
#include "base/io/log/Log.h"
2019-03-14 18:50:35 +00:00
#include "base/net/stratum/Pool.h"
#include "core/config/Config.h"
#include "core/Controller.h"
2019-06-28 06:08:08 +00:00
#include "crypto/common/Assembly.h"
2019-07-16 21:57:58 +00:00
#include "crypto/common/VirtualMemory.h"
2017-06-07 22:51:24 +00:00
#include "Summary.h"
2017-06-07 22:16:45 +00:00
#include "version.h"
2021-01-18 04:23:29 +00:00
#ifdef XMRIG_FEATURE_DMI
# include "hw/dmi/DmiReader.h"
#endif
#ifdef XMRIG_ALGO_RANDOMX
# include "crypto/rx/RxConfig.h"
#endif
2019-07-23 00:45:00 +00:00
namespace xmrig {
2020-12-15 18:59:20 +00:00
#ifdef XMRIG_OS_WIN
static constexpr const char *kHugepagesSupported = GREEN_BOLD("permission granted");
#else
static constexpr const char *kHugepagesSupported = GREEN_BOLD("supported");
#endif
#ifdef XMRIG_FEATURE_ASM
2018-09-24 11:19:26 +00:00
static const char *coloredAsmNames[] = {
2019-03-26 18:29:37 +00:00
RED_BOLD("none"),
2018-09-24 11:19:26 +00:00
"auto",
2019-03-26 18:29:37 +00:00
GREEN_BOLD("intel"),
GREEN_BOLD("ryzen"),
GREEN_BOLD("bulldozer")
2018-09-24 11:19:26 +00:00
};
2019-07-23 00:45:00 +00:00
inline static const char *asmName(Assembly::Id assembly)
2018-09-24 11:19:26 +00:00
{
2019-03-26 18:29:37 +00:00
return coloredAsmNames[assembly];
2018-09-24 11:19:26 +00:00
}
#endif
static void print_pages(const Config *config)
2019-12-08 07:30:44 +00:00
{
2019-07-23 00:45:00 +00:00
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s",
2020-12-15 18:59:20 +00:00
"HUGE PAGES", config->cpu().isHugePages() ? (VirtualMemory::isHugepagesAvailable() ? kHugepagesSupported : RED_BOLD("unavailable")) : RED_BOLD("disabled"));
# ifdef XMRIG_ALGO_RANDOMX
# ifdef XMRIG_OS_LINUX
2019-12-05 18:39:47 +00:00
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s",
2020-12-15 18:59:20 +00:00
"1GB PAGES", (VirtualMemory::isOneGbPagesAvailable() ? (config->rx().isOneGbPages() ? kHugepagesSupported : YELLOW_BOLD("disabled")) : YELLOW_BOLD("unavailable")));
# else
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", "1GB PAGES", YELLOW_BOLD("unavailable"));
# endif
2018-04-15 04:08:47 +00:00
# endif
2017-06-09 22:20:54 +00:00
}
static void print_cpu(const Config *)
2017-06-07 22:16:45 +00:00
{
const auto info = Cpu::info();
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%zu)") " %s %sAES%s",
2019-03-26 18:29:37 +00:00
"CPU",
2019-07-23 00:12:56 +00:00
info->brand(),
info->packages(),
ICpuInfo::is64bit() ? GREEN_BOLD("64-bit") : RED_BOLD("32-bit"),
2020-12-06 16:34:01 +00:00
info->hasAES() ? GREEN_BOLD_S : RED_BOLD_S "-",
info->isVM() ? RED_BOLD_S " VM" : ""
2019-07-23 00:12:56 +00:00
);
2020-12-06 14:51:24 +00:00
# if defined(XMRIG_FEATURE_HWLOC)
2019-07-26 08:29:06 +00:00
Log::print(WHITE_BOLD(" %-13s") BLACK_BOLD("L2:") WHITE_BOLD("%.1f MB") BLACK_BOLD(" L3:") WHITE_BOLD("%.1f MB")
CYAN_BOLD(" %zu") "C" BLACK_BOLD("/") CYAN_BOLD("%zu") "T"
BLACK_BOLD(" NUMA:") CYAN_BOLD("%zu"),
"",
2019-07-23 00:12:56 +00:00
info->L2() / 1048576.0,
info->L3() / 1048576.0,
info->cores(),
info->threads(),
info->nodes()
2019-07-23 00:12:56 +00:00
);
# else
Log::print(WHITE_BOLD(" %-13s") BLACK_BOLD("threads:") CYAN_BOLD("%zu"), "", info->threads());
2019-03-26 18:29:37 +00:00
# endif
2017-06-07 22:16:45 +00:00
}
static void print_memory(const Config *config)
2017-06-08 23:47:46 +00:00
{
2019-11-29 06:12:36 +00:00
constexpr size_t oneGiB = 1024U * 1024U * 1024U;
2019-11-29 06:25:24 +00:00
const auto freeMem = static_cast<double>(uv_get_free_memory());
const auto totalMem = static_cast<double>(uv_get_total_memory());
const double percent = freeMem > 0 ? ((totalMem - freeMem) / totalMem * 100.0) : 100.0;
2019-11-29 06:12:36 +00:00
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%.1f/%.1f") CYAN(" GB") BLACK_BOLD(" (%.0f%%)"),
2019-11-29 04:06:28 +00:00
"MEMORY",
2019-11-29 06:25:24 +00:00
(totalMem - freeMem) / oneGiB,
totalMem / oneGiB,
percent
2019-11-29 04:06:28 +00:00
);
2021-01-18 04:23:29 +00:00
# ifdef XMRIG_FEATURE_DMI
if (!config->isDMI()) {
return;
}
2021-01-18 04:23:29 +00:00
DmiReader reader;
if (!reader.read()) {
return;
}
const bool printEmpty = reader.memory().size() <= 8;
2021-01-19 17:43:01 +00:00
2021-01-18 04:23:29 +00:00
for (const auto &memory : reader.memory()) {
if (!memory.isValid()) {
continue;
}
2021-01-19 07:16:03 +00:00
if (memory.size()) {
Log::print(WHITE_BOLD(" %-13s") "%s: " CYAN_BOLD("%" PRIu64) CYAN(" GB ") WHITE_BOLD("%s @ %" PRIu64 " MHz ") BLACK_BOLD("%s"),
2021-01-28 21:23:50 +00:00
"", memory.id().data(), memory.size() / oneGiB, memory.type(), memory.speed() / 1000000ULL, memory.product().data());
2021-01-19 07:16:03 +00:00
}
else if (printEmpty) {
Log::print(WHITE_BOLD(" %-13s") "%s: " BLACK_BOLD("<empty>"), "", memory.id().data());
2021-01-18 04:23:29 +00:00
}
}
const auto &board = Cpu::info()->isVM() ? reader.system() : reader.board();
2021-01-19 17:43:01 +00:00
if (board.isValid()) {
2021-01-19 17:45:36 +00:00
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") WHITE_BOLD("%s") " - " WHITE_BOLD("%s"), "MOTHERBOARD", board.vendor().data(), board.product().data());
2021-01-18 04:23:29 +00:00
}
# endif
2019-11-29 06:25:24 +00:00
}
2019-11-29 04:06:28 +00:00
2019-11-29 06:25:24 +00:00
static void print_threads(const Config *config)
2019-11-29 06:25:24 +00:00
{
2019-07-23 00:45:00 +00:00
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") WHITE_BOLD("%s%d%%"),
"DONATE",
config->pools().donateLevel() == 0 ? RED_BOLD_S : "",
config->pools().donateLevel()
);
2018-09-24 11:19:26 +00:00
# ifdef XMRIG_FEATURE_ASM
2019-07-23 00:45:00 +00:00
if (config->cpu().assembly() == Assembly::AUTO) {
const Assembly assembly = Cpu::info()->assembly();
2018-09-24 11:19:26 +00:00
2019-07-23 00:45:00 +00:00
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s"), "ASSEMBLY", asmName(assembly));
2018-09-24 11:19:26 +00:00
}
else {
2019-07-23 00:45:00 +00:00
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s"), "ASSEMBLY", asmName(config->cpu().assembly()));
2018-09-24 11:19:26 +00:00
}
# endif
2017-06-16 08:32:34 +00:00
}
2019-07-23 00:45:00 +00:00
static void print_commands(Config *)
2017-07-23 07:04:23 +00:00
{
2019-12-17 19:20:31 +00:00
if (Log::isColors()) {
2020-12-03 12:45:16 +00:00
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BG_BOLD("h") WHITE_BOLD("ashrate, ")
MAGENTA_BG_BOLD("p") WHITE_BOLD("ause, ")
MAGENTA_BG_BOLD("r") WHITE_BOLD("esume, ")
WHITE_BOLD("re") MAGENTA_BG(WHITE_BOLD_S "s") WHITE_BOLD("ults, ")
2020-12-03 12:45:16 +00:00
MAGENTA_BG_BOLD("c") WHITE_BOLD("onnection")
);
2017-07-23 07:04:23 +00:00
}
else {
Log::print(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume, 's' results, 'c' connection");
2017-07-23 07:04:23 +00:00
}
}
2019-07-23 00:45:00 +00:00
} // namespace xmrig
void xmrig::Summary::print(Controller *controller)
2017-06-07 22:16:45 +00:00
{
const auto config = controller->config();
config->printVersions();
print_pages(config);
print_cpu(config);
print_memory(config);
print_threads(config);
config->pools().print();
print_commands(config);
2017-06-07 22:16:45 +00:00
}