ping reporter added to interface

This commit is contained in:
Mark Peng 2013-06-28 11:07:01 -07:00
parent d38389fc13
commit c5fe8b078e
11 changed files with 102842 additions and 3 deletions

View file

@ -398,6 +398,10 @@ int main(int argc, const char* argv[]) {
// give the new audio data to the matching injector agent // give the new audio data to the matching injector agent
agentList->updateAgentWithData(matchingInjector, packetData, receivedBytes); agentList->updateAgentWithData(matchingInjector, packetData, receivedBytes);
} else if (packetData[0] == PACKET_HEADER_PING) {
// If the packet is a ping, let processAgentData handle it.
agentList->processAgentData(agentAddress, packetData, receivedBytes);
} }
} }

50000
avatar-mixer/cachedStars.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -93,6 +93,7 @@ int main(int argc, const char* argv[]) {
} }
if (agentList->getAgentSocket()->receive(agentAddress, packetData, &receivedBytes)) { if (agentList->getAgentSocket()->receive(agentAddress, packetData, &receivedBytes)) {
switch (packetData[0]) { switch (packetData[0]) {
case PACKET_HEADER_HEAD_DATA: case PACKET_HEADER_HEAD_DATA:
// grab the agent ID from the packet // grab the agent ID from the packet

50000
interface/cachedStars.txt Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -161,7 +161,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_packetCount(0), _packetCount(0),
_packetsPerSecond(0), _packetsPerSecond(0),
_bytesPerSecond(0), _bytesPerSecond(0),
_bytesCount(0) _bytesCount(0),
_pingSentTime(0)
{ {
_applicationStartupTime = startup_time; _applicationStartupTime = startup_time;
_window->setWindowTitle("Interface"); _window->setWindowTitle("Interface");
@ -759,9 +760,23 @@ void Application::wheelEvent(QWheelEvent* event) {
} }
} }
void sendPingPacket() {
char agentTypesOfInterest[] = {'V', 'M', 'W'};
char pingPacket[1 + sizeof(long long)];
pingPacket[0] = PACKET_HEADER_PING;
long long currTime = usecTimestampNow();
memcpy(&pingPacket[1], &currTime, sizeof(long long));
AgentList::getInstance()->broadcastToAgents((unsigned char*)&pingPacket, 1 + sizeof(long long), agentTypesOfInterest, 3);
}
// Every second, check the frame rates and other stuff // Every second, check the frame rates and other stuff
void Application::timer() { void Application::timer() {
gettimeofday(&_timerEnd, NULL); gettimeofday(&_timerEnd, NULL);
_pingSentTime = usecTimestampNow();
sendPingPacket();
_fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); _fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
_packetsPerSecond = (float)_packetCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); _packetsPerSecond = (float)_packetCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
_bytesPerSecond = (float)_bytesCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); _bytesPerSecond = (float)_bytesCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
@ -2150,6 +2165,23 @@ void Application::displayOverlay() {
glPopMatrix(); glPopMatrix();
} }
void Application::getPing(long long &pingAudio, long long &pingAvatar, long long &pingVoxel) {
AgentList *agentList = AgentList::getInstance();
for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
const char *agentType = agent->getTypeName();
long long pingTime = agent->getPingTime();
if (strcmp(agentType, "Audio Mixer") == 0) {
pingAudio = pingTime / 1000;
}
if (strcmp(agentType, "Avatar Mixer") == 0) {
pingAvatar = pingTime / 1000;
}
if (strcmp(agentType, "Voxel Server") == 0) {
pingVoxel = pingTime / 1000;
}
}
}
void Application::displayStats() { void Application::displayStats() {
int statsVerticalOffset = 8; int statsVerticalOffset = 8;
@ -2157,6 +2189,13 @@ void Application::displayStats() {
sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps", sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps",
_fps, _packetsPerSecond, (float)_bytesPerSecond * 8.f / 1000000.f); _fps, _packetsPerSecond, (float)_bytesPerSecond * 8.f / 1000000.f);
drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats); drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats);
long long pingAudio = 0, pingAvatar = 0, pingVoxel = 0;
getPing(pingAudio, pingAvatar, pingVoxel);
char pingStats[200];
sprintf(pingStats, "Ping audio/avatar/voxel: %lld / %lld / %lld ", pingAudio, pingAvatar, pingVoxel);
drawtext(10, statsVerticalOffset + 35, 0.10f, 0, 1.0, 0, pingStats);
std::stringstream voxelStats; std::stringstream voxelStats;
voxelStats.precision(4); voxelStats.precision(4);

View file

