Skip to content

Commit 068a8fc

Browse files
committed
rpc: Track active commands
1 parent bf43832 commit 068a8fc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/rpc/server.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,35 @@ static RPCTimerInterface* timerInterface = nullptr;
3232
/* Map of name to timer. */
3333
static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers;
3434

35+
struct RPCCommandExecutionInfo
36+
{
37+
std::string method;
38+
int64_t start;
39+
};
40+
41+
struct RPCServerInfo
42+
{
43+
Mutex mutex;
44+
std::list<RPCCommandExecutionInfo> active_commands GUARDED_BY(mutex);
45+
};
46+
47+
static RPCServerInfo g_rpc_server_info;
48+
49+
struct RPCCommandExecution
50+
{
51+
std::list<RPCCommandExecutionInfo>::iterator it;
52+
explicit RPCCommandExecution(const std::string& method)
53+
{
54+
LOCK(g_rpc_server_info.mutex);
55+
it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.cend(), {method, GetTimeMicros()});
56+
}
57+
~RPCCommandExecution()
58+
{
59+
LOCK(g_rpc_server_info.mutex);
60+
g_rpc_server_info.active_commands.erase(it);
61+
}
62+
};
63+
3564
static struct CRPCSignals
3665
{
3766
boost::signals2::signal<void ()> Started;
@@ -485,6 +514,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
485514

486515
try
487516
{
517+
RPCCommandExecution execution(request.strMethod);
488518
// Execute, convert arguments to array if necessary
489519
if (request.params.isObject()) {
490520
return pcmd->actor(transformNamedArguments(request, pcmd->argNames));

0 commit comments

Comments
 (0)