diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2019-01-02 12:34:39 +0000 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2019-01-02 12:34:58 +0000 |
commit | 068a8fc05f8dbec198bdc3fe46f955d8a5255303 (patch) | |
tree | 41bfa4f50cafb48cfa740ab1532df71b173300f3 /src/rpc/server.cpp | |
parent | bf4383277d6761cc5b7a91975752c08df829af72 (diff) |
rpc: Track active commands
Diffstat (limited to 'src/rpc/server.cpp')
-rw-r--r-- | src/rpc/server.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5b4d8e2f3d..926fabe6af 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -32,6 +32,35 @@ static RPCTimerInterface* timerInterface = nullptr; /* Map of name to timer. */ static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers; +struct RPCCommandExecutionInfo +{ + std::string method; + int64_t start; +}; + +struct RPCServerInfo +{ + Mutex mutex; + std::list<RPCCommandExecutionInfo> active_commands GUARDED_BY(mutex); +}; + +static RPCServerInfo g_rpc_server_info; + +struct RPCCommandExecution +{ + std::list<RPCCommandExecutionInfo>::iterator it; + explicit RPCCommandExecution(const std::string& method) + { + LOCK(g_rpc_server_info.mutex); + it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.cend(), {method, GetTimeMicros()}); + } + ~RPCCommandExecution() + { + LOCK(g_rpc_server_info.mutex); + g_rpc_server_info.active_commands.erase(it); + } +}; + static struct CRPCSignals { boost::signals2::signal<void ()> Started; @@ -485,6 +514,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const try { + RPCCommandExecution execution(request.strMethod); // Execute, convert arguments to array if necessary if (request.params.isObject()) { return pcmd->actor(transformNamedArguments(request, pcmd->argNames)); |