Merge pull request #2104 from SChernykh/dev

Added `pause-on-active` option
This commit is contained in:
xmrig 2021-02-15 11:04:14 +07:00 committed by GitHub
commit d2f01cfa86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 57 additions and 6 deletions

View file

@ -49,6 +49,7 @@ public:
static inline const String &userAgent() { return m_userAgent; } static inline const String &userAgent() { return m_userAgent; }
static bool isOnBatteryPower(); static bool isOnBatteryPower();
static bool isUserActive();
private: private:
static char *createUserAgent(); static char *createUserAgent();

View file

@ -158,3 +158,10 @@ bool xmrig::Platform::isOnBatteryPower()
} }
return false; return false;
} }
bool xmrig::Platform::isUserActive()
{
// TODO
return false;
}

View file

@ -161,3 +161,16 @@ bool xmrig::Platform::isOnBatteryPower()
} }
return false; return false;
} }
bool xmrig::Platform::isUserActive()
{
LASTINPUTINFO info;
info.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&info)) {
return false;
}
return static_cast<int>(GetTickCount() - info.dwTime) < 60 * 1000;
}

View file

@ -62,6 +62,7 @@ const char *BaseConfig::kDryRun = "dry-run";
const char *BaseConfig::kHttp = "http"; const char *BaseConfig::kHttp = "http";
const char *BaseConfig::kLogFile = "log-file"; const char *BaseConfig::kLogFile = "log-file";
const char *BaseConfig::kPauseOnBattery = "pause-on-battery"; const char *BaseConfig::kPauseOnBattery = "pause-on-battery";
const char *BaseConfig::kPauseOnActive = "pause-on-active";
const char *BaseConfig::kPrintTime = "print-time"; const char *BaseConfig::kPrintTime = "print-time";
const char *BaseConfig::kSyslog = "syslog"; const char *BaseConfig::kSyslog = "syslog";
const char *BaseConfig::kTitle = "title"; const char *BaseConfig::kTitle = "title";
@ -92,6 +93,7 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
m_syslog = reader.getBool(kSyslog, m_syslog); m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool(kWatch, m_watch); m_watch = reader.getBool(kWatch, m_watch);
m_pauseOnBattery = reader.getBool(kPauseOnBattery, m_pauseOnBattery); m_pauseOnBattery = reader.getBool(kPauseOnBattery, m_pauseOnBattery);
m_pauseOnActive = reader.getBool(kPauseOnActive, m_pauseOnActive);
m_logFile = reader.getString(kLogFile); m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent); m_userAgent = reader.getString(kUserAgent);
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U); m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);

View file

@ -56,6 +56,7 @@ public:
static const char *kHttp; static const char *kHttp;
static const char *kLogFile; static const char *kLogFile;
static const char *kPauseOnBattery; static const char *kPauseOnBattery;
static const char *kPauseOnActive;
static const char *kPrintTime; static const char *kPrintTime;
static const char *kSyslog; static const char *kSyslog;
static const char *kTitle; static const char *kTitle;
@ -73,6 +74,7 @@ public:
inline bool isBackground() const { return m_background; } inline bool isBackground() const { return m_background; }
inline bool isDryRun() const { return m_dryRun; } inline bool isDryRun() const { return m_dryRun; }
inline bool isPauseOnBattery() const { return m_pauseOnBattery; } inline bool isPauseOnBattery() const { return m_pauseOnBattery; }
inline bool isPauseOnActive() const { return m_pauseOnActive; }
inline bool isSyslog() const { return m_syslog; } inline bool isSyslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile.data(); } inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); } inline const char *userAgent() const { return m_userAgent.data(); }
@ -101,6 +103,7 @@ protected:
bool m_background = false; bool m_background = false;
bool m_dryRun = false; bool m_dryRun = false;
bool m_pauseOnBattery = false; bool m_pauseOnBattery = false;
bool m_pauseOnActive = false;
bool m_syslog = false; bool m_syslog = false;
bool m_upgrade = false; bool m_upgrade = false;
bool m_watch = true; bool m_watch = true;

View file

@ -262,6 +262,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::DaemonKey: /* --daemon */ case IConfig::DaemonKey: /* --daemon */
case IConfig::VerboseKey: /* --verbose */ case IConfig::VerboseKey: /* --verbose */
case IConfig::PauseOnBatteryKey: /* --pause-on-battery */ case IConfig::PauseOnBatteryKey: /* --pause-on-battery */
case IConfig::PauseOnActiveKey: /* --pause-on-active */
return transformBoolean(doc, key, true); return transformBoolean(doc, key, true);
case IConfig::ColorKey: /* --no-color */ case IConfig::ColorKey: /* --no-color */
@ -323,6 +324,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
case IConfig::PauseOnBatteryKey: /* --pause-on-battery */ case IConfig::PauseOnBatteryKey: /* --pause-on-battery */
return set(doc, BaseConfig::kPauseOnBattery, enable); return set(doc, BaseConfig::kPauseOnBattery, enable);
case IConfig::PauseOnActiveKey: /* --pause-on-active */
return set(doc, BaseConfig::kPauseOnActive, enable);
default: default:
break; break;
} }

View file

