Converted double timestamps to long long (64 bit integers), fixed bug with

updating agent timestamps.
This commit is contained in:
Andrzej Kapolka 2013-06-13 11:11:59 -07:00
parent 677c2eed39
commit db729a04aa
18 changed files with 99 additions and 100 deletions

View file

@ -644,14 +644,14 @@ void* animateVoxels(void* args) {
sendDanceFloor();
}
double end = usecTimestampNow();
double elapsedSeconds = (end - ::start) / 1000000.0;
long long end = usecTimestampNow();
long long elapsedSeconds = (end - ::start) / 1000000;
if (::shouldShowPacketsPerSecond) {
printf("packetsSent=%ld, bytesSent=%ld pps=%f bps=%f\n",packetsSent,bytesSent,
(float)(packetsSent/elapsedSeconds),(float)(bytesSent/elapsedSeconds));
}
// dynamically sleep until we need to fire off the next set of voxels
double usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
long long usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
if (usecToSleep > 0) {
usleep(usecToSleep);

View file

@ -318,7 +318,7 @@ int main(int argc, const char* argv[]) {
}
}
double usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow();
long long usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow();
if (usecToSleep > 0) {
usleep(usecToSleep);

View file

@ -133,37 +133,26 @@ int main(int argc, const char * argv[])
if (numInterestTypes > 0) {
// if the agent has sent no types of interest, assume they want nothing but their own ID back
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType)) {
if (memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) {
// this is not the agent themselves
// and this is an agent of a type in the passed agent types of interest
// or the agent did not pass us any specific types they are interested in
if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) {
// this is an agent of which there can be multiple, just add them to the packet
// don't send avatar agents to other avatars, that will come from avatar mixer
if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) {
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent));
}
} else {
// solo agent, we need to only send newest
if (newestSoloAgents[agent->getType()] == NULL ||
newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) {
// we have to set the newer solo agent to add it to the broadcast later
newestSoloAgents[agent->getType()] = &(*agent);
}
if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType) &&
memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) {
// this is not the agent themselves
// and this is an agent of a type in the passed agent types of interest
// or the agent did not pass us any specific types they are interested in
if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) {
// this is an agent of which there can be multiple, just add them to the packet
// don't send avatar agents to other avatars, that will come from avatar mixer
if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) {
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent));
}
}
} else {
double timeNow = usecTimestampNow();
// this is the agent, just update last receive to now
agent->setLastHeardMicrostamp(timeNow);
if (packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY
&& memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) {
agent->setWakeMicrostamp(timeNow);
} else {
// solo agent, we need to only send newest
if (newestSoloAgents[agent->getType()] == NULL ||
newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) {
// we have to set the newer solo agent to add it to the broadcast later
newestSoloAgents[agent->getType()] = &(*agent);
}
}
}
}
@ -175,6 +164,15 @@ int main(int argc, const char * argv[])
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, soloAgent->second);
}
}
// update last receive to now
long long timeNow = usecTimestampNow();
newAgent->setLastHeardMicrostamp(timeNow);
if (packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY
&& memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) {
newAgent->setWakeMicrostamp(timeNow);
}
// add the agent ID to the end of the pointer
currentBufferPos += packAgentId(currentBufferPos, newAgent->getAgentID());

View file

@ -128,7 +128,7 @@ int main(int argc, const char* argv[]) {
broadcastPacket[0] = PACKET_HEADER_HEAD_DATA;
timeval thisSend;
double numMicrosecondsSleep = 0;
long long numMicrosecondsSleep = 0;
int handStateTimer = 0;
@ -212,4 +212,4 @@ int main(int argc, const char* argv[]) {
// stop the agent list's threads
agentList->stopPingUnknownAgentsThread();
agentList->stopSilentAgentRemovalThread();
}
}

View file

@ -187,7 +187,7 @@ int main(int argc, char* argv[]) {
unsigned char broadcastPacket = PACKET_HEADER_INJECT_AUDIO;
timeval thisSend;
double numMicrosecondsSleep = 0;
long long numMicrosecondsSleep = 0;
timeval lastDomainServerCheckIn = {};

View file

@ -2078,9 +2078,8 @@ void Application::displayOverlay() {
// Show on-screen msec timer
if (_renderFrameTimerOn->isChecked()) {
char frameTimer[10];
double mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5);
mSecsNow = mSecsNow - floor(mSecsNow / 1000.0) * 1000.0;
sprintf(frameTimer, "%3.0f\n", mSecsNow);
long long mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5);
sprintf(frameTimer, "%d\n", (int)(mSecsNow % 1000));
drawtext(_glWidget->width() - 100, _glWidget->height() - 20, 0.30, 0, 1.0, 0, frameTimer, 0, 0, 0);
drawtext(_glWidget->width() - 102, _glWidget->height() - 22, 0.30, 0, 1.0, 0, frameTimer, 1, 1, 1);
}

