Patch by Jerry:

- Measure file transfer speed
- Increased quit timeout in NetworkTests
- Some code duplication, to be fixed in future patch
This commit is contained in:
Nick Bolton 2013-07-26 12:44:14 +00:00
parent 99a7e0db23
commit 811cfd146d
7 changed files with 86 additions and 12 deletions

View File

@ -131,6 +131,9 @@ public:
//! Return true if recieved file size is valid //! Return true if recieved file size is valid
bool isReceivedFileSizeValid(); bool isReceivedFileSizeValid();
//! Return expected file size
size_t getExpectedFileSize() { return m_expectedFileSize; }
//@} //@}
// IScreen overrides // IScreen overrides

View File

@ -35,6 +35,8 @@
// CServerProxy // CServerProxy
// //
const UInt16 CServerProxy::m_intervalThreshold = 1;
CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue* events) : CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue* events) :
m_client(client), m_client(client),
m_stream(stream), m_stream(stream),
@ -49,7 +51,10 @@ CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueu
m_keepAliveAlarm(0.0), m_keepAliveAlarm(0.0),
m_keepAliveAlarmTimer(NULL), m_keepAliveAlarmTimer(NULL),
m_parser(&CServerProxy::parseHandshakeMessage), 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_client != NULL);
assert(m_stream != NULL); assert(m_stream != NULL);
@ -945,19 +950,42 @@ CServerProxy::fileChunkReceived()
switch (mark) { switch (mark) {
case kFileStart: case kFileStart:
LOG((CLOG_DEBUG2 "recv file data from server: size=%s", content.c_str()));
m_client->clearReceivedFileData(); m_client->clearReceivedFileData();
m_client->setExpectedFileSize(content); 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; break;
case kFileChunk: case kFileChunk:
LOG((CLOG_DEBUG2 "recv file data from server: size=%i", content.size()));
m_client->fileChunkReceived(content); 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; break;
case kFileEnd: case kFileEnd:
LOG((CLOG_DEBUG2 "file data transfer finished"));
m_events->addEvent(CEvent(m_events->forIScreen().fileRecieveComplete(), m_client)); 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; break;
} }
} }

View File

@ -23,6 +23,7 @@
#include "KeyTypes.h" #include "KeyTypes.h"
#include "CEvent.h" #include "CEvent.h"
#include "GameDeviceTypes.h" #include "GameDeviceTypes.h"
#include "CStopwatch.h"
class CClient; class CClient;
class CClientInfo; class CClientInfo;
@ -137,6 +138,11 @@ private:
MessageParser m_parser; MessageParser m_parser;
IEventQueue* m_events; IEventQueue* m_events;
CStopwatch m_stopwatch;
double m_elapsedTime;
size_t m_receivedDataSize;
static const UInt16 m_intervalThreshold;
}; };
#endif #endif

View File

@ -25,9 +25,14 @@
// CClientProxy1_5 // CClientProxy1_5
// //
const UInt16 CClientProxy1_5::m_intervalThreshold = 1;
CClientProxy1_5::CClientProxy1_5(const CString& name, synergy::IStream* stream, CServer* server, IEventQueue* events) : CClientProxy1_5::CClientProxy1_5(const CString& name, synergy::IStream* stream, CServer* server, IEventQueue* events) :
CClientProxy1_4(name, stream, server, 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(); CServer* server = getServer();
switch (mark) { switch (mark) {
case kFileStart: case kFileStart:
LOG((CLOG_DEBUG2 "recv file data from client: file size=%s", content.c_str()));
server->clearReceivedFileData(); server->clearReceivedFileData();
server->setExpectedFileSize(content); 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; break;
case kFileChunk: case kFileChunk:
LOG((CLOG_DEBUG2 "recv file data from client: chunck size=%i", content.size()));
server->fileChunkReceived(content); 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; break;
case kFileEnd: case kFileEnd:
LOG((CLOG_DEBUG2 "file data transfer finished"));
m_events->addEvent(CEvent(m_events->forIScreen().fileRecieveComplete(), server)); 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; break;
} }
} }

View File

@ -18,6 +18,7 @@
#pragma once #pragma once
#include "CClientProxy1_4.h" #include "CClientProxy1_4.h"
#include "CStopwatch.h"
class CServer; class CServer;
class IEventQueue; class IEventQueue;
@ -34,4 +35,9 @@ public:
private: private:
IEventQueue* m_events; IEventQueue* m_events;
CStopwatch m_stopwatch;
double m_elapsedTime;
size_t m_receivedDataSize;
static const UInt16 m_intervalThreshold;
}; };

View File

@ -178,6 +178,9 @@ public:
//! Return true if recieved file size is valid //! Return true if recieved file size is valid
bool isReceivedFileSizeValid(); bool isReceivedFileSizeValid();
//! Return expected file size
size_t getExpectedFileSize() { return m_expectedFileSize; }
//@} //@}
private: private:

View File

@ -149,7 +149,7 @@ TEST_F(NetworkTests, sendToClient_mockData)
client.connect(); client.connect();
m_events.initQuitTimeout(5); m_events.initQuitTimeout(10);
m_events.loop(); m_events.loop();
m_events.cleanupQuitTimeout(); m_events.cleanupQuitTimeout();
} }
@ -200,7 +200,7 @@ TEST_F(NetworkTests, sendToClient_mockFile)
client.connect(); client.connect();
m_events.initQuitTimeout(5); m_events.initQuitTimeout(10);
m_events.loop(); m_events.loop();
m_events.cleanupQuitTimeout(); m_events.cleanupQuitTimeout();
} }
@ -251,7 +251,7 @@ TEST_F(NetworkTests, sendToServer_mockData)
client.connect(); client.connect();
m_events.initQuitTimeout(5); m_events.initQuitTimeout(10);
m_events.loop(); m_events.loop();
m_events.cleanupQuitTimeout(); m_events.cleanupQuitTimeout();
} }
@ -302,7 +302,7 @@ TEST_F(NetworkTests, sendToServer_mockFile)
client.connect(); client.connect();
m_events.initQuitTimeout(5); m_events.initQuitTimeout(10);
m_events.loop(); m_events.loop();
m_events.cleanupQuitTimeout(); m_events.cleanupQuitTimeout();
} }