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
bool isReceivedFileSizeValid();
//! Return expected file size
size_t getExpectedFileSize() { return m_expectedFileSize; }
//@}
// IScreen overrides

View File

@ -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;
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;
};

View File

@ -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:

View File

@ -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();
}