mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
merge bitcoin#25456: Use steady_clock for getrpcinfo durations
This commit is contained in:
parent
ea3c727e02
commit
c7cb26ba05
@ -16,16 +16,20 @@
|
|||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
#include <util/time.h>
|
||||||
|
|
||||||
#include <boost/signals2/signal.hpp>
|
#include <boost/signals2/signal.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <memory> // for unique_ptr
|
#include <chrono>
|
||||||
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
using SteadyClock = std::chrono::steady_clock;
|
||||||
|
|
||||||
static Mutex g_rpc_warmup_mutex;
|
static Mutex g_rpc_warmup_mutex;
|
||||||
static std::atomic<bool> g_rpc_running{false};
|
static std::atomic<bool> g_rpc_running{false};
|
||||||
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
|
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
|
||||||
@ -43,7 +47,7 @@ static const std::string defaultPlatformUser = "platform-user";
|
|||||||
struct RPCCommandExecutionInfo
|
struct RPCCommandExecutionInfo
|
||||||
{
|
{
|
||||||
std::string method;
|
std::string method;
|
||||||
int64_t start;
|
SteadyClock::time_point start;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RPCServerInfo
|
struct RPCServerInfo
|
||||||
@ -60,7 +64,7 @@ struct RPCCommandExecution
|
|||||||
explicit RPCCommandExecution(const std::string& method)
|
explicit RPCCommandExecution(const std::string& method)
|
||||||
{
|
{
|
||||||
LOCK(g_rpc_server_info.mutex);
|
LOCK(g_rpc_server_info.mutex);
|
||||||
it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.end(), {method, GetTimeMicros()});
|
it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.end(), {method, SteadyClock::now()});
|
||||||
}
|
}
|
||||||
~RPCCommandExecution()
|
~RPCCommandExecution()
|
||||||
{
|
{
|
||||||
@ -272,7 +276,7 @@ static RPCHelpMan getrpcinfo()
|
|||||||
for (const RPCCommandExecutionInfo& info : g_rpc_server_info.active_commands) {
|
for (const RPCCommandExecutionInfo& info : g_rpc_server_info.active_commands) {
|
||||||
UniValue entry(UniValue::VOBJ);
|
UniValue entry(UniValue::VOBJ);
|
||||||
entry.pushKV("method", info.method);
|
entry.pushKV("method", info.method);
|
||||||
entry.pushKV("duration", GetTimeMicros() - info.start);
|
entry.pushKV("duration", int64_t{Ticks<std::chrono::microseconds>(SteadyClock::now() - info.start)});
|
||||||
active_commands.push_back(entry);
|
active_commands.push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +41,15 @@ void UninterruptibleSleep(const std::chrono::microseconds& n);
|
|||||||
* This helper is used to convert durations/time_points before passing them over an
|
* This helper is used to convert durations/time_points before passing them over an
|
||||||
* interface that doesn't support std::chrono (e.g. RPC, debug log, or the GUI)
|
* interface that doesn't support std::chrono (e.g. RPC, debug log, or the GUI)
|
||||||
*/
|
*/
|
||||||
|
template <typename Dur1, typename Dur2>
|
||||||
|
constexpr auto Ticks(Dur2 d)
|
||||||
|
{
|
||||||
|
return std::chrono::duration_cast<Dur1>(d).count();
|
||||||
|
}
|
||||||
template <typename Duration, typename Timepoint>
|
template <typename Duration, typename Timepoint>
|
||||||
constexpr auto TicksSinceEpoch(Timepoint t)
|
constexpr auto TicksSinceEpoch(Timepoint t)
|
||||||
{
|
{
|
||||||
return std::chrono::time_point_cast<Duration>(t).time_since_epoch().count();
|
return Ticks<Duration>(t.time_since_epoch());
|
||||||
}
|
}
|
||||||
constexpr int64_t count_seconds(std::chrono::seconds t) { return t.count(); }
|
constexpr int64_t count_seconds(std::chrono::seconds t) { return t.count(); }
|
||||||
constexpr int64_t count_milliseconds(std::chrono::milliseconds t) { return t.count(); }
|
constexpr int64_t count_milliseconds(std::chrono::milliseconds t) { return t.count(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user