add rpc call to get chronos futures at runtime

This commit is contained in:
Jacek Sieka 2020-11-15 16:35:16 +01:00 committed by zah
parent b2e0221f2d
commit 5b011b65ae
3 changed files with 35 additions and 1 deletions

View File

@ -6,6 +6,7 @@
import
std/strutils,
chronos,
stew/shims/macros,
stew/byteutils,
json_rpc/[rpcserver, jsonmarshal],
@ -18,6 +19,15 @@ logScope: topics = "nimbusapi"
type
RpcServer = RpcHttpServer
when defined(chronosFutureTracking):
type
FutureInfo* = object
id*: int
procname*: string
filename*: string
line*: int
state: string
proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
## Install non-standard api handlers - some of these are used by 3rd-parties
## such as eth2stats, pending a full REST api
@ -88,3 +98,19 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
{.gcsafe.}: # It's probably not, actually. Hopefully we don't log from threads...
updateLogLevel(level)
return true
when defined(chronosFutureTracking):
rpcServer.rpc("getChronosFutures") do () -> seq[FutureInfo]:
var res: seq[FutureInfo]
for item in pendingFutures():
let loc = item.location[LocCreateIndex][]
res.add FutureInfo(
id: item.id,
procname: $loc.procedure,
filename: $loc.file,
line: loc.line,
state: $item.state
)
return res

View File

@ -183,3 +183,11 @@ Set the current logging level dynamically: TRACE, DEBUG, INFO, NOTICE, WARN, ERR
```
curl -d '{"jsonrpc":"2.0","id":"id","method":"setLogLevel","params":["DEBUG; TRACE:discv5,libp2p; REQUIRED:none; DISABLED:none"] }' -H 'Content-Type: application/json' localhost:9190 -s | jq
```
### getChronosFutures
Get the current list of live async futures in the process - compile with `-d:chronosFutureTracking` to enable.
```
curl -d '{"jsonrpc":"2.0","id":"id","method":"getChronosFutures","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq '.result | (.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv'
```

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit 1ffd1cd3dc2145b6922eba465d29d1990e9d4254
Subproject commit 710454cc6b792748144882d7c97912b0c6cef138