@ -86,6 +86,7 @@ public:
BenchTokenKey = 1048, BenchTokenKey = 1048,
DmiKey = 1049, DmiKey = 1049,
HugePageSizeKey = 1050, HugePageSizeKey = 1050,
PauseOnActiveKey = 1051,
// xmrig common // xmrig common
CPUPriorityKey = 1021, CPUPriorityKey = 1021,

View file

@ -96,5 +96,6 @@
"user-agent": null, "user-agent": null,
"verbose": 0, "verbose": 0,
"watch": true, "watch": true,
"pause-on-battery": false "pause-on-battery": false,
"pause-on-active": false
} }

View file

@ -352,6 +352,7 @@ public:
Algorithms algorithms; Algorithms algorithms;
bool active = false; bool active = false;
bool battery_power = false; bool battery_power = false;
bool user_active = false;
bool enabled = true; bool enabled = true;
bool reset = true; bool reset = true;
Controller *controller; Controller *controller;
@ -629,18 +630,32 @@ void xmrig::Miner::onTimer(const Timer *)
if (d_ptr->controller->config()->isPauseOnBattery()) { if (d_ptr->controller->config()->isPauseOnBattery()) {
const bool battery_power = Platform::isOnBatteryPower(); const bool battery_power = Platform::isOnBatteryPower();
if (battery_power && d_ptr->enabled) { if (battery_power && !d_ptr->battery_power) {
LOG_INFO("%s " YELLOW_BOLD("on battery power"), Tags::miner()); LOG_INFO("%s " YELLOW_BOLD("on battery power"), Tags::miner());
d_ptr->battery_power = true; d_ptr->battery_power = true;
setEnabled(false);
} }
else if (!battery_power && !d_ptr->enabled && d_ptr->battery_power) { else if (!battery_power && d_ptr->battery_power) {
LOG_INFO("%s " GREEN_BOLD("on AC power"), Tags::miner()); LOG_INFO("%s " GREEN_BOLD("on AC power"), Tags::miner());
d_ptr->battery_power = false; d_ptr->battery_power = false;
setEnabled(true);
} }
} }
if (d_ptr->controller->config()->isPauseOnActive()) {
const bool user_active = Platform::isUserActive();
if (user_active && !d_ptr->user_active) {
LOG_INFO("%s " YELLOW_BOLD("user active"), Tags::miner());
d_ptr->user_active = true;
}
else if (!user_active && d_ptr->user_active) {
LOG_INFO("%s " GREEN_BOLD("user inactive"), Tags::miner());
d_ptr->user_active = false;
}
}
const bool batteryEnabled = !(d_ptr->controller->config()->isPauseOnBattery() && d_ptr->battery_power);
const bool userActiveEnabled = !(d_ptr->controller->config()->isPauseOnActive() && d_ptr->user_active);
setEnabled(batteryEnabled && userActiveEnabled);
if (stopMiner) { if (stopMiner) {
stop(); stop();
} }

View file

@ -270,4 +270,5 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember(StringRef(kVerbose), Log::verbose(), allocator); doc.AddMember(StringRef(kVerbose), Log::verbose(), allocator);
doc.AddMember(StringRef(kWatch), m_watch, allocator); doc.AddMember(StringRef(kWatch), m_watch, allocator);
doc.AddMember(StringRef(kPauseOnBattery), isPauseOnBattery(), allocator); doc.AddMember(StringRef(kPauseOnBattery), isPauseOnBattery(), allocator);
doc.AddMember(StringRef(kPauseOnActive), isPauseOnActive(), allocator);
} }

View file

@ -126,7 +126,8 @@ R"===(
"user-agent": null, "user-agent": null,
"verbose": 0, "verbose": 0,
"watch": true, "watch": true,
"pause-on-battery": false "pause-on-battery": false,
"pause-on-active": false
} }
)==="; )===";
#endif #endif

View file

@ -98,6 +98,7 @@ static const option options[] = {
{ "title", 1, nullptr, IConfig::TitleKey }, { "title", 1, nullptr, IConfig::TitleKey },
{ "no-title", 0, nullptr, IConfig::NoTitleKey }, { "no-title", 0, nullptr, IConfig::NoTitleKey },
{ "pause-on-battery", 0, nullptr, IConfig::PauseOnBatteryKey }, { "pause-on-battery", 0, nullptr, IConfig::PauseOnBatteryKey },
{ "pause-on-active", 0, nullptr, IConfig::PauseOnActiveKey },
# ifdef XMRIG_FEATURE_BENCHMARK # ifdef XMRIG_FEATURE_BENCHMARK
{ "stress", 0, nullptr, IConfig::StressKey }, { "stress", 0, nullptr, IConfig::StressKey },
{ "bench", 1, nullptr, IConfig::BenchKey }, { "bench", 1, nullptr, IConfig::BenchKey },

View file

@ -181,6 +181,7 @@ static inline const std::string &usage()
u += " --no-title disable setting console window title\n"; u += " --no-title disable setting console window title\n";
# endif # endif
u += " --pause-on-battery pause mine on battery power\n"; u += " --pause-on-battery pause mine on battery power\n";
u += " --pause-on-active pause mine when mouse or keyboard is touched\n";
# ifdef XMRIG_FEATURE_BENCHMARK # ifdef XMRIG_FEATURE_BENCHMARK
u += " --stress run continuous stress test to check system stability\n"; u += " --stress run continuous stress test to check system stability\n";