Improved/restructured --help output.

This commit is contained in:
XMRig 2019-09-23 03:47:40 +07:00
parent c7e4815d79
commit 637301d340
11 changed files with 119 additions and 133 deletions

View file

@ -23,7 +23,7 @@
*/ */
#include <assert.h> #include <cassert>
#include "backend/cpu/Cpu.h" #include "backend/cpu/Cpu.h"
@ -44,7 +44,15 @@ static xmrig::ICpuInfo *cpuInfo = nullptr;
xmrig::ICpuInfo *xmrig::Cpu::info() xmrig::ICpuInfo *xmrig::Cpu::info()
{ {
assert(cpuInfo != nullptr); if (cpuInfo == nullptr) {
# if defined(XMRIG_FEATURE_HWLOC)
cpuInfo = new HwlocCpuInfo();
# elif defined(XMRIG_FEATURE_LIBCPUID)
cpuInfo = new AdvancedCpuInfo();
# else
cpuInfo = new BasicCpuInfo();
# endif
}
return cpuInfo; return cpuInfo;
} }
@ -62,7 +70,7 @@ rapidjson::Value xmrig::Cpu::toJSON(rapidjson::Document &doc)
cpu.AddMember("brand", StringRef(i->brand()), allocator); cpu.AddMember("brand", StringRef(i->brand()), allocator);
cpu.AddMember("aes", i->hasAES(), allocator); cpu.AddMember("aes", i->hasAES(), allocator);
cpu.AddMember("avx2", i->hasAVX2(), allocator); cpu.AddMember("avx2", i->hasAVX2(), allocator);
cpu.AddMember("x64", i->isX64(), allocator); cpu.AddMember("x64", ICpuInfo::isX64(), allocator);
cpu.AddMember("l2", static_cast<uint64_t>(i->L2()), allocator); cpu.AddMember("l2", static_cast<uint64_t>(i->L2()), allocator);
cpu.AddMember("l3", static_cast<uint64_t>(i->L3()), allocator); cpu.AddMember("l3", static_cast<uint64_t>(i->L3()), allocator);
cpu.AddMember("cores", static_cast<uint64_t>(i->cores()), allocator); cpu.AddMember("cores", static_cast<uint64_t>(i->cores()), allocator);
@ -81,20 +89,6 @@ rapidjson::Value xmrig::Cpu::toJSON(rapidjson::Document &doc)
} }
void xmrig::Cpu::init()
{
assert(cpuInfo == nullptr);
# if defined(XMRIG_FEATURE_HWLOC)
cpuInfo = new HwlocCpuInfo();
# elif defined(XMRIG_FEATURE_LIBCPUID)
cpuInfo = new AdvancedCpuInfo();
# else
cpuInfo = new BasicCpuInfo();
# endif
}
void xmrig::Cpu::release() void xmrig::Cpu::release()
{ {
assert(cpuInfo != nullptr); assert(cpuInfo != nullptr);

View file

@ -37,7 +37,6 @@ class Cpu
public: public:
static ICpuInfo *info(); static ICpuInfo *info();
static rapidjson::Value toJSON(rapidjson::Document &doc); static rapidjson::Value toJSON(rapidjson::Document &doc);
static void init();
static void release(); static void release();
inline static Assembly::Id assembly(Assembly::Id hint) { return hint == Assembly::AUTO ? Cpu::info()->assembly() : hint; } inline static Assembly::Id assembly(Assembly::Id hint) { return hint == Assembly::AUTO ? Cpu::info()->assembly() : hint; }

View file

@ -23,7 +23,7 @@
*/ */
#include <stdio.h> #include <cstdio>
#include <uv.h> #include <uv.h>
@ -161,7 +161,7 @@ int xmrig::Entry::exec(const Process &process, Id id)
{ {
switch (id) { switch (id) {
case Usage: case Usage:
printf(usage); printf("%s\n", usage().c_str());
return 0; return 0;
case Version: case Version:

View file

@ -23,7 +23,7 @@
*/ */
#include <stdio.h> #include <cstdio>
#ifdef _MSC_VER #ifdef _MSC_VER
@ -50,12 +50,7 @@ static const char *kApi = "api";
static const char *kHttp = "http"; static const char *kHttp = "http";
static const char *kPools = "pools"; static const char *kPools = "pools";
} } // namespace xmrig
xmrig::BaseTransform::BaseTransform()
{
}
void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform) void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform)
@ -68,7 +63,7 @@ void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTrans
Document doc(kObjectType); Document doc(kObjectType);
while (1) { while (true) {
key = getopt_long(argc, argv, short_options, options, nullptr); key = getopt_long(argc, argv, short_options, options, nullptr);
if (key < 0) { if (key < 0) {
break; break;
@ -226,8 +221,10 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
case IConfig::TlsKey: /* --tls */ case IConfig::TlsKey: /* --tls */
return add(doc, kPools, "tls", enable); return add(doc, kPools, "tls", enable);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonKey: /* --daemon */ case IConfig::DaemonKey: /* --daemon */
return add(doc, kPools, "daemon", enable); return add(doc, kPools, "daemon", enable);
# endif
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
case IConfig::NicehashKey: /* --nicehash */ case IConfig::NicehashKey: /* --nicehash */
@ -273,8 +270,10 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui
case IConfig::PrintTimeKey: /* --print-time */ case IConfig::PrintTimeKey: /* --print-time */
return set(doc, "print-time", arg); return set(doc, "print-time", arg);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonPollKey: /* --daemon-poll-interval */ case IConfig::DaemonPollKey: /* --daemon-poll-interval */
return add(doc, kPools, "daemon-poll-interval", arg); return add(doc, kPools, "daemon-poll-interval", arg);
# endif
default: default:
break; break;

View file

@ -44,8 +44,6 @@ class Process;
class BaseTransform : public IConfigTransform class BaseTransform : public IConfigTransform
{ {
public: public:
BaseTransform();
static void load(JsonChain &chain, Process *process, IConfigTransform &transform); static void load(JsonChain &chain, Process *process, IConfigTransform &transform);
protected: protected:

View file

@ -78,6 +78,7 @@ public:
PrintTimeKey = 1007, PrintTimeKey = 1007,
// xmrig cpu // xmrig cpu
CPUKey = 1024,
AVKey = 'v', AVKey = 'v',
CPUAffinityKey = 1020, CPUAffinityKey = 1020,
DryRunKey = 5000, DryRunKey = 5000,

View file

@ -46,7 +46,6 @@ xmrig::Controller::~Controller()
int xmrig::Controller::init() int xmrig::Controller::init()
{ {
Cpu::init();
Base::init(); Base::init();
m_network = new Network(this); m_network = new Network(this);

View file

@ -80,12 +80,7 @@ static inline bool isHwAes(uint64_t av)
} }
} } // namespace xmrig
xmrig::ConfigTransform::ConfigTransform() : BaseTransform()
{
}
void xmrig::ConfigTransform::finalize(rapidjson::Document &doc) void xmrig::ConfigTransform::finalize(rapidjson::Document &doc)
@ -131,7 +126,7 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
return transformUint64(doc, key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); return transformUint64(doc, key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10));
} }
# ifndef XMRIG_NO_ASM # ifdef XMRIG_FEATURE_ASM
case IConfig::AssemblyKey: /* --asm */ case IConfig::AssemblyKey: /* --asm */
return set(doc, kCpu, "asm", arg); return set(doc, kCpu, "asm", arg);
# endif # endif

View file

@ -34,9 +34,6 @@ namespace xmrig {
class ConfigTransform : public BaseTransform class ConfigTransform : public BaseTransform
{ {
public:
ConfigTransform();
protected: protected:
void finalize(rapidjson::Document &doc) override; void finalize(rapidjson::Document &doc) override;
void transform(rapidjson::Document &doc, int key, const char *arg) override; void transform(rapidjson::Document &doc, int key, const char *arg) override;

View file

@ -45,6 +45,7 @@ static const char short_options[] = "a:c:kBp:Px:r:R:s:t:T:o:u:O:v:l:S";
static const option options[] = { static const option options[] = {
{ "algo", 1, nullptr, IConfig::AlgorithmKey }, { "algo", 1, nullptr, IConfig::AlgorithmKey },
# ifdef XMRIG_FEATURE_HTTP
{ "api-worker-id", 1, nullptr, IConfig::ApiWorkerIdKey }, { "api-worker-id", 1, nullptr, IConfig::ApiWorkerIdKey },
{ "api-id", 1, nullptr, IConfig::ApiIdKey }, { "api-id", 1, nullptr, IConfig::ApiIdKey },
{ "http-enabled", 0, nullptr, IConfig::HttpEnabledKey }, { "http-enabled", 0, nullptr, IConfig::HttpEnabledKey },
@ -52,6 +53,9 @@ static const option options[] = {
{ "http-access-token", 1, nullptr, IConfig::HttpAccessTokenKey }, { "http-access-token", 1, nullptr, IConfig::HttpAccessTokenKey },
{ "http-port", 1, nullptr, IConfig::HttpPort }, { "http-port", 1, nullptr, IConfig::HttpPort },
{ "http-no-restricted", 0, nullptr, IConfig::HttpRestrictedKey }, { "http-no-restricted", 0, nullptr, IConfig::HttpRestrictedKey },
{ "daemon", 0, nullptr, IConfig::DaemonKey },
{ "daemon-poll-interval", 1, nullptr, IConfig::DaemonPollKey },
# endif
{ "av", 1, nullptr, IConfig::AVKey }, { "av", 1, nullptr, IConfig::AVKey },
{ "background", 0, nullptr, IConfig::BackgroundKey }, { "background", 0, nullptr, IConfig::BackgroundKey },
{ "config", 1, nullptr, IConfig::ConfigKey }, { "config", 1, nullptr, IConfig::ConfigKey },
@ -76,13 +80,17 @@ static const option options[] = {
{ "user-agent", 1, nullptr, IConfig::UserAgentKey }, { "user-agent", 1, nullptr, IConfig::UserAgentKey },
{ "userpass", 1, nullptr, IConfig::UserpassKey }, { "userpass", 1, nullptr, IConfig::UserpassKey },
{ "rig-id", 1, nullptr, IConfig::RigIdKey }, { "rig-id", 1, nullptr, IConfig::RigIdKey },
# ifdef XMRIG_FEATURE_TLS
{ "tls", 0, nullptr, IConfig::TlsKey }, { "tls", 0, nullptr, IConfig::TlsKey },
{ "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey }, { "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey },
# endif
# ifdef XMRIG_FEATURE_ASM
{ "asm", 1, nullptr, IConfig::AssemblyKey }, { "asm", 1, nullptr, IConfig::AssemblyKey },
{ "daemon", 0, nullptr, IConfig::DaemonKey }, # endif
{ "daemon-poll-interval", 1, nullptr, IConfig::DaemonPollKey }, # ifdef XMRIG_ALGO_RANDOMX
{ "randomx-init", 1, nullptr, IConfig::RandomXInitKey }, { "randomx-init", 1, nullptr, IConfig::RandomXInitKey },
{ "randomx-no-numa", 0, nullptr, IConfig::RandomXNumaKey }, { "randomx-no-numa", 0, nullptr, IConfig::RandomXNumaKey },
# endif
{ nullptr, 0, nullptr, 0 } { nullptr, 0, nullptr, 0 }
}; };

View file

@ -29,99 +29,95 @@
#include "version.h" #include "version.h"
#include <string>
namespace xmrig { namespace xmrig {
static char const usage[] = "\ static inline const std::string &usage()
Usage: " APP_ID " [OPTIONS]\n\ {
Options:\n\ static std::string u;
-a, --algo=ALGO specify the algorithm to use\n\
cn/r, cn/2, cn/1, cn/0, cn/double, cn/half, cn/fast,\n\ if (!u.empty()) {
cn/rwz, cn/zls, cn/xao, cn/rto" return u;
#ifdef XMRIG_ALGO_CN_GPU }
", cn/gpu,\n"
#else u += "Usage: " APP_ID " [OPTIONS]\n\nNetwork:\n";
",\n" u += " -o, --url=URL URL of mining server\n";
#endif u += " -a, --algo=ALGO mining algorithm https://xmrig.com/docs/algorithms\n";
#ifdef XMRIG_ALGO_CN_LITE u += " -u, --user=USERNAME username for mining server\n";
"\ u += " -p, --pass=PASSWORD password for mining server\n";
cn-lite/1,\n" u += " -O, --userpass=U:P username:password pair for mining server\n";
#endif u += " -k, --keepalive send keepalived packet for prevent timeout (needs pool support)\n";
#ifdef XMRIG_ALGO_CN_HEAVY u += " --nicehash enable nicehash.com support\n";
"\ u += " --rig-id=ID rig identifier for pool-side statistics (needs pool support)\n";
cn-heavy/xhv, cn-heavy/tube, cn-heavy/0,\n"
#endif
#ifdef XMRIG_ALGO_CN_PICO
"\
cn-pico,\n"
#endif
#ifdef XMRIG_ALGO_RANDOMX
"\
rx/wow, rx/loki\n"
#endif
"\
-o, --url=URL URL of mining server\n\
-O, --userpass=U:P username:password pair for mining server\n\
-u, --user=USERNAME username for mining server\n\
-p, --pass=PASSWORD password for mining server\n\
--rig-id=ID rig identifier for pool-side statistics (needs pool support)\n\
-t, --threads=N number of miner threads\n\
-v, --av=N algorithm variation, 0 auto select\n\
-k, --keepalive send keepalived packet for prevent timeout (needs pool support)\n\
--nicehash enable nicehash.com support\n"
# ifdef XMRIG_FEATURE_TLS # ifdef XMRIG_FEATURE_TLS
"\ u += " --tls enable SSL/TLS support (needs pool support)\n";
--tls enable SSL/TLS support (needs pool support)\n\ u += " --tls-fingerprint=HEX pool TLS certificate fingerprint for strict certificate pinning\n";
--tls-fingerprint=F pool TLS certificate fingerprint, if set enable strict certificate pinning\n"
# endif # endif
# ifdef XMRIG_FEATURE_HTTP # ifdef XMRIG_FEATURE_HTTP
"\ u += " --daemon use daemon RPC instead of pool for solo mining\n";
--daemon use daemon RPC instead of pool for solo mining\n\ u += " --daemon-poll-interval=N daemon poll interval in milliseconds (default: 1000)\n";
--daemon-poll-interval=N daemon poll interval in milliseconds (default: 1000)\n"
#endif
"\
-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\
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\
--no-huge-pages disable huge pages support\n\
--no-color disable colored output\n\
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
--user-agent set custom user-agent string for pool\n\
-B, --background run the miner in the background\n\
-c, --config=FILE load a JSON-format configuration file\n\
-l, --log-file=FILE log all output to a file\n"
# ifdef HAVE_SYSLOG_H
"\
-S, --syslog use system log for output messages\n"
# endif
"\
--asm=ASM ASM optimizations, possible values: auto, none, intel, ryzen, bulldozer.\n\
--print-time=N print hashrate report every N seconds\n"
#ifdef XMRIG_FEATURE_HTTP
"\
--api-worker-id=ID custom worker-id for API\n\
--api-id=ID custom instance ID for API\n\
--http-enabled enable HTTP API\n\
--http-host=HOST bind host for HTTP API (default: 127.0.0.1)\n\
--http-port=N bind port for HTTP API\n\
--http-access-token=T access token for HTTP API\n\
--http-no-restricted enable full remote access to HTTP API (only if access token set)\n"
# endif # endif
u += " -r, --retries=N number of times to retry before switch to backup server (default: 5)\n";
u += " -R, --retry-pause=N time to pause between retries (default: 5)\n";
u += " --user-agent set custom user-agent string for pool\n";
u += " --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n";
u += " --donate-over-proxy=N control donate over xmrig-proxy feature\n";
u += "\nCPU backend:\n";
u += " -t, --threads=N number of CPU threads\n";
u += " -v, --av=N algorithm variation, 0 auto select\n";
u += " --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n";
u += " --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n";
u += " --no-huge-pages disable huge pages support\n";
u += " --asm=ASM ASM optimizations, possible values: auto, none, intel, ryzen, bulldozer\n";
# ifdef XMRIG_ALGO_RANDOMX # ifdef XMRIG_ALGO_RANDOMX
"\ u += " --randomx-init=N threads count to initialize RandomX dataset\n";
--randomx-init=N threads count to initialize RandomX dataset\n\ u += " --randomx-no-numa disable NUMA support for RandomX\n";
--randomx-no-numa disable NUMA support for RandomX\n"
# endif # endif
# ifdef XMRIG_FEATURE_HTTP
u += "\nAPI:\n";
u += " --api-worker-id=ID custom worker-id for API\n";
u += " --api-id=ID custom instance ID for API\n";
u += " --http-enabled enable HTTP API\n";
u += " --http-host=HOST bind host for HTTP API (default: 127.0.0.1)\n";
u += " --http-port=N bind port for HTTP API\n";
u += " --http-access-token=T access token for HTTP API\n";
u += " --http-no-restricted enable full remote access to HTTP API (only if access token set)\n";
# endif
u += "\nLogging:\n";
# ifdef HAVE_SYSLOG_H
u += " -S, --syslog use system log for output messages\n";
# endif
u += " -l, --log-file=FILE log all output to a file\n";
u += " --print-time=N print hashrate report every N seconds\n";
u += " --no-color disable colored output\n";
u += "\nMisc:\n";
u += " -c, --config=FILE load a JSON-format configuration file\n";
u += " -B, --background run the miner in the background\n";
u += " -V, --version output version information and exit\n";
u += " -h, --help display this help and exit\n";
u += " --dry-run test configuration and exit\n";
# ifdef XMRIG_FEATURE_HWLOC # ifdef XMRIG_FEATURE_HWLOC
"\ u += " --export-topology export hwloc topology to a XML file and exit\n";
--export-topology export hwloc topology to a XML file and exit\n"
# endif # endif
"\
--dry-run test configuration and exit\n\ return u;
-h, --help display this help and exit\n\ }
-V, --version output version information and exit\n\
";
} /* namespace xmrig */ } /* namespace xmrig */