collect packet rate stats in NodeList

This commit is contained in:
Stephen Birarda 2014-03-24 15:06:53 -07:00
parent 40fa4bfbd2
commit 8dbe4dfdde
3 changed files with 40 additions and 6 deletions

View file

@ -369,12 +369,20 @@ void AudioMixer::sendStatsPacket() {
statsObject["average_mixes_per_listener"] = 0.0;
}
NodeList* nodeList = NodeList::getInstance();
float packetsPerSecond, bytesPerSecond;
nodeList->getPacketStats(packetsPerSecond, bytesPerSecond);
nodeList->resetPacketStats();
statsObject["packets_per_second"] = packetsPerSecond;
statsObject["bytes_per_second"] = bytesPerSecond;
_sumListeners = 0;
_sumMixes = 0;
_numStatFrames = 0;
NodeList::getInstance()->sendStatsToDomainServer(statsObject);
nodeList->sendStatsToDomainServer(statsObject);
}
void AudioMixer::run() {

View file

@ -69,7 +69,10 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
_assignmentServerSocket(),
_publicSockAddr(),
_hasCompletedInitialSTUNFailure(false),
_stunRequestsSinceSuccess(0)
_stunRequestsSinceSuccess(0),
_numCollectedPackets(0),
_numCollectedBytes(0),
_packetStatTimer()
{
_nodeSocket.bind(QHostAddress::AnyIPv4, newSocketListenPort);
qDebug() << "NodeList socket is listening on" << _nodeSocket.localPort();
@ -79,6 +82,8 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
// clear our NodeList when logout is requested
connect(&AccountManager::getInstance(), &AccountManager::logoutComplete , this, &NodeList::reset);
_packetStatTimer.start();
}
bool NodeList::packetVersionAndHashMatch(const QByteArray& packet) {
@ -161,7 +166,11 @@ qint64 NodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& d
// setup the MD5 hash for source verification in the header
replaceHashInPacketGivenConnectionUUID(datagramCopy, connectionSecret);
// stat collection for packets
++_numCollectedPackets;
_numCollectedBytes += datagram.size();
return _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr.getAddress(), destinationSockAddr.getPort());
}
@ -854,6 +863,17 @@ SharedNodePointer NodeList::soloNodeOfType(char nodeType) {
return SharedNodePointer();
}
void NodeList::getPacketStats(float& packetsPerSecond, float& bytesPerSecond) {
packetsPerSecond = _numCollectedPackets / (float) (_packetStatTimer.elapsed() / 1000.0f);
bytesPerSecond = _numCollectedBytes / (float) (_packetStatTimer.elapsed() / 1000.0f);
}
void NodeList::resetPacketStats() {
_numCollectedPackets = 0;
_numCollectedBytes = 0;
_packetStatTimer.restart();
}
void NodeList::removeSilentNodes() {
_nodeHashMutex.lock();

View file

@ -21,6 +21,7 @@
#include <unistd.h> // not on windows, not needed for mac or windows
#endif
#include <QtCore/QElapsedTimer>
#include <QtCore/QMutex>
#include <QtCore/QSet>
#include <QtCore/QSettings>
@ -120,6 +121,9 @@ public:
unsigned broadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes);
SharedNodePointer soloNodeOfType(char nodeType);
void getPacketStats(float &packetsPerSecond, float &bytesPerSecond);
void resetPacketStats();
void loadData(QSettings* settings);
void saveData(QSettings* settings);
public slots:
@ -155,6 +159,8 @@ private:
void processDomainServerAuthRequest(const QByteArray& packet);
void requestAuthForDomainServer();
void activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode);
void timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode);
NodeHash _nodeHash;
QMutex _nodeHashMutex;
@ -168,9 +174,9 @@ private:
HifiSockAddr _publicSockAddr;
bool _hasCompletedInitialSTUNFailure;
unsigned int _stunRequestsSinceSuccess;
void activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode);
void timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode);
int _numCollectedPackets;
int _numCollectedBytes;
QElapsedTimer _packetStatTimer;
};
#endif /* defined(__hifi__NodeList__) */