@ -81,6 +81,7 @@ public:
private slots: private slots:
void getPing(long long &pingAudio, long long &pingAvatar, long long &pingVoxel);
void timer(); void timer();
void idle(); void idle();
void terminate(); void terminate();
@ -221,6 +222,7 @@ private:
timeval _applicationStartupTime; timeval _applicationStartupTime;
timeval _timerStart, _timerEnd; timeval _timerStart, _timerEnd;
timeval _lastTimeIdle; timeval _lastTimeIdle;
long long _pingSentTime;
bool _justStarted; bool _justStarted;
Stars _stars; Stars _stars;
@ -305,6 +307,7 @@ private:
int _packetsPerSecond; int _packetsPerSecond;
int _bytesPerSecond; int _bytesPerSecond;
int _bytesCount; int _bytesCount;
}; };
#endif /* defined(__interface__Application__) */ #endif /* defined(__interface__Application__) */

View file

@ -63,6 +63,9 @@ public:
float getAverageKilobitsPerSecond(); float getAverageKilobitsPerSecond();
float getAveragePacketsPerSecond(); float getAveragePacketsPerSecond();
long long getPingTime() { return _pingTime; };
void setPingTime(long long pingTime) { _pingTime = pingTime; };
static void printLog(Agent const&); static void printLog(Agent const&);
private: private:
// privatize copy and assignment operator to disallow Agent copying // privatize copy and assignment operator to disallow Agent copying
@ -79,6 +82,7 @@ private:
SimpleMovingAverage* _bytesReceivedMovingAverage; SimpleMovingAverage* _bytesReceivedMovingAverage;
AgentData* _linkedData; AgentData* _linkedData;
bool _isAlive; bool _isAlive;
long long _pingTime;
}; };

View file

@ -77,6 +77,20 @@ AgentList::~AgentList() {
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex);
} }
void AgentList::timePingReply(sockaddr *agentAddress, unsigned char *packetData) {
char pingPacket[1 + sizeof(long long)];
memcpy(pingPacket, packetData, 1 + sizeof(long long));
for(AgentList::iterator agent = begin(); agent != end(); agent++) {
if (socketMatch(agent->getPublicSocket(), agentAddress) ||
socketMatch(agent->getLocalSocket(), agentAddress)) {
long long pingTime = usecTimestampNow() - *(long long *)(pingPacket+1);
agent->setPingTime(pingTime);
break;
}
}
}
void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) { void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes) {
switch (((char *)packetData)[0]) { switch (((char *)packetData)[0]) {
case PACKET_HEADER_DOMAIN: { case PACKET_HEADER_DOMAIN: {
@ -84,11 +98,15 @@ void AgentList::processAgentData(sockaddr *senderAddress, unsigned char *packetD
break; break;
} }
case PACKET_HEADER_PING: { case PACKET_HEADER_PING: {
_agentSocket.send(senderAddress, &PACKET_HEADER_PING_REPLY, 1); char pingPacket[1 + sizeof(long long)];
memcpy(pingPacket, packetData, 1 + sizeof(long long));
pingPacket[0] = PACKET_HEADER_PING_REPLY;
_agentSocket.send(senderAddress, pingPacket, 1 + sizeof(long long));
break; break;
} }
case PACKET_HEADER_PING_REPLY: { case PACKET_HEADER_PING_REPLY: {
handlePingReply(senderAddress); // handlePingReply(senderAddress);
timePingReply(senderAddress, packetData);
break; break;
} }
} }

View file

@ -49,6 +49,7 @@ public:
AgentListIterator end() const; AgentListIterator end() const;
char getOwnerType() const { return _ownerType; } char getOwnerType() const { return _ownerType; }
char *getAgentTypesOfInterest() const { return _agentTypesOfInterest; }
uint16_t getLastAgentID() const { return _lastAgentID; } uint16_t getLastAgentID() const { return _lastAgentID; }
void increaseAgentID() { ++_lastAgentID; } void increaseAgentID() { ++_lastAgentID; }
@ -116,6 +117,7 @@ private:
pthread_mutex_t mutex; pthread_mutex_t mutex;
void handlePingReply(sockaddr *agentAddress); void handlePingReply(sockaddr *agentAddress);
void timePingReply(sockaddr *agentAddress, unsigned char *packetData);
}; };
class AgentListIterator : public std::iterator<std::input_iterator_tag, Agent> { class AgentListIterator : public std::iterator<std::input_iterator_tag, Agent> {

View file

@ -706,6 +706,10 @@ int main(int argc, const char * argv[]) {
agentList->updateAgentWithData(agent, packetData, receivedBytes); agentList->updateAgentWithData(agent, packetData, receivedBytes);
} }
// If the packet is a ping, let processAgentData handle it.
if (packetData[0] == PACKET_HEADER_PING) {
agentList->processAgentData(&agentPublicAddress, packetData, receivedBytes);
}
} }
} }