mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 12:57:38 +02:00
cleaned up debug statements
also reorganized MovingPercentile a little bit
This commit is contained in:
parent
6f45939113
commit
b452d08495
10 changed files with 26 additions and 232 deletions
|
@ -25,39 +25,7 @@ DatagramProcessor::DatagramProcessor(QObject* parent) :
|
|||
|
||||
}
|
||||
|
||||
|
||||
// DEBUG
|
||||
|
||||
int DatagramProcessor::skewsI[10000];
|
||||
int DatagramProcessor::S = 0;
|
||||
|
||||
unsigned char DatagramProcessor::typesI[10000];
|
||||
int DatagramProcessor::diffsI[10000];
|
||||
int DatagramProcessor::I = 0;
|
||||
|
||||
|
||||
|
||||
quint64 DatagramProcessor::prevTime = 0;
|
||||
|
||||
unsigned char DatagramProcessor::typesA[100];
|
||||
quint64 DatagramProcessor::timesA[100];
|
||||
int DatagramProcessor::A = 1;
|
||||
|
||||
unsigned char DatagramProcessor::typesB[100];
|
||||
quint64 DatagramProcessor::timesB[100];
|
||||
int DatagramProcessor::B = 1;
|
||||
|
||||
unsigned char* DatagramProcessor::currTypes = typesA;
|
||||
unsigned char* DatagramProcessor::prevTypes = typesB;
|
||||
quint64* DatagramProcessor::currTimes = timesA;
|
||||
quint64* DatagramProcessor::prevTimes = timesB;
|
||||
int* DatagramProcessor::currN = &A;
|
||||
int* DatagramProcessor::prevN = &B;
|
||||
|
||||
|
||||
|
||||
void DatagramProcessor::processDatagrams() {
|
||||
|
||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||
"DatagramProcessor::processDatagrams()");
|
||||
|
||||
|
@ -68,29 +36,6 @@ void DatagramProcessor::processDatagrams() {
|
|||
Application* application = Application::getInstance();
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
|
||||
|
||||
|
||||
prevTime = prevTimes[*prevN-1];
|
||||
|
||||
// swap
|
||||
unsigned char* temp = currTypes;
|
||||
currTypes = prevTypes;
|
||||
prevTypes = temp;
|
||||
// swap
|
||||
quint64* temp2 = currTimes;
|
||||
currTimes = prevTimes;
|
||||
prevTimes = temp2;
|
||||
// swap
|
||||
int* temp3 = currN;
|
||||
currN = prevN;
|
||||
prevN = temp3;
|
||||
|
||||
// reset
|
||||
*currN = 0;
|
||||
|
||||
int skew = 0;
|
||||
|
||||
|
||||
while (NodeList::getInstance()->getNodeSocket().hasPendingDatagrams()) {
|
||||
incomingPacket.resize(nodeList->getNodeSocket().pendingDatagramSize());
|
||||
nodeList->getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(),
|
||||
|
@ -101,14 +46,8 @@ int skew = 0;
|
|||
|
||||
if (nodeList->packetVersionAndHashMatch(incomingPacket)) {
|
||||
|
||||
PacketType type = packetTypeForPacket(incomingPacket);
|
||||
currTimes[*currN] = usecTimestampNow();
|
||||
currTypes[*currN] = (unsigned char)type;
|
||||
(*currN)++;
|
||||
|
||||
|
||||
// only process this packet if we have a match on the packet version
|
||||
switch (type) { //packetTypeForPacket(incomingPacket)) {
|
||||
switch (packetTypeForPacket(incomingPacket)) {
|
||||
case PacketTypeMixedAudio:
|
||||
QMetaObject::invokeMethod(&application->_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection,
|
||||
Q_ARG(QByteArray, incomingPacket));
|
||||
|
@ -208,55 +147,9 @@ currTypes[*currN] = (unsigned char)type;
|
|||
break;
|
||||
}
|
||||
default:
|
||||
int s = nodeList->processNodeData(senderSockAddr, incomingPacket);
|
||||
if (s!=1234567890 && abs(s) > abs(skew))
|
||||
skew = s;
|
||||
nodeList->processNodeData(senderSockAddr, incomingPacket);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (abs(skew) > 3000) {
|
||||
|
||||
printf("large skew! %d ----------------------------\n", skew);
|
||||
|
||||
skewsI[S++] = skew;
|
||||
|
||||
/*
|
||||
printf("prev:::::::::::::::::::::::::::::::::::::\n");
|
||||
|
||||
printf("\t type: %d time: %llu diff: %llu\n", prevTypes[0], prevTimes[0] % 100000000, prevTimes[0] - prevTime);
|
||||
for (int i = 1; i < *prevN; i++) {
|
||||
printf("\t type: %d time: %llu diff: %llu\n", prevTypes[i], prevTimes[i] % 100000000, prevTimes[i] - prevTimes[i - 1]);
|
||||
}
|
||||
|
||||
printf("curr:::::::::::::::::::::::::::::::::::::\n");
|
||||
|
||||
printf("\t type: %d time: %llu diff: %llu\n", currTypes[0], currTimes[0] % 100000000, currTimes[0] - prevTimes[*prevN - 1]);
|
||||
for (int i = 1; i < *currN; i++) {
|
||||
printf("\t type: %d time: %llu diff: %llu\n", currTypes[i], currTimes[i] % 100000000, currTimes[i] - currTimes[i - 1]);
|
||||
}*/
|
||||
|
||||
diffsI[I++] = -2; // prev marker
|
||||
|
||||
typesI[I] = prevTypes[0];
|
||||
diffsI[I++] = prevTimes[0] - prevTime;
|
||||
for (int i = 1; i < *prevN; i++) {
|
||||
typesI[I] = prevTypes[i];
|
||||
diffsI[I++] = prevTimes[i] - prevTimes[i - 1];
|
||||
}
|
||||
|
||||
|
||||
diffsI[I++] = -1; // curr marker
|
||||
|
||||
typesI[I] = currTypes[0];
|
||||
diffsI[I++] = currTimes[0] - prevTimes[*prevN - 1];
|
||||
for (int i = 1; i < *currN; i++) {
|
||||
typesI[I] = currTypes[i];
|
||||
diffsI[I++] = currTimes[i] - currTimes[i - 1];
|
||||
}
|
||||
}
|
||||
|
||||
skew = 0;
|
||||
}
|
||||
|
|
|
@ -29,32 +29,6 @@ public slots:
|
|||
private:
|
||||
int _packetCount;
|
||||
int _byteCount;
|
||||
|
||||
public:
|
||||
// DEBUG
|
||||
|
||||
static int skewsI[];
|
||||
static int S;
|
||||
|
||||
static unsigned char typesI[];
|
||||
static int diffsI[];
|
||||
static int I;
|
||||
|
||||
|
||||
static quint64 prevTime;
|
||||
|
||||
static unsigned char typesA[];
|
||||
static quint64 timesA[];
|
||||
static int A;
|
||||
|
||||
static unsigned char typesB[];
|
||||
static quint64 timesB[];
|
||||
static int B;
|
||||
|
||||
|
||||
static unsigned char* currTypes, *prevTypes;
|
||||
static quint64* currTimes, *prevTimes;
|
||||
static int* currN, *prevN;
|
||||
};
|
||||
|
||||
#endif // hifi_DatagramProcessor_h
|
||||
|
|
|
@ -46,25 +46,5 @@ int main(int argc, const char * argv[]) {
|
|||
exitCode = app.exec();
|
||||
}
|
||||
qDebug("Normal exit.");
|
||||
|
||||
int s = 0;
|
||||
for (int i = 0; i < DatagramProcessor::I; i++) {
|
||||
|
||||
switch (DatagramProcessor::diffsI[i]) {
|
||||
case -2:
|
||||
printf("\nskew: %d\n", DatagramProcessor::skewsI[s++]);
|
||||
printf("prev:::::::::::::::::::::::::::::::\n");
|
||||
break;
|
||||
case -1:
|
||||
printf("curr:::::::::::::::::::::::::::::::\n");
|
||||
break;
|
||||
default:
|
||||
printf("\t type: %d diff: %d\n", DatagramProcessor::typesI[i], DatagramProcessor::diffsI[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
|
|
@ -172,11 +172,6 @@ quint64 end;
|
|||
|
||||
versionDebugSuppressMap.insert(senderUUID, checkType);
|
||||
}
|
||||
|
||||
|
||||
if ((end=usecTimestampNow()) - start > 100) {
|
||||
printf("\t\t\t\t version and hash match long diff: %d\n", end-start);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -187,11 +182,6 @@ quint64 end;
|
|||
if (sendingNode) {
|
||||
// check if the md5 hash in the header matches the hash we would expect
|
||||
if (hashFromPacketHeader(packet) == hashForPacketAndConnectionUUID(packet, sendingNode->getConnectionSecret())) {
|
||||
|
||||
if ((end = usecTimestampNow()) - start > 100) {
|
||||
printf("\t\t\t\t version and hash match long diff: %d\n", end - start);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
qDebug() << "Packet hash mismatch on" << checkType << "- Sender"
|
||||
|
@ -210,10 +200,6 @@ quint64 end;
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
if ((end = usecTimestampNow()) - start > 100) {
|
||||
printf("\t\t\t\t version and hash match long diff: %d\n", end - start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket,
|
|||
_isAlive(true),
|
||||
_clockSkewUsec(0),
|
||||
_mutex(),
|
||||
_clockSkewMovingPercentile(30, 0.8f) // moving upper quartile of 21 samples
|
||||
_clockSkewMovingPercentile(30, 0.8f) // moving 80th percentile of 30 samples
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -134,11 +134,9 @@ float Node::getAverageKilobitsPerSecond() {
|
|||
}
|
||||
}
|
||||
|
||||
void Node::setClockSkewUsec(int clockSkew) {
|
||||
_clockSkewMovingPercentile.updatePercentile((float)clockSkew);
|
||||
void Node::updateClockSkewUsec(int clockSkewSample) {
|
||||
_clockSkewMovingPercentile.updatePercentile((float)clockSkewSample);
|
||||
_clockSkewUsec = (int)_clockSkewMovingPercentile.getValueAtPercentile();
|
||||
|
||||
//_clockSkewUsec = clockSkew;
|
||||
}
|
||||
|
||||
QDataStream& operator<<(QDataStream& out, const Node& node) {
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
void setPingMs(int pingMs) { _pingMs = pingMs; }
|
||||
|
||||
int getClockSkewUsec() const { return _clockSkewUsec; }
|
||||
void setClockSkewUsec(int clockSkew);
|
||||
void updateClockSkewUsec(int clockSkewSample);
|
||||
QMutex& getMutex() { return _mutex; }
|
||||
|
||||
friend QDataStream& operator<<(QDataStream& out, const Node& node);
|
||||
|
@ -122,7 +122,6 @@ private:
|
|||
int _pingMs;
|
||||
int _clockSkewUsec;
|
||||
QMutex _mutex;
|
||||
|
||||
MovingPercentile _clockSkewMovingPercentile;
|
||||
};
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ qint64 NodeList::sendStatsToDomainServer(const QJsonObject& statsObject) {
|
|||
return writeUnverifiedDatagram(statsPacket, _domainHandler.getSockAddr());
|
||||
}
|
||||
|
||||
int NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode) {
|
||||
void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode) {
|
||||
QDataStream packetStream(packet);
|
||||
packetStream.skipRawData(numBytesForPacketHeader(packet));
|
||||
|
||||
|
@ -96,10 +96,7 @@ int NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& s
|
|||
int clockSkew = othersReplyTime - othersExprectedReply;
|
||||
|
||||
sendingNode->setPingMs(pingTime / 1000);
|
||||
sendingNode->setClockSkewUsec(clockSkew);
|
||||
|
||||
printf("\t\t clock skew sample: %d val at percentile: %d\n", clockSkew, sendingNode->getClockSkewUsec());
|
||||
|
||||
sendingNode->updateClockSkewUsec(clockSkew);
|
||||
|
||||
const bool wantDebug = false;
|
||||
|
||||
|
@ -113,14 +110,9 @@ printf("\t\t clock skew sample: %d val at percentile: %d\n", clockSkew, sending
|
|||
" othersExprectedReply: " << othersExprectedReply << "\n" <<
|
||||
" clockSkew: " << clockSkew;
|
||||
}
|
||||
|
||||
///if (abs(clockSkew) > 1000)
|
||||
//printf("clockskew = %d \n", clockSkew);
|
||||
|
||||
return clockSkew;
|
||||
}
|
||||
|
||||
int NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) {
|
||||
void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) {
|
||||
switch (packetTypeForPacket(packet)) {
|
||||
case PacketTypeDomainList: {
|
||||
processDomainServerList(packet);
|
||||
|
@ -160,8 +152,7 @@ int NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArr
|
|||
activateSocketFromNodeCommunication(packet, sendingNode);
|
||||
|
||||
// set the ping time for this node for stat collection
|
||||
return timePingReply(packet, sendingNode);
|
||||
|
||||
timePingReply(packet, sendingNode);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -176,7 +167,6 @@ int NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArr
|
|||
LimitedNodeList::processNodeData(senderSockAddr, packet);
|
||||
break;
|
||||
}
|
||||
return 1234567890;
|
||||
}
|
||||
|
||||
void NodeList::reset() {
|
||||
|
@ -489,11 +479,8 @@ QByteArray NodeList::constructPingReplyPacket(const QByteArray& pingPacket) {
|
|||
QByteArray replyPacket = byteArrayWithPopulatedHeader(PacketTypePingReply);
|
||||
QDataStream packetStream(&replyPacket, QIODevice::Append);
|
||||
|
||||
quint64 now;
|
||||
packetStream << typeFromOriginalPing << timeFromOriginalPing << (now = usecTimestampNow());
|
||||
packetStream << typeFromOriginalPing << timeFromOriginalPing << usecTimestampNow();
|
||||
|
||||
|
||||
printf("\n>>>>>>>> recv ping: %llu reply: %llu diff: %lld\n", timeFromOriginalPing, now, (qint64)now-(qint64)timeFromOriginalPing);
|
||||
return replyPacket;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
void addSetOfNodeTypesToNodeInterestSet(const NodeSet& setOfNodeTypes);
|
||||
void resetNodeInterestSet() { _nodeTypesOfInterest.clear(); }
|
||||
|
||||
int processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet);
|
||||
void processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet);
|
||||
|
||||
int processDomainServerList(const QByteArray& packet);
|
||||
|
||||
|
@ -95,7 +95,7 @@ private:
|
|||
void processDomainServerAuthRequest(const QByteArray& packet);
|
||||
void requestAuthForDomainServer();
|
||||
void activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode);
|
||||
int timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode);
|
||||
void timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode);
|
||||
|
||||
NodeType_t _ownerType;
|
||||
NodeSet _nodeTypesOfInterest;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "MovingPercentile.h"
|
||||
//#include "stdio.h"// DEBUG
|
||||
|
||||
MovingPercentile::MovingPercentile(int numSamples, float percentile)
|
||||
: _numSamples(numSamples),
|
||||
|
@ -19,14 +18,15 @@ MovingPercentile::~MovingPercentile() {
|
|||
|
||||
void MovingPercentile::updatePercentile(float sample) {
|
||||
|
||||
//printf("\nnew sample: %2.2f ", sample);
|
||||
// age all current samples by 1
|
||||
for (int i = 0; i < _numExistingSamples; i++) {
|
||||
_sampleAges[i]++;
|
||||
}
|
||||
|
||||
// find index in _samplesSorted to insert new sample.
|
||||
// if samples have not been filled yet, this will be the next empty spot
|
||||
// otherwise, it will be the spot of the oldest sample
|
||||
int newSampleIndex;
|
||||
if (_numExistingSamples < _numSamples) {
|
||||
|
||||
// if samples have not been filled yet, this will be the next empty spot
|
||||
newSampleIndex = _numExistingSamples;
|
||||
_numExistingSamples++;
|
||||
|
||||
|
@ -35,19 +35,9 @@ void MovingPercentile::updatePercentile(float sample) {
|
|||
_indexOfPercentile = (int)(index + 0.5f); // round to int
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < _numExistingSamples; i++) {
|
||||
if (_sampleAges[i] == _numExistingSamples - 1) {
|
||||
newSampleIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//printf("will be inserted at index %d\n", newSampleIndex);
|
||||
|
||||
// update _sampleAges to reflect new sample (age all samples by 1)
|
||||
for (int i = 0; i < _numExistingSamples; i++) {
|
||||
_sampleAges[i]++;
|
||||
// if samples have been filled, it will be the spot of the oldest sample
|
||||
newSampleIndex = 0;
|
||||
while (_sampleAges[newSampleIndex] != _numExistingSamples) { newSampleIndex++; }
|
||||
}
|
||||
|
||||
// insert new sample at that index
|
||||
|
@ -56,11 +46,8 @@ void MovingPercentile::updatePercentile(float sample) {
|
|||
|
||||
// swap new sample with neighboring elements in _samplesSorted until it's in sorted order
|
||||
// try swapping up first, then down. element will only be swapped one direction.
|
||||
|
||||
float neighborSample;
|
||||
while (newSampleIndex < _numExistingSamples-1 && sample > (neighborSample = _samplesSorted[newSampleIndex+1])) {
|
||||
//printf("\t swapping up...\n");
|
||||
_samplesSorted[newSampleIndex] = neighborSample;
|
||||
while (newSampleIndex < _numExistingSamples-1 && sample > _samplesSorted[newSampleIndex+1]) {
|
||||
_samplesSorted[newSampleIndex] = _samplesSorted[newSampleIndex + 1];
|
||||
_samplesSorted[newSampleIndex+1] = sample;
|
||||
|
||||
_sampleAges[newSampleIndex] = _sampleAges[newSampleIndex+1];
|
||||
|
@ -68,9 +55,8 @@ void MovingPercentile::updatePercentile(float sample) {
|
|||
|
||||
newSampleIndex++;
|
||||
}
|
||||
while (newSampleIndex > 0 && sample < (neighborSample = _samplesSorted[newSampleIndex - 1])) {
|
||||
//printf("\t swapping down...\n");
|
||||
_samplesSorted[newSampleIndex] = neighborSample;
|
||||
while (newSampleIndex > 0 && sample < _samplesSorted[newSampleIndex - 1]) {
|
||||
_samplesSorted[newSampleIndex] = _samplesSorted[newSampleIndex - 1];
|
||||
_samplesSorted[newSampleIndex - 1] = sample;
|
||||
|
||||
_sampleAges[newSampleIndex] = _sampleAges[newSampleIndex - 1];
|
||||
|
@ -81,13 +67,4 @@ void MovingPercentile::updatePercentile(float sample) {
|
|||
|
||||
// find new value at percentile
|
||||
_valueAtPercentile = _samplesSorted[_indexOfPercentile];
|
||||
/*
|
||||
printf(" new median: %f\n", _median);
|
||||
|
||||
// debug:
|
||||
for (int i = 0; i < _numExistingSamples; i++) {
|
||||
printf("%2.2f (%d), ", _samplesSorted[i], _sampleAges[i]);
|
||||
}
|
||||
printf("\n\n");
|
||||
*/
|
||||
}
|
|
@ -26,4 +26,4 @@ private:
|
|||
int _indexOfPercentile;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue