From 811cfd146d8f5147f29e9567e6e3e23599a3ff68 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Fri, 26 Jul 2013 12:44:14 +0000 Subject: [PATCH] Patch by Jerry: - Measure file transfer speed - Increased quit timeout in NetworkTests - Some code duplication, to be fixed in future patch --- src/lib/client/CClient.h | 3 +++ src/lib/client/CServerProxy.cpp | 36 ++++++++++++++++++++++++---- src/lib/client/CServerProxy.h | 6 +++++ src/lib/server/CClientProxy1_5.cpp | 36 ++++++++++++++++++++++++---- src/lib/server/CClientProxy1_5.h | 6 +++++ src/lib/server/CServer.h | 3 +++ src/test/integtests/NetworkTests.cpp | 8 +++---- 7 files changed, 86 insertions(+), 12 deletions(-) diff --git a/src/lib/client/CClient.h b/src/lib/client/CClient.h index 030e64b7..5d93143d 100644 --- a/src/lib/client/CClient.h +++ b/src/lib/client/CClient.h @@ -131,6 +131,9 @@ public: //! Return true if recieved file size is valid bool isReceivedFileSizeValid(); + //! Return expected file size + size_t getExpectedFileSize() { return m_expectedFileSize; } + //@} // IScreen overrides diff --git a/src/lib/client/CServerProxy.cpp b/src/lib/client/CServerProxy.cpp index c8475cb6..deea22f5 100644 --- a/src/lib/client/CServerProxy.cpp +++ b/src/lib/client/CServerProxy.cpp @@ -35,6 +35,8 @@ // CServerProxy // +const UInt16 CServerProxy::m_intervalThreshold = 1; + CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue* events) : m_client(client), m_stream(stream), @@ -49,7 +51,10 @@ CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueu m_keepAliveAlarm(0.0), m_keepAliveAlarmTimer(NULL), m_parser(&CServerProxy::parseHandshakeMessage), - m_events(events) + m_events(events), + m_stopwatch(true), + m_elapsedTime(0), + m_receivedDataSize(0) { assert(m_client != NULL); assert(m_stream != NULL); @@ -945,19 +950,42 @@ CServerProxy::fileChunkReceived() switch (mark) { case kFileStart: - LOG((CLOG_DEBUG2 "recv file data from server: size=%s", content.c_str())); m_client->clearReceivedFileData(); m_client->setExpectedFileSize(content); + if (CLOG->getFilter() >= kDEBUG2) { + LOG((CLOG_DEBUG2 "recv file data from server: size=%s", content.c_str())); + m_stopwatch.start(); + } break; case kFileChunk: - LOG((CLOG_DEBUG2 "recv file data from server: size=%i", content.size())); m_client->fileChunkReceived(content); + if (CLOG->getFilter() >= kDEBUG2) { + LOG((CLOG_DEBUG2 "recv file data from server: size=%i", content.size())); + double interval = m_stopwatch.getTime(); + LOG((CLOG_DEBUG2 "recv file data from server: interval=%f s", interval)); + m_receivedDataSize += content.size(); + if (interval >= m_intervalThreshold) { + double averageSpeed = m_receivedDataSize / interval / 1000; + LOG((CLOG_DEBUG2 "recv file data from server: average speed=%f kb/s", averageSpeed)); + + m_receivedDataSize = 0; + m_elapsedTime += interval; + m_stopwatch.reset(); + } + } break; case kFileEnd: - LOG((CLOG_DEBUG2 "file data transfer finished")); m_events->addEvent(CEvent(m_events->forIScreen().fileRecieveComplete(), m_client)); + if (CLOG->getFilter() >= kDEBUG2) { + LOG((CLOG_DEBUG2 "file data transfer finished")); + m_elapsedTime += m_stopwatch.getTime(); + double averageSpeed = m_client->getExpectedFileSize() / m_elapsedTime / 1000; + LOG((CLOG_DEBUG2 "file data transfer finished: total time consumed=%f s", m_elapsedTime)); + LOG((CLOG_DEBUG2 "file data transfer finished: total data received=%i kb", m_client->getExpectedFileSize() / 1000)); + LOG((CLOG_DEBUG2 "file data transfer finished: total average speed=%f kb/s", averageSpeed)); + } break; } } diff --git a/src/lib/client/CServerProxy.h b/src/lib/client/CServerProxy.h index 74255fa8..ea4adcb4 100644 --- a/src/lib/client/CServerProxy.h +++ b/src/lib/client/CServerProxy.h @@ -23,6 +23,7 @@ #include "KeyTypes.h" #include "CEvent.h" #include "GameDeviceTypes.h" +#include "CStopwatch.h" class CClient; class CClientInfo; @@ -137,6 +138,11 @@ private: MessageParser m_parser; IEventQueue* m_events; + + CStopwatch m_stopwatch; + double m_elapsedTime; + size_t m_receivedDataSize; + static const UInt16 m_intervalThreshold; }; #endif diff --git a/src/lib/server/CClientProxy1_5.cpp b/src/lib/server/CClientProxy1_5.cpp index 0fdd7d8a..a1d07a83 100644 --- a/src/lib/server/CClientProxy1_5.cpp +++ b/src/lib/server/CClientProxy1_5.cpp @@ -25,9 +25,14 @@ // CClientProxy1_5 // +const UInt16 CClientProxy1_5::m_intervalThreshold = 1; + CClientProxy1_5::CClientProxy1_5(const CString& name, synergy::IStream* stream, CServer* server, IEventQueue* events) : CClientProxy1_4(name, stream, server, events), - m_events(events) + m_events(events), + m_stopwatch(true), + m_elapsedTime(0), + m_receivedDataSize(0) { } @@ -81,19 +86,42 @@ CClientProxy1_5::fileChunkReceived() CServer* server = getServer(); switch (mark) { case kFileStart: - LOG((CLOG_DEBUG2 "recv file data from client: file size=%s", content.c_str())); server->clearReceivedFileData(); server->setExpectedFileSize(content); + if (CLOG->getFilter() >= kDEBUG2) { + LOG((CLOG_DEBUG2 "recv file data from client: file size=%s", content.c_str())); + m_stopwatch.start(); + } break; case kFileChunk: - LOG((CLOG_DEBUG2 "recv file data from client: chunck size=%i", content.size())); server->fileChunkReceived(content); + if (CLOG->getFilter() >= kDEBUG2) { + LOG((CLOG_DEBUG2 "recv file data from client: chunck size=%i", content.size())); + double interval = m_stopwatch.getTime(); + m_receivedDataSize += content.size(); + LOG((CLOG_DEBUG2 "recv file data from client: interval=%f s", interval)); + if (interval >= m_intervalThreshold) { + double averageSpeed = m_receivedDataSize / interval / 1000; + LOG((CLOG_DEBUG2 "recv file data from client: average speed=%f kb/s", averageSpeed)); + + m_receivedDataSize = 0; + m_elapsedTime += interval; + m_stopwatch.reset(); + } + } break; case kFileEnd: - LOG((CLOG_DEBUG2 "file data transfer finished")); m_events->addEvent(CEvent(m_events->forIScreen().fileRecieveComplete(), server)); + if (CLOG->getFilter() >= kDEBUG2) { + LOG((CLOG_DEBUG2 "file data transfer finished")); + m_elapsedTime += m_stopwatch.getTime(); + double averageSpeed = getServer()->getExpectedFileSize() / m_elapsedTime / 1000; + LOG((CLOG_DEBUG2 "file data transfer finished: total time consumed=%f s", m_elapsedTime)); + LOG((CLOG_DEBUG2 "file data transfer finished: total data received=%i kb", getServer()->getExpectedFileSize() / 1000)); + LOG((CLOG_DEBUG2 "file data transfer finished: total average speed=%f kb/s", averageSpeed)); + } break; } } diff --git a/src/lib/server/CClientProxy1_5.h b/src/lib/server/CClientProxy1_5.h index 65ae94d2..7a26baef 100644 --- a/src/lib/server/CClientProxy1_5.h +++ b/src/lib/server/CClientProxy1_5.h @@ -18,6 +18,7 @@ #pragma once #include "CClientProxy1_4.h" +#include "CStopwatch.h" class CServer; class IEventQueue; @@ -34,4 +35,9 @@ public: private: IEventQueue* m_events; + + CStopwatch m_stopwatch; + double m_elapsedTime; + size_t m_receivedDataSize; + static const UInt16 m_intervalThreshold; }; diff --git a/src/lib/server/CServer.h b/src/lib/server/CServer.h index c848f317..da4edbeb 100644 --- a/src/lib/server/CServer.h +++ b/src/lib/server/CServer.h @@ -178,6 +178,9 @@ public: //! Return true if recieved file size is valid bool isReceivedFileSizeValid(); + //! Return expected file size + size_t getExpectedFileSize() { return m_expectedFileSize; } + //@} private: diff --git a/src/test/integtests/NetworkTests.cpp b/src/test/integtests/NetworkTests.cpp index 4b173a13..7d55b296 100644 --- a/src/test/integtests/NetworkTests.cpp +++ b/src/test/integtests/NetworkTests.cpp @@ -149,7 +149,7 @@ TEST_F(NetworkTests, sendToClient_mockData) client.connect(); - m_events.initQuitTimeout(5); + m_events.initQuitTimeout(10); m_events.loop(); m_events.cleanupQuitTimeout(); } @@ -200,7 +200,7 @@ TEST_F(NetworkTests, sendToClient_mockFile) client.connect(); - m_events.initQuitTimeout(5); + m_events.initQuitTimeout(10); m_events.loop(); m_events.cleanupQuitTimeout(); } @@ -251,7 +251,7 @@ TEST_F(NetworkTests, sendToServer_mockData) client.connect(); - m_events.initQuitTimeout(5); + m_events.initQuitTimeout(10); m_events.loop(); m_events.cleanupQuitTimeout(); } @@ -302,7 +302,7 @@ TEST_F(NetworkTests, sendToServer_mockFile) client.connect(); - m_events.initQuitTimeout(5); + m_events.initQuitTimeout(10); m_events.loop(); m_events.cleanupQuitTimeout(); }