Skip to content

Commit

Permalink
Merge pull request bitcoin#25 from gandrewstone/stats
Browse files Browse the repository at this point in the history
add statistics container and example instrumentation
  • Loading branch information
gandrewstone committed Mar 9, 2016
2 parents 1d6eb07 + 627b914 commit dd95ea8
Show file tree
Hide file tree
Showing 12 changed files with 828 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ BITCOIN_CORE_H = \
uint256.h \
undo.h \
unlimited.h \
stat.h \
util.h \
utilmoneystr.h \
utilstrencodings.h \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ RAW_TEST_FILES = test/data/alertTests.raw
GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h)

BITCOIN_TESTS =\
test/stat_tests.cpp \
test/arith_uint256_tests.cpp \
test/scriptnum10.h \
test/addrman_tests.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "utilmoneystr.h"
#include "utilstrencodings.h"
#include "validationinterface.h"
#include "unlimited.h"
#ifdef ENABLE_WALLET
#include "wallet/db.h"
#include "wallet/wallet.h"
Expand Down
16 changes: 16 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ int SocketSendData(CNode* pnode)
int nBytes = send(pnode->hSocket, &data[pnode->nSendOffset], amt2Send, MSG_NOSIGNAL | MSG_DONTWAIT);
if (nBytes > 0) {
progress++; // BU
pnode->bytesSent += nBytes; // BU stats
pnode->nLastSend = GetTime();
pnode->nSendBytes += nBytes;
pnode->nSendOffset += nBytes;
Expand Down Expand Up @@ -1034,6 +1035,7 @@ void ThreadSocketHandler()
int progress; // This variable is incremented if something happens. If it is zero at the bottom of the loop, we delay. This solves spin loop issues where the select does not block but no bytes can be transferred (traffic shaping limited, for example).
while (true) {
progress = 0;
stat_io_service.poll(); // BU instrumentation
//
// Disconnect nodes
//
Expand Down Expand Up @@ -1215,6 +1217,7 @@ void ThreadSocketHandler()
pnode->CloseSocketDisconnect();
pnode->nLastRecv = GetTime();
pnode->nRecvBytes += nBytes;
pnode->bytesReceived += nBytes; // BU stats
pnode->RecordBytesRecv(nBytes);
} else if (nBytes == 0) {
// socket closed gracefully
Expand Down Expand Up @@ -2324,6 +2327,19 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
nMinPingUsecTime = std::numeric_limits<int64_t>::max();
thinBlockWaitingForTxns = -1; // BUIP010 Xtreme Thinblocks

// BU instrumentation
std::string xmledName;
if (addrNameIn != "") xmledName = addrNameIn;
else
{
xmledName="ip" + addr.ToStringIP() + "p" + addr.ToStringPort();
}
bytesSent.init("node/" + xmledName + "/bytesSent");
bytesReceived.init("node/" + xmledName + "/bytesReceived");
//txReqLatency.init("node/" + xmledName + "/txLatency", STAT_OP_AVE);
//firstTx.init("node/" + xmledName + "/firstTxn");
//firstBlock.init("node/" + xmledName + "/firstBlock");

{
LOCK(cs_nLastNodeId);
id = nLastNodeId++;
Expand Down
13 changes: 13 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <boost/signals2/signal.hpp>

#include "unlimited.h"
#include "stat.h"

class CAddrMan;
class CScheduler;
Expand Down Expand Up @@ -429,6 +430,18 @@ class CNode
// Whether a ping is requested.
bool fPingQueued;

// BU instrumentation
// track the number of bytes sent to this node
CStatHistory<unsigned int > bytesSent;
// track the number of bytes received from this node
CStatHistory<unsigned int > bytesReceived;
// track the average round trip latency for transaction requests to this node
// CStatHistory<unsigned int > txReqLatency;
// track the # of times this node is the first to send us a transaction INV
//CStatHistory<unsigned int> firstTx;
// track the # of times this node is the first to send us a block INV
//CStatHistory<unsigned int> firstBlock;

CNode(SOCKET hSocketIn, const CAddress &addrIn, const std::string &addrNameIn = "", bool fInboundIn = false);
~CNode();

Expand Down
2 changes: 2 additions & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ static const CRPCCommand vRPCCommands[] =
{ "util", "estimatepriority", &estimatepriority, true },
{ "util", "estimatesmartfee", &estimatesmartfee, true },
{ "util", "estimatesmartpriority", &estimatesmartpriority, true },
{ "util", "getstatlist", &getstatlist, true }, // BU
{ "util", "getstat", &getstat, true }, // BU

/* Not shown in help */
{ "hidden", "invalidateblock", &invalidateblock, true },
Expand Down
Loading

0 comments on commit dd95ea8

Please sign in to comment.