void CClient::updateStat () { // write each pong in a file string ha = Address.hostName(); if (ha.empty()) { ha = Address.ipAddress(); } string fn = StatPathName + ConnectionName + "_" + ha + "_" + getDate() + ".stat"; string line; line += "NbPing " + toString(NbPing) + " "; line += "NbPong " + toString(NbPong) + " "; if (NbPong == 0) line += "MeanPongTime <Undef> "; else line += "MeanPongTime " + toString(MeanPongTime/NbPong) + " "; line += "NbDuplicated " + toString(NbDuplicated) + " "; FILE *fp = fopen (fn.c_str(), "at"); if (fp == NULL) { nlwarning ("Can't open stat file name '%s'", fn.c_str()); } else { if (FirstWrite) { //nlassert (!Address.hostName().empty()) fprintf (fp, "HostAddress: %s\n", Address.asString().c_str()); FirstWrite = false; } fprintf (fp, "%s\n", line.c_str()); fclose (fp); } nlinfo (line.c_str()); CMessage msgout("INFO"); msgout.serial(line); CallbackServer->send (msgout, From); NbPing = NbPong = MeanPongTime = NbDuplicated = 0; }
void CClient::updateFullStat () { uint32 NbLost = 0, NbDup = 0, NbPong = 0; /* if (Address.hostName().empty()) { // don't log because we receive no pong at all return; }*/ for (uint i = 0; i < LastPongReceived; i++) { if (PongReceived[i].first == 0) NbLost++; else { NbPong++; NbDup += PongReceived[i].first - 1; } } { // write each pong in a file string ha = Address.hostName(); if (ha.empty()) { ha = Address.ipAddress(); } string fn = StatPathName + ConnectionName + "_" + ha + "_" + getDate() + ".stat"; string line = "Full Summary: "; line += "NbPing " + toString(LastPongReceived) + " "; line += "NbPong " + toString(NbPong) + " "; line += "NbLost " + toString(NbLost) + " "; if (LastPongReceived>0) line += "(" + toString((float)NbLost/LastPongReceived*100.0f) + "pc) "; line += "NbDuplicated " + toString(NbDup) + " "; if (LastPongReceived>0) line += "(" + toString((float)NbDup/LastPongReceived*100.0f) + "pc) "; if (FullNbPong == 0) line += "MeanPongTime <Undef> "; else line += "MeanPongTime " + toString(FullMeanPongTime/FullNbPong) + " "; FILE *fp = fopen (fn.c_str(), "at"); if (fp == NULL) { nlwarning ("Can't open stat file name '%s'", fn.c_str()); } else { fprintf (fp, "%s\n", line.c_str()); fclose (fp); // send the full sumary to the client CMessage msgout("INFO"); msgout.serial(line); CallbackServer->send (msgout, From); } nlinfo (line.c_str()); } { // write each ping in a file string ha = Address.hostName(); if (ha.empty()) { ha = Address.ipAddress(); } string fn = StatPathName + ConnectionName + "_" + ha + "_" + getDate() + ".ping"; FILE *fp = fopen (fn.c_str(), "rt"); if (fp == NULL) { // new file, add the header FILE *fp = fopen (fn.c_str(), "wt"); if (fp != NULL) { fprintf (fp, "#%s\t%s\n", "NbPongRcv", "Delta"); fclose (fp); } } else { fclose (fp); } fp = fopen (fn.c_str(), "at"); if (fp == NULL) { nlwarning ("Can't open ping file name '%s'", fn.c_str()); } else { // add a fake value to know that it s a different session fprintf (fp, "-1\t0\n"); for (uint i = 0; i < LastPongReceived; i++) { fprintf (fp, "%d\t%d\n", PongReceived[i].first, PongReceived[i].second); } fclose (fp); } } // clear all structures PongReceived.clear (); PongReceived.resize (1001); BlockNumber++; NextPingNumber = LastPongReceived = 0; FullMeanPongTime = FullNbPong = 0; // NbPing = NbPong = MeanPongTime = NbDuplicated = 0; }
void CClient::updatePong (sint64 pingTime, sint64 pongTime, uint32 pongNumber, uint32 blockNumber) { // it means that it s a too old packet, discard it if (blockNumber != BlockNumber) return; // add the pong in the array to detect lost, duplication if (pongNumber >= PongReceived.size()) { // if the array is too big, we flush actual data and restart all updateFullStat (); return; } PongReceived[pongNumber].first++; if (PongReceived[pongNumber].first > 1) { NbDuplicated++; } else { // increase only for new pong NbPong++; MeanPongTime += (uint32)(pongTime-pingTime); FullNbPong++; FullMeanPongTime += (uint32)(pongTime-pingTime); PongReceived[pongNumber].second = (uint16)(pongTime - pingTime); } if (pongNumber > LastPongReceived) LastPongReceived = pongNumber; // write each pong in a file string ha = Address.hostName(); if (ha.empty()) { ha = Address.ipAddress(); } string fn = StatPathName + ConnectionName + "_" + ha + "_" + getDate() + ".pong"; FILE *fp = fopen (fn.c_str(), "rt"); if (fp == NULL) { // new file, add the header FILE *fp = fopen (fn.c_str(), "wt"); if (fp != NULL) { fprintf (fp, "#%s\t%s\t%s\t%s\n", "PingTime", "PongTime", "Delta", "PingNumber"); fclose (fp); } } else { fclose (fp); } fp = fopen (fn.c_str(), "at"); if (fp == NULL) { nlwarning ("Can't open pong file name '%s'", fn.c_str()); } else { fprintf (fp, "%"NL_I64"d\t%"NL_I64"d\t%"NL_I64"d\t%d\n", pongTime, pingTime, (pongTime-pingTime), pongNumber); fclose (fp); } }