View file

@ -165,15 +165,15 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
void VoxelSystem::setupNewVoxelsForDrawing() {
PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated
double start = usecTimestampNow();
double sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000.0;
long long start = usecTimestampNow();
long long sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;
bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging
if (!iAmDebugging && sinceLastTime <= std::max(_setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {
return; // bail early, it hasn't been long enough since the last time we ran
}
double sinceLastViewCulling = (start - _lastViewCulling) / 1000.0;
long long sinceLastViewCulling = (start - _lastViewCulling) / 1000;
// If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view
if ((sinceLastViewCulling >= std::max(_lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS))
&& !isViewChanging() && hasViewChanged()) {
@ -189,8 +189,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
// VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary.
cleanupRemovedVoxels();
double endViewCulling = usecTimestampNow();
_lastViewCullingElapsed = (endViewCulling - start) / 1000.0;
long long endViewCulling = usecTimestampNow();
_lastViewCullingElapsed = (endViewCulling - start) / 1000;
}
bool didWriteFullVBO = _writeRenderFullVBO;
@ -226,8 +226,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
pthread_mutex_unlock(&_bufferWriteLock);
double end = usecTimestampNow();
double elapsedmsec = (end - start) / 1000.0;
long long end = usecTimestampNow();
long long elapsedmsec = (end - start) / 1000;
_setupNewVoxelsForDrawingLastFinished = end;
_setupNewVoxelsForDrawingLastElapsed = elapsedmsec;
}

View file

@ -115,7 +115,7 @@ void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destination
injectorSocket->send(destinationSocket, dataPacket, sizeof(dataPacket));
double usecToSleep = usecTimestamp(&startTime) + (++nextFrame * INJECT_INTERVAL_USECS) - usecTimestampNow();
long long usecToSleep = usecTimestamp(&startTime) + (++nextFrame * INJECT_INTERVAL_USECS) - usecTimestampNow();
if (usecToSleep > 0) {
usleep(usecToSleep);
}

View file

@ -6,6 +6,8 @@
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include "stdio.h"
#include <pthread.h>
#include "Agent.h"
#include "AgentTypes.h"

View file

@ -37,11 +37,11 @@ public:
uint16_t getAgentID() const { return _agentID; }
void setAgentID(uint16_t agentID) { _agentID = agentID;}
double getWakeMicrostamp() const { return _wakeMicrostamp; }
void setWakeMicrostamp(double wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; }
long long getWakeMicrostamp() const { return _wakeMicrostamp; }
void setWakeMicrostamp(long long wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; }
double getLastHeardMicrostamp() const { return _lastHeardMicrostamp; }
void setLastHeardMicrostamp(double lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; }
long long getLastHeardMicrostamp() const { return _lastHeardMicrostamp; }
void setLastHeardMicrostamp(long long lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; }
sockaddr* getPublicSocket() const { return _publicSocket; }
void setPublicSocket(sockaddr* publicSocket) { _publicSocket = publicSocket; }
@ -71,8 +71,8 @@ private:
char _type;
uint16_t _agentID;
double _wakeMicrostamp;
double _lastHeardMicrostamp;
long long _wakeMicrostamp;
long long _lastHeardMicrostamp;
sockaddr* _publicSocket;
sockaddr* _localSocket;
sockaddr* _activeSocket;

View file

@ -392,7 +392,7 @@ void *pingUnknownAgents(void *args) {
}
}
double usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend));
long long usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend));
if (usecToSleep > 0) {
usleep(usecToSleep);
@ -413,7 +413,7 @@ void AgentList::stopPingUnknownAgentsThread() {
void *removeSilentAgents(void *args) {
AgentList* agentList = (AgentList*) args;
double checkTimeUSecs, sleepTime;
long long checkTimeUSecs, sleepTime;
while (!silentAgentThreadStopFlag) {
checkTimeUSecs = usecTimestampNow();
@ -422,7 +422,7 @@ void *removeSilentAgents(void *args) {
if ((checkTimeUSecs - agent->getLastHeardMicrostamp()) > AGENT_SILENCE_THRESHOLD_USECS
&& agent->getType() != AGENT_TYPE_VOXEL_SERVER) {
printLog("Killed ");
Agent::printLog(*agent);

View file

@ -104,7 +104,7 @@ int PerfStat::DumpStats(char** array) {
// Destructor handles recording all of our stats
PerformanceWarning::~PerformanceWarning() {
double end = usecTimestampNow();
long long end = usecTimestampNow();
double elapsedmsec = (end - _start) / 1000.0;
if ((_alwaysDisplay || _renderWarningsOn) && elapsedmsec > 1) {
if (elapsedmsec > 1000) {

View file

@ -84,7 +84,7 @@ typedef std::map<std::string,PerfStatHistory,std::less<std::string> >::iterator
class PerformanceWarning {
private:
double _start;
long long _start;
const char* _message;
bool _renderWarningsOn;
bool _alwaysDisplay;

View file

@ -22,14 +22,14 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
double usecTimestamp(timeval *time) {
return (time->tv_sec * 1000000.0 + time->tv_usec);
long long usecTimestamp(timeval *time) {
return (time->tv_sec * 1000000 + time->tv_usec);
}
double usecTimestampNow() {
long long usecTimestampNow() {
timeval now;
gettimeofday(&now, NULL);
return (now.tv_sec * 1000000.0 + now.tv_usec);
return (now.tv_sec * 1000000 + now.tv_usec);
}
float randFloat () {

View file

@ -36,8 +36,8 @@ static const float DECIMETER = 0.1f;
static const float CENTIMETER = 0.01f;
static const float MILLIIMETER = 0.001f;
double usecTimestamp(timeval *time);
double usecTimestampNow();
long long usecTimestamp(timeval *time);
long long usecTimestampNow();
float randFloat();
int randIntInRange (int min, int max);

View file

@ -25,7 +25,7 @@ public:
float getAverageSampleValuePerSecond();
private:
int _numSamples;
double _lastEventTimestamp;
long long _lastEventTimestamp;
float _average;
float _eventDeltaAverage;

View file

@ -29,7 +29,7 @@ private:
#endif
glBufferIndex _glBufferIndex;
bool _isDirty;
double _lastChanged;
long long _lastChanged;
bool _shouldRender;
bool _isStagedForDeletion;
AABox _box;
@ -80,7 +80,7 @@ public:
void printDebugDetails(const char* label) const;
bool isDirty() const { return _isDirty; };
void clearDirtyBit() { _isDirty = false; };
bool hasChangedSince(double time) const { return (_lastChanged > time); };
bool hasChangedSince(long long time) const { return (_lastChanged > time); };
void markWithChangedTime() { _lastChanged = usecTimestampNow(); };
void handleSubtreeChanged(VoxelTree* myTree);

View file

@ -32,7 +32,7 @@
const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo";
const char* VOXELS_PERSIST_FILE = "/etc/highfidelity/voxel-server/resources/voxels.svo";
const double VOXEL_PERSIST_INTERVAL = 1000.0 * 30; // every 30 seconds
const long long VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
const int VOXEL_LISTEN_PORT = 40106;
@ -118,7 +118,7 @@ void resInVoxelDistributor(AgentList* agentList,
bool searchReset = false;
int searchLoops = 0;
int searchLevelWas = agentData->getMaxSearchLevel();
double start = usecTimestampNow();
long long start = usecTimestampNow();
while (!searchReset && agentData->nodeBag.isEmpty()) {
searchLoops++;
@ -137,19 +137,19 @@ void resInVoxelDistributor(AgentList* agentList,
}
}
}
double end = usecTimestampNow();
double elapsedmsec = (end - start)/1000.0;
long long end = usecTimestampNow();
int elapsedmsec = (end - start)/1000;
if (elapsedmsec > 100) {
if (elapsedmsec > 1000) {
double elapsedsec = (end - start)/1000000.0;
printf("WARNING! searchForColoredNodes() took %lf seconds to identify %d nodes at level %d in %d loops\n",
int elapsedsec = (end - start)/1000000;
printf("WARNING! searchForColoredNodes() took %d seconds to identify %d nodes at level %d in %d loops\n",
elapsedsec, agentData->nodeBag.count(), searchLevelWas, searchLoops);
} else {
printf("WARNING! searchForColoredNodes() took %lf milliseconds to identify %d nodes at level %d in %d loops\n",
printf("WARNING! searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d in %d loops\n",
elapsedmsec, agentData->nodeBag.count(), searchLevelWas, searchLoops);
}
} else if (::debugVoxelSending) {
printf("searchForColoredNodes() took %lf milliseconds to identify %d nodes at level %d in %d loops\n",
printf("searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d in %d loops\n",
elapsedmsec, agentData->nodeBag.count(), searchLevelWas, searchLoops);
}
@ -161,7 +161,7 @@ void resInVoxelDistributor(AgentList* agentList,
int packetsSentThisInterval = 0;
int truePacketsSent = 0;
int trueBytesSent = 0;
double start = usecTimestampNow();
long long start = usecTimestampNow();
bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS);
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) {
@ -206,19 +206,19 @@ void resInVoxelDistributor(AgentList* agentList,
trueBytesSent += envPacketLength;
truePacketsSent++;
}
double end = usecTimestampNow();
double elapsedmsec = (end - start)/1000.0;
long long end = usecTimestampNow();
int elapsedmsec = (end - start)/1000;
if (elapsedmsec > 100) {
if (elapsedmsec > 1000) {
double elapsedsec = (end - start)/1000000.0;
printf("WARNING! packetLoop() took %lf seconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n",
int elapsedsec = (end - start)/1000000;
printf("WARNING! packetLoop() took %d seconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n",
elapsedsec, trueBytesSent, truePacketsSent, searchLevelWas, agentData->nodeBag.count());
} else {
printf("WARNING! packetLoop() took %lf milliseconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n",
printf("WARNING! packetLoop() took %d milliseconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n",
elapsedmsec, trueBytesSent, truePacketsSent, searchLevelWas, agentData->nodeBag.count());
}
} else if (::debugVoxelSending) {
printf("packetLoop() took %lf milliseconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n",
printf("packetLoop() took %d milliseconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n",
elapsedmsec, trueBytesSent, truePacketsSent, searchLevelWas, agentData->nodeBag.count());
}
@ -245,7 +245,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
pthread_mutex_lock(&::treeLock);
int maxLevelReached = 0;
double start = usecTimestampNow();
long long start = usecTimestampNow();
// FOR NOW... agent tells us if it wants to receive only view frustum deltas
bool wantDelta = agentData->getWantDelta();
@ -281,19 +281,19 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
}
}
double end = usecTimestampNow();
double elapsedmsec = (end - start)/1000.0;
long long end = usecTimestampNow();
int elapsedmsec = (end - start)/1000;
if (elapsedmsec > 100) {
if (elapsedmsec > 1000) {
double elapsedsec = (end - start)/1000000.0;
printf("WARNING! searchForColoredNodes() took %lf seconds to identify %d nodes at level %d\n",
int elapsedsec = (end - start)/1000000;
printf("WARNING! searchForColoredNodes() took %d seconds to identify %d nodes at level %d\n",
elapsedsec, agentData->nodeBag.count(), maxLevelReached);
} else {
printf("WARNING! searchForColoredNodes() took %lf milliseconds to identify %d nodes at level %d\n",
printf("WARNING! searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d\n",
elapsedmsec, agentData->nodeBag.count(), maxLevelReached);
}
} else if (::debugVoxelSending) {
printf("searchForColoredNodes() took %lf milliseconds to identify %d nodes at level %d\n",
printf("searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d\n",
elapsedmsec, agentData->nodeBag.count(), maxLevelReached);
}
@ -304,7 +304,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
int packetsSentThisInterval = 0;
int truePacketsSent = 0;
int trueBytesSent = 0;
double start = usecTimestampNow();
long long start = usecTimestampNow();
bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS);
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) {
@ -351,19 +351,19 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
truePacketsSent++;
}
double end = usecTimestampNow();
double elapsedmsec = (end - start)/1000.0;
long long end = usecTimestampNow();
int elapsedmsec = (end - start)/1000;
if (elapsedmsec > 100) {
if (elapsedmsec > 1000) {
double elapsedsec = (end - start)/1000000.0;
printf("WARNING! packetLoop() took %lf seconds to generate %d bytes in %d packets %d nodes still to send\n",
int elapsedsec = (end - start)/1000000;
printf("WARNING! packetLoop() took %d seconds to generate %d bytes in %d packets %d nodes still to send\n",
elapsedsec, trueBytesSent, truePacketsSent, agentData->nodeBag.count());
} else {
printf("WARNING! packetLoop() took %lf milliseconds to generate %d bytes in %d packets, %d nodes still to send\n",
printf("WARNING! packetLoop() took %d milliseconds to generate %d bytes in %d packets, %d nodes still to send\n",
elapsedmsec, trueBytesSent, truePacketsSent, agentData->nodeBag.count());
}
} else if (::debugVoxelSending) {
printf("packetLoop() took %lf milliseconds to generate %d bytes in %d packets, %d nodes still to send\n",
printf("packetLoop() took %d milliseconds to generate %d bytes in %d packets, %d nodes still to send\n",
elapsedmsec, trueBytesSent, truePacketsSent, agentData->nodeBag.count());
}
@ -380,10 +380,10 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
pthread_mutex_unlock(&::treeLock);
}
double lastPersistVoxels = 0;
long long lastPersistVoxels = 0;
void persistVoxelsWhenDirty() {
double now = usecTimestampNow();
double sinceLastTime = (now - ::lastPersistVoxels) / 1000.0;
long long now = usecTimestampNow();
long long sinceLastTime = (now - ::lastPersistVoxels) / 1000;
// check the dirty bit and persist here...
if (::wantVoxelPersist && ::serverTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) {
@ -428,7 +428,7 @@ void *distributeVoxelsToListeners(void *args) {
}
// dynamically sleep until we need to fire off the next set of voxels
double usecToSleep = VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
long long usecToSleep = VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
if (usecToSleep > 0) {
usleep(usecToSleep);