Added CMake option WITH_BENCHMARK.
This commit is contained in:
parent
ccebf6bb20
commit
a152d6be42
19 changed files with 245 additions and 121 deletions
|
@ -44,7 +44,6 @@ set(HEADERS_BASE
|
|||
src/base/net/http/HttpListener.h
|
||||
src/base/net/stratum/BaseClient.h
|
||||
src/base/net/stratum/Client.h
|
||||
src/base/net/stratum/NullClient.h
|
||||
src/base/net/stratum/Job.h
|
||||
src/base/net/stratum/NetworkState.h
|
||||
src/base/net/stratum/Pool.h
|
||||
|
@ -98,7 +97,6 @@ set(SOURCES_BASE
|
|||
src/base/net/http/Http.cpp
|
||||
src/base/net/stratum/BaseClient.cpp
|
||||
src/base/net/stratum/Client.cpp
|
||||
src/base/net/stratum/NullClient.cpp
|
||||
src/base/net/stratum/Job.cpp
|
||||
src/base/net/stratum/NetworkState.cpp
|
||||
src/base/net/stratum/Pool.cpp
|
||||
|
@ -229,11 +227,16 @@ endif()
|
|||
if (WITH_PROFILING)
|
||||
add_definitions(/DXMRIG_FEATURE_PROFILING)
|
||||
|
||||
list(APPEND HEADERS_BASE
|
||||
src/base/tools/Profiler.h
|
||||
)
|
||||
|
||||
list(APPEND SOURCES_BASE
|
||||
src/base/tools/Profiler.cpp
|
||||
)
|
||||
list(APPEND HEADERS_BASE src/base/tools/Profiler.h)
|
||||
list(APPEND SOURCES_BASE src/base/tools/Profiler.cpp)
|
||||
endif()
|
||||
|
||||
|
||||
if (WITH_RANDOMX AND WITH_BENCHMARK)
|
||||
add_definitions(/DXMRIG_FEATURE_BENCHMARK)
|
||||
|
||||
list(APPEND HEADERS_BASE src/base/net/stratum/NullClient.h)
|
||||
list(APPEND SOURCES_BASE src/base/net/stratum/NullClient.cpp)
|
||||
else()
|
||||
remove_definitions(/DXMRIG_FEATURE_BENCHMARK)
|
||||
endif()
|
||||
|
|
|
@ -151,9 +151,9 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
|
|||
}
|
||||
break;
|
||||
|
||||
case IConfig::UrlKey: /* --url */
|
||||
case IConfig::UrlKey: /* --url */
|
||||
case IConfig::StressKey: /* --stress */
|
||||
case IConfig::BenchKey: /* --bench */
|
||||
case IConfig::BenchKey: /* --bench */
|
||||
{
|
||||
if (!doc.HasMember(Pools::kPools)) {
|
||||
doc.AddMember(rapidjson::StringRef(Pools::kPools), rapidjson::kArrayType, doc.GetAllocator());
|
||||
|
@ -164,19 +164,20 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
|
|||
array.PushBack(rapidjson::kObjectType, doc.GetAllocator());
|
||||
}
|
||||
|
||||
if (key == IConfig::UrlKey) {
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
if (key != IConfig::UrlKey) {
|
||||
set(doc, array[array.Size() - 1], Pool::kUrl, (key == IConfig::BenchKey) ? "benchmark" :
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
"stratum+ssl://randomx.xmrig.com:443"
|
||||
# else
|
||||
"randomx.xmrig.com:3333"
|
||||
# endif
|
||||
);
|
||||
} else
|
||||
# endif
|
||||
{
|
||||
set(doc, array[array.Size() - 1], Pool::kUrl, arg);
|
||||
}
|
||||
else {
|
||||
set(doc, array[array.Size() - 1], Pool::kUrl, (key == IConfig::BenchKey) ? "offline" : "donate.v2.xmrig.com:3333");
|
||||
set(doc, "cpu", "huge-pages-jit", true);
|
||||
set(doc, "cpu", "priority", 2);
|
||||
set(doc, "cpu", "yield", false);
|
||||
if (key == IConfig::BenchKey) {
|
||||
set(doc, array[array.Size() - 1], Pool::kBenchmark, arg);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -154,7 +154,6 @@ void xmrig::Job::copy(const Job &other)
|
|||
{
|
||||
m_algorithm = other.m_algorithm;
|
||||
m_nicehash = other.m_nicehash;
|
||||
m_bench = other.m_bench;
|
||||
m_size = other.m_size;
|
||||
m_clientId = other.m_clientId;
|
||||
m_id = other.m_id;
|
||||
|
@ -175,6 +174,10 @@ void xmrig::Job::copy(const Job &other)
|
|||
memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob));
|
||||
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
m_bench = other.m_bench;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,7 +185,6 @@ void xmrig::Job::move(Job &&other)
|
|||
{
|
||||
m_algorithm = other.m_algorithm;
|
||||
m_nicehash = other.m_nicehash;
|
||||
m_bench = other.m_bench;
|
||||
m_size = other.m_size;
|
||||
m_clientId = std::move(other.m_clientId);
|
||||
m_id = std::move(other.m_id);
|
||||
|
@ -207,4 +209,8 @@ void xmrig::Job::move(Job &&other)
|
|||
memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob));
|
||||
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
m_bench = other.m_bench;
|
||||
# endif
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ public:
|
|||
inline uint8_t *blob() { return m_blob; }
|
||||
inline uint8_t fixedByte() const { return *(m_blob + 42); }
|
||||
inline uint8_t index() const { return m_index; }
|
||||
inline uint32_t bench() const { return m_bench; }
|
||||
inline void reset() { m_size = 0; m_diff = 0; }
|
||||
inline void setAlgorithm(const Algorithm::Id id) { m_algorithm = id; }
|
||||
inline void setAlgorithm(const char *algo) { m_algorithm = algo; }
|
||||
|
@ -97,7 +96,6 @@ public:
|
|||
inline void setHeight(uint64_t height) { m_height = height; }
|
||||
inline void setIndex(uint8_t index) { m_index = index; }
|
||||
inline void setPoolWallet(const String &poolWallet) { m_poolWallet = poolWallet; }
|
||||
inline void setBench(uint32_t bench) { m_bench = bench; }
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
inline char *rawBlob() { return m_rawBlob; }
|
||||
|
@ -113,13 +111,17 @@ public:
|
|||
inline Job &operator=(const Job &other) { copy(other); return *this; }
|
||||
inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; }
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
inline uint32_t bench() const { return m_bench; }
|
||||
inline void setBench(uint32_t bench) { m_bench = bench; }
|
||||
# endif
|
||||
|
||||
private:
|
||||
void copy(const Job &other);
|
||||
void move(Job &&other);
|
||||
|
||||
Algorithm m_algorithm;
|
||||
bool m_nicehash = false;
|
||||
uint32_t m_bench = 0;
|
||||
Buffer m_seed;
|
||||
size_t m_size = 0;
|
||||
String m_clientId;
|
||||
|
@ -138,6 +140,10 @@ private:
|
|||
char m_rawTarget[24]{};
|
||||
String m_rawSeedHash;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
uint32_t m_bench = 0;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/net/stratum/NullClient.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
|
||||
|
||||
|
|
|
@ -34,37 +34,37 @@ public:
|
|||
NullClient(IClientListener* listener);
|
||||
~NullClient() override = default;
|
||||
|
||||
virtual bool disconnect() override { return true; }
|
||||
virtual bool hasExtension(Extension extension) const noexcept override { return false; }
|
||||
virtual bool isEnabled() const override { return true; }
|
||||
virtual bool isTLS() const override { return false; }
|
||||
virtual const char* mode() const override { return "benchmark"; }
|
||||
virtual const char* tag() const override { return "null"; }
|
||||
virtual const char* tlsFingerprint() const override { return nullptr; }
|
||||
virtual const char* tlsVersion() const override { return nullptr; }
|
||||
virtual const Job& job() const override { return m_job; }
|
||||
virtual const Pool& pool() const override { return m_pool; }
|
||||
virtual const String& ip() const override { return m_ip; }
|
||||
virtual int id() const override { return 0; }
|
||||
virtual int64_t send(const rapidjson::Value& obj, Callback callback) override { return 0; }
|
||||
virtual int64_t send(const rapidjson::Value& obj) override { return 0; }
|
||||
virtual int64_t sequence() const override { return 0; }
|
||||
virtual int64_t submit(const JobResult& result) override { return 0; }
|
||||
virtual void connect() override;
|
||||
virtual void connect(const Pool& pool) override { setPool(pool); }
|
||||
virtual void deleteLater() override {}
|
||||
virtual void setAlgo(const Algorithm& algo) override {}
|
||||
virtual void setEnabled(bool enabled) override {}
|
||||
virtual void setPool(const Pool& pool) override;
|
||||
virtual void setProxy(const ProxyUrl& proxy) override {}
|
||||
virtual void setQuiet(bool quiet) override {}
|
||||
virtual void setRetries(int retries) override {}
|
||||
virtual void setRetryPause(uint64_t ms) override {}
|
||||
virtual void tick(uint64_t now) override {}
|
||||
inline bool disconnect() override { return true; }
|
||||
inline bool hasExtension(Extension extension) const noexcept override { return false; }
|
||||
inline bool isEnabled() const override { return true; }
|
||||
inline bool isTLS() const override { return false; }
|
||||
inline const char *mode() const override { return "benchmark"; }
|
||||
inline const char *tag() const override { return "null"; }
|
||||
inline const char *tlsFingerprint() const override { return nullptr; }
|
||||
inline const char *tlsVersion() const override { return nullptr; }
|
||||
inline const Job &job() const override { return m_job; }
|
||||
inline const Pool &pool() const override { return m_pool; }
|
||||
inline const String &ip() const override { return m_ip; }
|
||||
inline int id() const override { return 0; }
|
||||
inline int64_t send(const rapidjson::Value& obj, Callback callback) override { return 0; }
|
||||
inline int64_t send(const rapidjson::Value& obj) override { return 0; }
|
||||
inline int64_t sequence() const override { return 0; }
|
||||
inline int64_t submit(const JobResult& result) override { return 0; }
|
||||
inline void connect(const Pool& pool) override { setPool(pool); }
|
||||
inline void deleteLater() override {}
|
||||
inline void setAlgo(const Algorithm& algo) override {}
|
||||
inline void setEnabled(bool enabled) override {}
|
||||
inline void setProxy(const ProxyUrl& proxy) override {}
|
||||
inline void setQuiet(bool quiet) override {}
|
||||
inline void setRetries(int retries) override {}
|
||||
inline void setRetryPause(uint64_t ms) override {}
|
||||
inline void tick(uint64_t now) override {}
|
||||
|
||||
void connect() override;
|
||||
void setPool(const Pool& pool) override;
|
||||
|
||||
private:
|
||||
IClientListener* m_listener;
|
||||
|
||||
Job m_job;
|
||||
Pool m_pool;
|
||||
String m_ip;
|
||||
|
|
|
@ -50,7 +50,9 @@
|
|||
#endif
|
||||
|
||||
|
||||
#include "base/net/stratum/NullClient.h"
|
||||
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||
# include "base/net/stratum/NullClient.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -80,10 +82,11 @@ const char *Pool::kSOCKS5 = "socks5";
|
|||
const char *Pool::kTls = "tls";
|
||||
const char *Pool::kUrl = "url";
|
||||
const char *Pool::kUser = "user";
|
||||
const char *Pool::kNicehashHost = "nicehash.com";
|
||||
|
||||
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||
const char *Pool::kBenchmark = "benchmark";
|
||||
|
||||
|
||||
const char *Pool::kNicehashHost = "nicehash.com";
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t Pool::benchProgress = 0;
|
||||
|
@ -137,35 +140,22 @@ xmrig::Pool::Pool(const rapidjson::Value &object) :
|
|||
m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash) || m_url.host().contains(kNicehashHost));
|
||||
m_flags.set(FLAG_TLS, Json::getBool(object, kTls) || m_url.isTLS());
|
||||
|
||||
const char* benchSize = Json::getString(object, kBenchmark, nullptr);
|
||||
if (benchSize) {
|
||||
std::string s;
|
||||
for (int i = 1; i <= 10; ++i) {
|
||||
s = std::to_string(i) + "M";
|
||||
if (strcasecmp(benchSize, s.c_str()) == 0) {
|
||||
m_benchSize = i * 1000000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
setKeepAlive(Json::getValue(object, kKeepalive));
|
||||
|
||||
if (m_benchSize) {
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
if (setBenchSize(Json::getString(object, kBenchmark, nullptr))) {
|
||||
m_mode = MODE_BENCHMARK;
|
||||
|
||||
return;
|
||||
}
|
||||
else if (m_daemon.isValid()) {
|
||||
# endif
|
||||
|
||||
if (m_daemon.isValid()) {
|
||||
m_mode = MODE_SELF_SELECT;
|
||||
}
|
||||
else if (Json::getBool(object, kDaemon)) {
|
||||
m_mode = MODE_DAEMON;
|
||||
}
|
||||
|
||||
const rapidjson::Value &keepalive = Json::getValue(object, kKeepalive);
|
||||
if (keepalive.IsInt()) {
|
||||
setKeepAlive(keepalive.GetInt());
|
||||
}
|
||||
else if (keepalive.IsBool()) {
|
||||
setKeepAlive(keepalive.GetBool());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -244,9 +234,11 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
|
|||
client = new AutoClient(id, Platform::userAgent(), listener);
|
||||
}
|
||||
# endif
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
else if (m_mode == MODE_BENCHMARK) {
|
||||
client = new NullClient(listener);
|
||||
}
|
||||
# endif
|
||||
|
||||
assert(client != nullptr);
|
||||
|
||||
|
@ -337,3 +329,34 @@ void xmrig::Pool::print() const
|
|||
LOG_DEBUG ("keepAlive: %d", m_keepAlive);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void xmrig::Pool::setKeepAlive(const rapidjson::Value &value)
|
||||
{
|
||||
if (value.IsInt()) {
|
||||
setKeepAlive(value.GetInt());
|
||||
}
|
||||
else if (value.IsBool()) {
|
||||
setKeepAlive(value.GetBool());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||
bool xmrig::Pool::setBenchSize(const char *benchmark)
|
||||
{
|
||||
if (!benchmark) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto size = strtoul(benchmark, nullptr, 10);
|
||||
if (size < 1 || size > 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string s = std::to_string(size) + "M";
|
||||
m_benchSize = strcasecmp(benchmark, s.c_str()) == 0 ? size * 1000000 : 0;
|
||||
|
||||
return m_benchSize > 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -51,7 +51,9 @@ public:
|
|||
MODE_DAEMON,
|
||||
MODE_SELF_SELECT,
|
||||
MODE_AUTO_ETH,
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
MODE_BENCHMARK,
|
||||
# endif
|
||||
};
|
||||
|
||||
static const String kDefaultPassword;
|
||||
|
@ -72,9 +74,12 @@ public:
|
|||
static const char *kTls;
|
||||
static const char *kUrl;
|
||||
static const char *kUser;
|
||||
static const char* kBenchmark;
|
||||
static const char *kNicehashHost;
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
static const char *kBenchmark;
|
||||
# endif
|
||||
|
||||
constexpr static int kKeepAliveTimeout = 60;
|
||||
constexpr static uint16_t kDefaultPort = 3333;
|
||||
constexpr static uint64_t kDefaultPollInterval = 1000;
|
||||
|
@ -99,7 +104,6 @@ public:
|
|||
inline const Url &daemon() const { return m_daemon; }
|
||||
inline int keepAlive() const { return m_keepAlive; }
|
||||
inline Mode mode() const { return m_mode; }
|
||||
inline uint64_t benchSize() const { return m_benchSize; }
|
||||
inline uint16_t port() const { return m_url.port(); }
|
||||
inline uint64_t pollInterval() const { return m_pollInterval; }
|
||||
inline void setAlgo(const Algorithm &algorithm) { m_algorithm = algorithm; }
|
||||
|
@ -108,6 +112,10 @@ public:
|
|||
inline void setRigId(const String &rigId) { m_rigId = rigId; }
|
||||
inline void setUser(const String &user) { m_user = user; }
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
inline uint64_t benchSize() const { return m_benchSize; }
|
||||
# endif
|
||||
|
||||
inline bool operator!=(const Pool &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Pool &other) const { return isEqual(other); }
|
||||
|
||||
|
@ -134,11 +142,12 @@ private:
|
|||
inline void setKeepAlive(bool enable) { setKeepAlive(enable ? kKeepAliveTimeout : 0); }
|
||||
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
|
||||
|
||||
void setKeepAlive(const rapidjson::Value &value);
|
||||
|
||||
Algorithm m_algorithm;
|
||||
Coin m_coin;
|
||||
int m_keepAlive = 0;
|
||||
Mode m_mode = MODE_POOL;
|
||||
uint32_t m_benchSize = 0;
|
||||
ProxyUrl m_proxy;
|
||||
std::bitset<FLAG_MAX> m_flags = 0;
|
||||
String m_fingerprint;
|
||||
|
@ -148,6 +157,12 @@ private:
|
|||
uint64_t m_pollInterval = kDefaultPollInterval;
|
||||
Url m_daemon;
|
||||
Url m_url;
|
||||
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
bool setBenchSize(const char *benchmark);
|
||||
|
||||
uint32_t m_benchSize = 0;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -65,6 +65,18 @@ bool xmrig::Pools::isEqual(const Pools &other) const
|
|||
}
|
||||
|
||||
|
||||
int xmrig::Pools::donateLevel() const
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
if (m_data.size() == 1 && m_data.front().mode() == Pool::MODE_BENCHMARK) {
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
return m_donateLevel;
|
||||
}
|
||||
|
||||
|
||||
xmrig::IStrategy *xmrig::Pools::createStrategy(IStrategyListener *listener) const
|
||||
{
|
||||
if (active() == 1) {
|
||||
|
|
|
@ -58,7 +58,6 @@ public:
|
|||
Pools();
|
||||
|
||||
inline const std::vector<Pool> &data() const { return m_data; }
|
||||
inline int donateLevel() const { return m_donateLevel; }
|
||||
inline int retries() const { return m_retries; }
|
||||
inline int retryPause() const { return m_retryPause; }
|
||||
inline ProxyDonate proxyDonate() const { return m_proxyDonate; }
|
||||
|
@ -67,6 +66,7 @@ public:
|
|||
inline bool operator==(const Pools &other) const { return isEqual(other); }
|
||||
|
||||
bool isEqual(const Pools &other) const;
|
||||
int donateLevel() const;
|
||||
IStrategy *createStrategy(IStrategyListener *listener) const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
size_t active() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue