Browse Source

gethashespersec and added version and hashespersec to getinfo

miguelfreitas
Satoshi Nakamoto 15 years ago committed by Gavin Andresen
parent
commit
9db7bf5f52
  1. 29
      main.cpp
  2. 2
      main.h
  3. 20
      rpc.cpp
  4. 2
      serialize.h

29
main.cpp

@ -53,6 +53,9 @@ CCriticalSection cs_mapAddressBook; @@ -53,6 +53,9 @@ CCriticalSection cs_mapAddressBook;
vector<unsigned char> vchDefaultKey;
double dHashesPerSec;
int64 nHPSTimerStart;
// Settings
int fGenerateBitcoins = false;
int64 nTransactionFee = 0;
@ -2542,6 +2545,9 @@ void ThreadBitcoinMiner(void* parg) @@ -2542,6 +2545,9 @@ void ThreadBitcoinMiner(void* parg)
PrintException(NULL, "ThreadBitcoinMiner()");
}
UIThreadCall(bind(CalledSetStatusBar, "", 0));
nHPSTimerStart = 0;
if (vnThreadsRunning[3] == 0)
dHashesPerSec = 0;
printf("ThreadBitcoinMiner exiting, %d threads remaining\n", vnThreadsRunning[3]);
}
@ -2768,25 +2774,28 @@ void BitcoinMiner() @@ -2768,25 +2774,28 @@ void BitcoinMiner()
// Update nTime every few seconds
const unsigned int nMask = 0xffff;
const int nHashesPerCycle = (nMask+1);
if ((++tmp.block.nNonce & nMask) == 0)
{
// Meter hashes/sec
static int64 nTimerStart;
static int nHashCounter;
if (nTimerStart == 0)
nTimerStart = GetTimeMillis();
static int nCycleCounter;
if (nHPSTimerStart == 0)
{
nHPSTimerStart = GetTimeMillis();
nCycleCounter = 0;
}
else
nHashCounter++;
if (GetTimeMillis() - nTimerStart > 4000)
nCycleCounter++;
if (GetTimeMillis() - nHPSTimerStart > 4000)
{
static CCriticalSection cs;
CRITICAL_BLOCK(cs)
{
if (GetTimeMillis() - nTimerStart > 4000)
if (GetTimeMillis() - nHPSTimerStart > 4000)
{
double dHashesPerSec = 1000.0 * (nMask+1) * nHashCounter / (GetTimeMillis() - nTimerStart);
nTimerStart = GetTimeMillis();
nHashCounter = 0;
dHashesPerSec = 1000.0 * nHashesPerCycle * nCycleCounter / (GetTimeMillis() - nHPSTimerStart);
nHPSTimerStart = GetTimeMillis();
nCycleCounter = 0;
string strStatus = strprintf(" %.0f khash/s", dHashesPerSec/1000.0);
UIThreadCall(bind(CalledSetStatusBar, strStatus, 0));
static int64 nLogTime;

2
main.h

@ -42,6 +42,8 @@ extern CCriticalSection cs_mapRequestCount; @@ -42,6 +42,8 @@ extern CCriticalSection cs_mapRequestCount;
extern map<string, string> mapAddressBook;
extern CCriticalSection cs_mapAddressBook;
extern vector<unsigned char> vchDefaultKey;
extern double dHashesPerSec;
extern int64 nHPSTimerStart;
// Settings
extern int fGenerateBitcoins;

20
rpc.cpp

@ -217,13 +217,28 @@ Value setgenerate(const Array& params, bool fHelp) @@ -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)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getinfo");
"getinfo\n"
"Returns an object containing various state info.");
Object obj;
obj.push_back(Pair("version", (int)VERSION));
obj.push_back(Pair("balance", (double)GetBalance() / (double)COIN));
obj.push_back(Pair("blocks", (int)nBestHeight + 1));
obj.push_back(Pair("connections", (int)vNodes.size()));
@ -231,6 +246,7 @@ Value getinfo(const Array& params, bool fHelp) @@ -231,6 +246,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("generate", (bool)fGenerateBitcoins));
obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1)));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
return obj;
}
@ -467,6 +483,7 @@ Value getreceivedbylabel(const Array& params, bool fHelp) @@ -467,6 +483,7 @@ Value getreceivedbylabel(const Array& params, bool fHelp)
}
struct tallyitem
{
int64 nAmount;
@ -635,6 +652,7 @@ pair<string, rpcfn_type> pCallTable[] = @@ -635,6 +652,7 @@ pair<string, rpcfn_type> pCallTable[] =
make_pair("getbalance", &getbalance),
make_pair("getgenerate", &getgenerate),
make_pair("setgenerate", &setgenerate),
make_pair("gethashespersec", &gethashespersec),
make_pair("getinfo", &getinfo),
make_pair("getnewaddress", &getnewaddress),
make_pair("setlabel", &setlabel),

2
serialize.h

@ -20,7 +20,7 @@ class CDataStream; @@ -20,7 +20,7 @@ class CDataStream;
class CAutoFile;
static const int VERSION = 308;
static const char* pszSubVer = ".2";
static const char* pszSubVer = ".3";

Loading…
Cancel
Save