mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 10:01:06 +00:00
Use normalize for load average values.
This commit is contained in:
parent
901f1a7ab1
commit
a4d35065d9
4 changed files with 26 additions and 11 deletions
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "backend/common/Hashrate.h"
|
#include "backend/common/Hashrate.h"
|
||||||
|
#include "base/io/json/Json.h"
|
||||||
#include "base/tools/Chrono.h"
|
#include "base/tools/Chrono.h"
|
||||||
#include "base/tools/Handle.h"
|
#include "base/tools/Handle.h"
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
@ -157,13 +158,7 @@ const char *xmrig::Hashrate::format(double h, char *buf, size_t size)
|
||||||
|
|
||||||
rapidjson::Value xmrig::Hashrate::normalize(double d)
|
rapidjson::Value xmrig::Hashrate::normalize(double d)
|
||||||
{
|
{
|
||||||
using namespace rapidjson;
|
return Json::normalize(d, false);
|
||||||
|
|
||||||
if (!std::isnormal(d)) {
|
|
||||||
return Value(kNullType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Value(floor(d * 100.0) / 100.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "base/api/Api.h"
|
#include "base/api/Api.h"
|
||||||
|
#include "3rdparty/http-parser/http_parser.h"
|
||||||
#include "base/api/interfaces/IApiListener.h"
|
#include "base/api/interfaces/IApiListener.h"
|
||||||
#include "base/api/requests/HttpApiRequest.h"
|
#include "base/api/requests/HttpApiRequest.h"
|
||||||
|
#include "base/io/json/Json.h"
|
||||||
#include "base/kernel/Base.h"
|
#include "base/kernel/Base.h"
|
||||||
#include "base/tools/Buffer.h"
|
#include "base/tools/Buffer.h"
|
||||||
#include "base/tools/Chrono.h"
|
#include "base/tools/Chrono.h"
|
||||||
|
@ -73,9 +74,10 @@ static rapidjson::Value getResources(rapidjson::Document &doc)
|
||||||
|
|
||||||
double loadavg[3] = { 0.0 };
|
double loadavg[3] = { 0.0 };
|
||||||
uv_loadavg(loadavg);
|
uv_loadavg(loadavg);
|
||||||
load_average.PushBack(loadavg[0], allocator);
|
|
||||||
load_average.PushBack(loadavg[1], allocator);
|
for (double value : loadavg) {
|
||||||
load_average.PushBack(loadavg[2], allocator);
|
load_average.PushBack(Json::normalize(value, true), allocator);
|
||||||
|
}
|
||||||
|
|
||||||
out.AddMember("memory", memory, allocator);
|
out.AddMember("memory", memory, allocator);
|
||||||
out.AddMember("load_average", load_average, allocator);
|
out.AddMember("load_average", load_average, allocator);
|
||||||
|
@ -182,6 +184,9 @@ void xmrig::Api::exec(IApiRequest &request)
|
||||||
# endif
|
# endif
|
||||||
# ifdef XMRIG_FEATURE_OPENCL
|
# ifdef XMRIG_FEATURE_OPENCL
|
||||||
features.PushBack("opencl", allocator);
|
features.PushBack("opencl", allocator);
|
||||||
|
# endif
|
||||||
|
# ifdef XMRIG_FEATURE_CUDA
|
||||||
|
features.PushBack("cuda", allocator);
|
||||||
# endif
|
# endif
|
||||||
reply.AddMember("features", features, allocator);
|
reply.AddMember("features", features, allocator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -154,6 +155,18 @@ unsigned xmrig::Json::getUint(const rapidjson::Value &obj, const char *key, unsi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::Json::normalize(double value, bool zero)
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
|
||||||
|
if (!std::isnormal(value)) {
|
||||||
|
return zero ? Value(0.0) : Value(kNullType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Value(floor(value * 100.0) / 100.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool xmrig::JsonReader::isEmpty() const
|
bool xmrig::JsonReader::isEmpty() const
|
||||||
{
|
{
|
||||||
return !m_obj.IsObject() || m_obj.ObjectEmpty();
|
return !m_obj.IsObject() || m_obj.ObjectEmpty();
|
||||||
|
|
|
@ -48,6 +48,8 @@ public:
|
||||||
|
|
||||||
static bool get(const char *fileName, rapidjson::Document &doc);
|
static bool get(const char *fileName, rapidjson::Document &doc);
|
||||||
static bool save(const char *fileName, const rapidjson::Document &doc);
|
static bool save(const char *fileName, const rapidjson::Document &doc);
|
||||||
|
|
||||||
|
static rapidjson::Value normalize(double value, bool zero);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue