Skip to content

Commit 6567999

Browse files
committed
rpc: Add getmemoryinfo call
``` getmemoryinfo Returns an object containing information about memory usage. Result: { "locked": { (json object) Information about locked memory manager "used": xxxxx, (numeric) Number of bytes used "free": xxxxx, (numeric) Number of bytes available in current arenas "total": xxxxxxx, (numeric) Total number of bytes managed "locked": xxxxxx, (numeric) Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk. } } Examples: > bitcoin-cli getmemoryinfo > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getmemoryinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/ ```
1 parent 4536148 commit 6567999

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/rpc/misc.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,53 @@ UniValue setmocktime(const JSONRPCRequest& request)
450450
return NullUniValue;
451451
}
452452

453+
static UniValue RPCLockedMemoryInfo()
454+
{
455+
LockedPool::Stats stats = LockedPoolManager::Instance().stats();
456+
UniValue obj(UniValue::VOBJ);
457+
obj.push_back(Pair("used", uint64_t(stats.used)));
458+
obj.push_back(Pair("free", uint64_t(stats.free)));
459+
obj.push_back(Pair("total", uint64_t(stats.total)));
460+
obj.push_back(Pair("locked", uint64_t(stats.locked)));
461+
obj.push_back(Pair("chunks_used", uint64_t(stats.chunks_used)));
462+
obj.push_back(Pair("chunks_free", uint64_t(stats.chunks_free)));
463+
return obj;
464+
}
465+
466+
UniValue getmemoryinfo(const JSONRPCRequest& request)
467+
{
468+
/* Please, avoid using the word "pool" here in the RPC interface or help,
469+
* as users will undoubtedly confuse it with the other "memory pool"
470+
*/
471+
if (request.fHelp || request.params.size() != 0)
472+
throw runtime_error(
473+
"getmemoryinfo\n"
474+
"Returns an object containing information about memory usage.\n"
475+
"\nResult:\n"
476+
"{\n"
477+
" \"locked\": { (json object) Information about locked memory manager\n"
478+
" \"used\": xxxxx, (numeric) Number of bytes used\n"
479+
" \"free\": xxxxx, (numeric) Number of bytes available in current arenas\n"
480+
" \"total\": xxxxxxx, (numeric) Total number of bytes managed\n"
481+
" \"locked\": xxxxxx, (numeric) Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk.\n"
482+
" \"chunks_used\": xxxxx, (numeric) Number allocated chunks\n"
483+
" \"chunks_free\": xxxxx, (numeric) Number unused chunks\n"
484+
" }\n"
485+
"}\n"
486+
"\nExamples:\n"
487+
+ HelpExampleCli("getmemoryinfo", "")
488+
+ HelpExampleRpc("getmemoryinfo", "")
489+
);
490+
UniValue obj(UniValue::VOBJ);
491+
obj.push_back(Pair("locked", RPCLockedMemoryInfo()));
492+
return obj;
493+
}
494+
453495
static const CRPCCommand commands[] =
454496
{ // category name actor (function) okSafeMode
455497
// --------------------- ------------------------ ----------------------- ----------
456498
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
499+
{ "control", "getmemoryinfo", &getmemoryinfo, true },
457500
{ "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */
458501
{ "util", "createmultisig", &createmultisig, true },
459502
{ "util", "verifymessage", &verifymessage, true },

0 commit comments

Comments
 (0)