gethashespersec and added version and hashespersec to getinfo
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@127 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
parent
342e1b7338
commit
fb83d28768
4 changed files with 41 additions and 12 deletions
29
main.cpp
29
main.cpp
|
@ -53,6 +53,9 @@ CCriticalSection cs_mapAddressBook;
|
||||||
|
|
||||||
vector<unsigned char> vchDefaultKey;
|
vector<unsigned char> vchDefaultKey;
|
||||||
|
|
||||||
|
double dHashesPerSec;
|
||||||
|
int64 nHPSTimerStart;
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
int fGenerateBitcoins = false;
|
int fGenerateBitcoins = false;
|
||||||
int64 nTransactionFee = 0;
|
int64 nTransactionFee = 0;
|
||||||
|
@ -2542,6 +2545,9 @@ void ThreadBitcoinMiner(void* parg)
|
||||||
PrintException(NULL, "ThreadBitcoinMiner()");
|
PrintException(NULL, "ThreadBitcoinMiner()");
|
||||||
}
|
}
|
||||||
UIThreadCall(bind(CalledSetStatusBar, "", 0));
|
UIThreadCall(bind(CalledSetStatusBar, "", 0));
|
||||||
|
nHPSTimerStart = 0;
|
||||||
|
if (vnThreadsRunning[3] == 0)
|
||||||
|
dHashesPerSec = 0;
|
||||||
printf("ThreadBitcoinMiner exiting, %d threads remaining\n", vnThreadsRunning[3]);
|
printf("ThreadBitcoinMiner exiting, %d threads remaining\n", vnThreadsRunning[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2768,25 +2774,28 @@ void BitcoinMiner()
|
||||||
|
|
||||||
// Update nTime every few seconds
|
// Update nTime every few seconds
|
||||||
const unsigned int nMask = 0xffff;
|
const unsigned int nMask = 0xffff;
|
||||||
|
const int nHashesPerCycle = (nMask+1);
|
||||||
if ((++tmp.block.nNonce & nMask) == 0)
|
if ((++tmp.block.nNonce & nMask) == 0)
|
||||||
{
|
{
|
||||||
// Meter hashes/sec
|
// Meter hashes/sec
|
||||||
static int64 nTimerStart;
|
static int nCycleCounter;
|
||||||
static int nHashCounter;
|
if (nHPSTimerStart == 0)
|
||||||
if (nTimerStart == 0)
|
{
|
||||||
nTimerStart = GetTimeMillis();
|
nHPSTimerStart = GetTimeMillis();
|
||||||
|
nCycleCounter = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
nHashCounter++;
|
nCycleCounter++;
|
||||||
if (GetTimeMillis() - nTimerStart > 4000)
|
if (GetTimeMillis() - nHPSTimerStart > 4000)
|
||||||
{
|
{
|
||||||
static CCriticalSection cs;
|
static CCriticalSection cs;
|
||||||
CRITICAL_BLOCK(cs)
|
CRITICAL_BLOCK(cs)
|
||||||
{
|
{
|
||||||
if (GetTimeMillis() - nTimerStart > 4000)
|
if (GetTimeMillis() - nHPSTimerStart > 4000)
|
||||||
{
|
{
|
||||||
double dHashesPerSec = 1000.0 * (nMask+1) * nHashCounter / (GetTimeMillis() - nTimerStart);
|
dHashesPerSec = 1000.0 * nHashesPerCycle * nCycleCounter / (GetTimeMillis() - nHPSTimerStart);
|
||||||
nTimerStart = GetTimeMillis();
|
nHPSTimerStart = GetTimeMillis();
|
||||||
nHashCounter = 0;
|
nCycleCounter = 0;
|
||||||
string strStatus = strprintf(" %.0f khash/s", dHashesPerSec/1000.0);
|
string strStatus = strprintf(" %.0f khash/s", dHashesPerSec/1000.0);
|
||||||
UIThreadCall(bind(CalledSetStatusBar, strStatus, 0));
|
UIThreadCall(bind(CalledSetStatusBar, strStatus, 0));
|
||||||
static int64 nLogTime;
|
static int64 nLogTime;
|
||||||
|
|
2
main.h
2
main.h
|
@ -42,6 +42,8 @@ extern CCriticalSection cs_mapRequestCount;
|
||||||
extern map<string, string> mapAddressBook;
|
extern map<string, string> mapAddressBook;
|
||||||
extern CCriticalSection cs_mapAddressBook;
|
extern CCriticalSection cs_mapAddressBook;
|
||||||
extern vector<unsigned char> vchDefaultKey;
|
extern vector<unsigned char> vchDefaultKey;
|
||||||
|
extern double dHashesPerSec;
|
||||||
|
extern int64 nHPSTimerStart;
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
extern int fGenerateBitcoins;
|
extern int fGenerateBitcoins;
|
||||||
|
|
20
rpc.cpp
20
rpc.cpp
|
@ -217,13 +217,28 @@ Value setgenerate(const Array& params, bool fHelp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Value gethashespersec(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() != 0)
|
||||||
|
throw runtime_error(
|
||||||
|
"gethashespersec\n"
|
||||||
|
"Returns a recent hashes per second performance measurement while generating.");
|
||||||
|
|
||||||
|
if (GetTimeMillis() - nHPSTimerStart > 8000)
|
||||||
|
return (int64)0;
|
||||||
|
return (int64)dHashesPerSec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Value getinfo(const Array& params, bool fHelp)
|
Value getinfo(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() != 0)
|
if (fHelp || params.size() != 0)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"getinfo");
|
"getinfo\n"
|
||||||
|
"Returns an object containing various state info.");
|
||||||
|
|
||||||
Object obj;
|
Object obj;
|
||||||
|
obj.push_back(Pair("version", (int)VERSION));
|
||||||
obj.push_back(Pair("balance", (double)GetBalance() / (double)COIN));
|
obj.push_back(Pair("balance", (double)GetBalance() / (double)COIN));
|
||||||
obj.push_back(Pair("blocks", (int)nBestHeight + 1));
|
obj.push_back(Pair("blocks", (int)nBestHeight + 1));
|
||||||
obj.push_back(Pair("connections", (int)vNodes.size()));
|
obj.push_back(Pair("connections", (int)vNodes.size()));
|
||||||
|
@ -231,6 +246,7 @@ Value getinfo(const Array& params, bool fHelp)
|
||||||
obj.push_back(Pair("generate", (bool)fGenerateBitcoins));
|
obj.push_back(Pair("generate", (bool)fGenerateBitcoins));
|
||||||
obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1)));
|
obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1)));
|
||||||
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
|
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
|
||||||
|
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,6 +483,7 @@ Value getreceivedbylabel(const Array& params, bool fHelp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct tallyitem
|
struct tallyitem
|
||||||
{
|
{
|
||||||
int64 nAmount;
|
int64 nAmount;
|
||||||
|
@ -635,6 +652,7 @@ pair<string, rpcfn_type> pCallTable[] =
|
||||||
make_pair("getbalance", &getbalance),
|
make_pair("getbalance", &getbalance),
|
||||||
make_pair("getgenerate", &getgenerate),
|
make_pair("getgenerate", &getgenerate),
|
||||||
make_pair("setgenerate", &setgenerate),
|
make_pair("setgenerate", &setgenerate),
|
||||||
|
make_pair("gethashespersec", &gethashespersec),
|
||||||
make_pair("getinfo", &getinfo),
|
make_pair("getinfo", &getinfo),
|
||||||
make_pair("getnewaddress", &getnewaddress),
|
make_pair("getnewaddress", &getnewaddress),
|
||||||
make_pair("setlabel", &setlabel),
|
make_pair("setlabel", &setlabel),
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CDataStream;
|
||||||
class CAutoFile;
|
class CAutoFile;
|
||||||
|
|
||||||
static const int VERSION = 308;
|
static const int VERSION = 308;
|
||||||
static const char* pszSubVer = ".2";
|
static const char* pszSubVer = ".3";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue