From fc07ecf83dfa8bb835195a725ce4718b01c2bbc1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 31 Jan 2015 20:40:18 -0800 Subject: [PATCH] use BandwidthRecorder rather than recompute Mbps and pps in Application --- interface/src/Application.cpp | 16 ++++++++-------- interface/src/Application.h | 16 ++++++++-------- interface/src/ui/ApplicationOverlay.cpp | 9 +++++---- interface/src/ui/Stats.cpp | 8 ++++---- interface/src/ui/Stats.h | 2 +- libraries/networking/src/BandwidthRecorder.h | 4 ++-- libraries/networking/src/LimitedNodeList.cpp | 8 ++++---- 7 files changed, 32 insertions(+), 31 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c984df5707..f1aa0ee873 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -241,10 +241,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _mousePressed(false), _enableProcessOctreeThread(true), _octreeProcessor(), - _inPacketsPerSecond(0), - _outPacketsPerSecond(0), - _inBytesPerSecond(0), - _outBytesPerSecond(0), +// _inPacketsPerSecond(0), +// _outPacketsPerSecond(0), +// _inBytesPerSecond(0), +// _outBytesPerSecond(0), _nodeBoundsDisplay(this), _previousScriptLocation(), _applicationOverlay(), @@ -1380,10 +1380,10 @@ void Application::timer() { _fps = (float)_frameCount / diffTime; - _inPacketsPerSecond = (float) _datagramProcessor.getInPacketCount() / diffTime; - _outPacketsPerSecond = (float) _datagramProcessor.getOutPacketCount() / diffTime; - _inBytesPerSecond = (float) _datagramProcessor.getInByteCount() / diffTime; - _outBytesPerSecond = (float) _datagramProcessor.getOutByteCount() / diffTime; + // _inPacketsPerSecond = (float) _datagramProcessor.getInPacketCount() / diffTime; + // _outPacketsPerSecond = (float) _datagramProcessor.getOutPacketCount() / diffTime; + // _inBytesPerSecond = (float) _datagramProcessor.getInByteCount() / diffTime; + // _outBytesPerSecond = (float) _datagramProcessor.getOutByteCount() / diffTime; _frameCount = 0; _datagramProcessor.resetCounters(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 7ac05d668b..510843758b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -208,10 +208,10 @@ public: Overlays& getOverlays() { return _overlays; } float getFps() const { return _fps; } - float getInPacketsPerSecond() const { return _inPacketsPerSecond; } - float getOutPacketsPerSecond() const { return _outPacketsPerSecond; } - float getInBytesPerSecond() const { return _inBytesPerSecond; } - float getOutBytesPerSecond() const { return _outBytesPerSecond; } + // float getInPacketsPerSecond() const { return _inPacketsPerSecond; } + // float getOutPacketsPerSecond() const { return _outPacketsPerSecond; } + // float getInBytesPerSecond() const { return _inBytesPerSecond; } + // float getOutBytesPerSecond() const { return _outBytesPerSecond; } const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; } void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; } @@ -535,10 +535,10 @@ private: OctreePacketProcessor _octreeProcessor; EntityEditPacketSender _entityEditSender; - int _inPacketsPerSecond; - int _outPacketsPerSecond; - int _inBytesPerSecond; - int _outBytesPerSecond; + // int _inPacketsPerSecond; + // int _outPacketsPerSecond; + // int _inBytesPerSecond; + // int _outBytesPerSecond; StDev _idleLoopStdev; float _idleLoopMeasuredJitter; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2daa22ebdd..93dd64879b 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -904,6 +904,7 @@ void ApplicationOverlay::renderAudioMeter() { void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); + BandwidthRecorder* bandwidthRecorder = Application::getInstance()->getBandwidthRecorder(); auto glCanvas = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); @@ -919,10 +920,10 @@ void ApplicationOverlay::renderStatsAndLogs() { int voxelPacketsToProcess = octreePacketProcessor.packetsToProcessCount(); // Onscreen text about position, servers, etc Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), - application->getInPacketsPerSecond(), - application->getOutPacketsPerSecond(), - application->getInBytesPerSecond(), - application->getOutBytesPerSecond(), + bandwidthRecorder->totalChannel->getAverageInputPacketsPerSecond(), + bandwidthRecorder->totalChannel->getAverageOutputPacketsPerSecond(), + bandwidthRecorder->totalChannel->getAverageInputKilobitsPerSecond(), + bandwidthRecorder->totalChannel->getAverageOutputKilobitsPerSecond(), voxelPacketsToProcess); } diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 0416bf31ed..c248140ae3 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -201,8 +201,8 @@ void Stats::display( float fps, int inPacketsPerSecond, int outPacketsPerSecond, - int inBytesPerSecond, - int outBytesPerSecond, + int inKbitsPerSecond, + int outKbitsPerSecond, int voxelPacketsToProcess) { auto glCanvas = DependencyManager::get(); @@ -318,8 +318,8 @@ void Stats::display( sprintf(packetsPerSecondString, "Packets In/Out: %d/%d", inPacketsPerSecond, outPacketsPerSecond); char averageMegabitsPerSecond[30]; sprintf(averageMegabitsPerSecond, "Mbps In/Out: %3.2f/%3.2f", - (float)inBytesPerSecond * 8.0f / 1000000.0f, - (float)outBytesPerSecond * 8.0f / 1000000.0f); + (float)inKbitsPerSecond * 1.0f / 1000.0f, + (float)outKbitsPerSecond * 1.0f / 1000.0f); verticalOffset += STATS_PELS_PER_LINE; drawText(horizontalOffset, verticalOffset, scale, rotation, font, packetsPerSecondString, color); diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h index 136baf448b..d6da8d8cc6 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -30,7 +30,7 @@ public: void checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseDragStartedY, int horizontalOffset); void resetWidth(int width, int horizontalOffset); void display(const float* color, int horizontalOffset, float fps, int inPacketsPerSecond, int outPacketsPerSecond, - int inBytesPerSecond, int outBytesPerSecond, int voxelPacketsToProcess); + int inKbitsPerSecond, int outKbitsPerSecond, int voxelPacketsToProcess); bool includeTimingRecord(const QString& name); Q_INVOKABLE void setMetavoxelStats(int internal, int leaves, int sendProgress, diff --git a/libraries/networking/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h index 6f0ccf2c04..5ae5de813f 100644 --- a/libraries/networking/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -52,8 +52,8 @@ class BandwidthRecorder : public QObject { unsigned colorRGBA; private: - SimpleMovingAverage _input; - SimpleMovingAverage _output; + SimpleMovingAverage _input = SimpleMovingAverage(1000); + SimpleMovingAverage _output = SimpleMovingAverage(1000); }; // create the channels we keep track of diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 666424151c..7d188af6aa 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -47,8 +47,8 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short _localSockAddr(), _publicSockAddr(), _stunSockAddr(STUN_SERVER_HOSTNAME, STUN_SERVER_PORT), - _numCollectedPackets(0), - _numCollectedBytes(0), + // _numCollectedPackets(0), + // _numCollectedBytes(0), _packetStatTimer() { static bool firstCall = true; @@ -234,8 +234,8 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSock } // stat collection for packets - ++_numCollectedPackets; - _numCollectedBytes += datagram.size(); + // ++_numCollectedPackets; + // _numCollectedBytes += datagram.size(); qint64 bytesWritten = _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr.getAddress(), destinationSockAddr.getPort());