mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 21:42:47 +01:00
Add ability to change debug category on the fly from console
NOTE: Before switching to another debug catgory you'd need to turn debugging off via "debug 0" and wait a bit (each thread (de)activates debug mode on its own)
This commit is contained in:
parent
a7fd7821e9
commit
2fc05e5b9d
@ -24,6 +24,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <boost/assign/list_of.hpp>
|
#include <boost/assign/list_of.hpp>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
@ -113,6 +114,30 @@ UniValue getinfo(const UniValue& params, bool fHelp)
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue debug(const UniValue& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() != 1)
|
||||||
|
throw runtime_error(
|
||||||
|
"debug ( 0|1|addrman|alert|bench|coindb|db|lock|rand|rpc|selectcoins|mempool"
|
||||||
|
"|mempoolrej|net|proxy|prune|http|libevent|tor|zmq|"
|
||||||
|
"dash|darksend|instantx|masternode|keepass|mnpayments|mnbudget )\n"
|
||||||
|
"Change debug category on the fly. Specify single category or use comma to specify many.\n"
|
||||||
|
"\nExamples:\n"
|
||||||
|
+ HelpExampleCli("debug", "dash")
|
||||||
|
+ HelpExampleRpc("debug", "dash,net")
|
||||||
|
);
|
||||||
|
|
||||||
|
std::string strMode = params[0].get_str();
|
||||||
|
|
||||||
|
mapMultiArgs["-debug"].clear();
|
||||||
|
boost::split(mapMultiArgs["-debug"], strMode, boost::is_any_of(","));
|
||||||
|
mapArgs["-debug"] = mapMultiArgs["-debug"][mapMultiArgs["-debug"].size() - 1];
|
||||||
|
|
||||||
|
fDebug = mapArgs["-debug"] != "0";
|
||||||
|
|
||||||
|
return "Debug mode: " + (fDebug ? strMode : "off");
|
||||||
|
}
|
||||||
|
|
||||||
UniValue mnsync(const UniValue& params, bool fHelp)
|
UniValue mnsync(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() != 1)
|
if (fHelp || params.size() != 1)
|
||||||
|
@ -258,6 +258,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
// --------------------- ------------------------ ----------------------- ----------
|
// --------------------- ------------------------ ----------------------- ----------
|
||||||
/* Overall control/query calls */
|
/* Overall control/query calls */
|
||||||
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
|
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
|
||||||
|
{ "control", "debug", &debug, true },
|
||||||
{ "control", "help", &help, true },
|
{ "control", "help", &help, true },
|
||||||
{ "control", "stop", &stop, true },
|
{ "control", "stop", &stop, true },
|
||||||
|
|
||||||
|
@ -232,6 +232,7 @@ extern UniValue walletlock(const UniValue& params, bool fHelp);
|
|||||||
extern UniValue encryptwallet(const UniValue& params, bool fHelp);
|
extern UniValue encryptwallet(const UniValue& params, bool fHelp);
|
||||||
extern UniValue validateaddress(const UniValue& params, bool fHelp);
|
extern UniValue validateaddress(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getinfo(const UniValue& params, bool fHelp);
|
extern UniValue getinfo(const UniValue& params, bool fHelp);
|
||||||
|
extern UniValue debug(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
|
extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
|
extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);
|
extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);
|
||||||
|
16
src/util.cpp
16
src/util.cpp
@ -253,16 +253,26 @@ bool LogAcceptCategory(const char* category)
|
|||||||
{
|
{
|
||||||
if (category != NULL)
|
if (category != NULL)
|
||||||
{
|
{
|
||||||
if (!fDebug)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Give each thread quick access to -debug settings.
|
// Give each thread quick access to -debug settings.
|
||||||
// This helps prevent issues debugging global destructors,
|
// This helps prevent issues debugging global destructors,
|
||||||
// where mapMultiArgs might be deleted before another
|
// where mapMultiArgs might be deleted before another
|
||||||
// global destructor calls LogPrint()
|
// global destructor calls LogPrint()
|
||||||
static boost::thread_specific_ptr<set<string> > ptrCategory;
|
static boost::thread_specific_ptr<set<string> > ptrCategory;
|
||||||
|
|
||||||
|
if (!fDebug) {
|
||||||
|
if (ptrCategory.get() != NULL) {
|
||||||
|
LogPrintf("debug turned off: thread %s\n", GetThreadName());
|
||||||
|
ptrCategory.release();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (ptrCategory.get() == NULL)
|
if (ptrCategory.get() == NULL)
|
||||||
{
|
{
|
||||||
|
std::string strThreadName = GetThreadName();
|
||||||
|
LogPrintf("debug turned on:\n");
|
||||||
|
for (int i = 0; i < (int)mapMultiArgs["-debug"].size(); ++i)
|
||||||
|
LogPrintf(" thread %s category %s\n", strThreadName, mapMultiArgs["-debug"][i]);
|
||||||
const vector<string>& categories = mapMultiArgs["-debug"];
|
const vector<string>& categories = mapMultiArgs["-debug"];
|
||||||
ptrCategory.reset(new set<string>(categories.begin(), categories.end()));
|
ptrCategory.reset(new set<string>(categories.begin(), categories.end()));
|
||||||
// thread_specific_ptr automatically deletes the set when the thread ends.
|
// thread_specific_ptr automatically deletes the set when the thread ends.
|
||||||
|
Loading…
Reference in New Issue
Block a user