MCPcopy Create free account
hub / github.com/ElementsProject/elements / getmemoryinfo

Function getmemoryinfo

src/rpc/misc.cpp:566–619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

564#endif
565
566static RPCHelpMan getmemoryinfo()
567{
568 /* Please, avoid using the word "pool" here in the RPC interface or help,
569 * as users will undoubtedly confuse it with the other "memory pool"
570 */
571 return RPCHelpMan{"getmemoryinfo",
572 "Returns an object containing information about memory usage.\n",
573 {
574 {"mode", RPCArg::Type::STR, RPCArg::Default{"stats"}, "determines what kind of information is returned.\n"
575 " - \"stats\" returns general statistics about memory usage in the daemon.\n"
576 " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+)."},
577 },
578 {
579 RPCResult{"mode \"stats\"",
580 RPCResult::Type::OBJ, "", "",
581 {
582 {RPCResult::Type::OBJ, "locked", "Information about locked memory manager",
583 {
584 {RPCResult::Type::NUM, "used", "Number of bytes used"},
585 {RPCResult::Type::NUM, "free", "Number of bytes available in current arenas"},
586 {RPCResult::Type::NUM, "total", "Total number of bytes managed"},
587 {RPCResult::Type::NUM, "locked", "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."},
588 {RPCResult::Type::NUM, "chunks_used", "Number allocated chunks"},
589 {RPCResult::Type::NUM, "chunks_free", "Number unused chunks"},
590 }},
591 }
592 },
593 RPCResult{"mode \"mallocinfo\"",
594 RPCResult::Type::STR, "", "\"<malloc version=\"1\">...\""
595 },
596 },
597 RPCExamples{
598 HelpExampleCli("getmemoryinfo", "")
599 + HelpExampleRpc("getmemoryinfo", "")
600 },
601 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
602{
603 std::string mode = request.params[0].isNull() ? "stats" : request.params[0].get_str();
604 if (mode == "stats") {
605 UniValue obj(UniValue::VOBJ);
606 obj.pushKV("locked", RPCLockedMemoryInfo());
607 return obj;
608 } else if (mode == "mallocinfo") {
609#ifdef HAVE_MALLOC_INFO
610 return RPCMallocInfo();
611#else
612 throw JSONRPCError(RPC_INVALID_PARAMETER, "mallocinfo mode not available");
613#endif
614 } else {
615 throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown mode " + mode);
616 }
617},
618 };
619}
620
621static void EnableOrDisableLogCategories(UniValue cats, bool enable) {
622 cats = cats.get_array();

Callers

nothing calls this directly

Calls 7

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
RPCLockedMemoryInfoFunction · 0.85
RPCMallocInfoFunction · 0.85
JSONRPCErrorFunction · 0.85
isNullMethod · 0.45
pushKVMethod · 0.45

Tested by

no test coverage detected