switch usec timestamps to uint64_t

This commit is contained in:
Stephen Birarda 2013-07-10 11:46:48 -07:00
parent 9ba3bfc8b8
commit ca8f25955a
20 changed files with 58 additions and 57 deletions

View file

@ -643,14 +643,14 @@ void* animateVoxels(void* args) {
sendDanceFloor();
}
long long end = usecTimestampNow();
long long elapsedSeconds = (end - ::start) / 1000000;
uint64_t end = usecTimestampNow();
int 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
long long usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
uint64_t usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
if (usecToSleep > 0) {
usleep(usecToSleep);

View file

@ -47,7 +47,7 @@ const unsigned short MIXER_LISTEN_PORT = 55443;
const short JITTER_BUFFER_MSECS = 12;
const short JITTER_BUFFER_SAMPLES = JITTER_BUFFER_MSECS * (SAMPLE_RATE / 1000.0);
const long long BUFFER_SEND_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SAMPLE_RATE) * 1000000);
const unsigned int BUFFER_SEND_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SAMPLE_RATE) * 1000000);
const long MAX_SAMPLE_VALUE = std::numeric_limits<int16_t>::max();
const long MIN_SAMPLE_VALUE = std::numeric_limits<int16_t>::min();
@ -412,7 +412,7 @@ int main(int argc, const char* argv[]) {
numStatCollections++;
}
long long usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow();
int usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow();
if (usecToSleep > 0) {
usleep(usecToSleep);

View file

@ -159,7 +159,7 @@ int main(int argc, const char * argv[])
}
// update last receive to now
long long timeNow = usecTimestampNow();
uint64_t timeNow = usecTimestampNow();
newNode->setLastHeardMicrostamp(timeNow);
if (packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY

View file

@ -128,7 +128,7 @@ int main(int argc, const char* argv[]) {
broadcastPacket[0] = PACKET_HEADER_HEAD_DATA;
timeval thisSend;
long long numMicrosecondsSleep = 0;
int numMicrosecondsSleep = 0;
int handStateTimer = 0;

View file

@ -903,7 +903,7 @@ void Application::wheelEvent(QWheelEvent* event) {
void Application::sendPingPackets() {
char nodeTypesOfInterest[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER};
long long currentTime = usecTimestampNow();
uint64_t currentTime = usecTimestampNow();
unsigned char pingPacket[1 + sizeof(currentTime)];
pingPacket[0] = PACKET_HEADER_PING;
@ -2429,7 +2429,7 @@ void Application::displayOverlay() {
// Show on-screen msec timer
if (_renderFrameTimerOn->isChecked()) {
char frameTimer[10];
long long mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5);
uint64_t 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

@ -168,15 +168,15 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
void VoxelSystem::setupNewVoxelsForDrawing() {
PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated
long long start = usecTimestampNow();
long long sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;
uint64_t start = usecTimestampNow();
int 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
}
long long sinceLastViewCulling = (start - _lastViewCulling) / 1000;
int 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()) {
@ -192,7 +192,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
// VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary.
cleanupRemovedVoxels();
long long endViewCulling = usecTimestampNow();
uint64_t endViewCulling = usecTimestampNow();
_lastViewCullingElapsed = (endViewCulling - start) / 1000;
}
@ -229,8 +229,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
pthread_mutex_unlock(&_bufferWriteLock);
long long end = usecTimestampNow();
long long elapsedmsec = (end - start) / 1000;
uint64_t end = usecTimestampNow();
int elapsedmsec = (end - start) / 1000;
_setupNewVoxelsForDrawingLastFinished = end;
_setupNewVoxelsForDrawingLastElapsed = elapsedmsec;
}

View file

@ -191,8 +191,8 @@ void Webcam::setFrame(const Mat& frame, int format, const Mat& depth, const Rota
const int MAX_FPS = 60;
const int MIN_FRAME_DELAY = 1000000 / MAX_FPS;
long long now = usecTimestampNow();
long long remaining = MIN_FRAME_DELAY;
uint64_t now = usecTimestampNow();
int remaining = MIN_FRAME_DELAY;
if (_startTimestamp == 0) {
_startTimestamp = now;
} else {

View file

@ -73,10 +73,10 @@ private:
cv::RotatedRect _initialFaceRect;
JointVector _joints;
long long _startTimestamp;
uint64_t _startTimestamp;
int _frameCount;
long long _lastFrameTimestamp;
uint64_t _lastFrameTimestamp;
glm::vec3 _estimatedPosition;
glm::vec3 _estimatedRotation;

View file

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

View file

@ -21,7 +21,7 @@ const int STREAM_IDENTIFIER_NUM_BYTES = 8;
const int MAX_INJECTOR_VOLUME = 0xFF;
const long long INJECT_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SAMPLE_RATE) * 1000000);
const int INJECT_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SAMPLE_RATE) * 1000000);
class AudioInjector {
public:

View file

@ -37,11 +37,11 @@ public:
uint16_t getNodeID() const { return _nodeID; }
void setNodeID(uint16_t nodeID) { _nodeID = nodeID;}
long long getWakeMicrostamp() const { return _wakeMicrostamp; }
void setWakeMicrostamp(long long wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; }
uint64_t getWakeMicrostamp() const { return _wakeMicrostamp; }
void setWakeMicrostamp(uint64_t wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; }
long long getLastHeardMicrostamp() const { return _lastHeardMicrostamp; }
void setLastHeardMicrostamp(long long lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; }
uint64_t getLastHeardMicrostamp() const { return _lastHeardMicrostamp; }
void setLastHeardMicrostamp(uint64_t lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; }
sockaddr* getPublicSocket() const { return _publicSocket; }
void setPublicSocket(sockaddr* publicSocket) { _publicSocket = publicSocket; }
@ -74,8 +74,8 @@ private:
char _type;
uint16_t _nodeID;
long long _wakeMicrostamp;
long long _lastHeardMicrostamp;
uint64_t _wakeMicrostamp;
uint64_t _lastHeardMicrostamp;
sockaddr* _publicSocket;
sockaddr* _localSocket;
sockaddr* _activeSocket;

View file

@ -81,7 +81,7 @@ void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
for(NodeList::iterator node = begin(); node != end(); node++) {
if (socketMatch(node->getPublicSocket(), nodeAddress) ||
socketMatch(node->getLocalSocket(), nodeAddress)) {
int pingTime = usecTimestampNow() - *(long long *)(packetData + 1);
int pingTime = usecTimestampNow() - *(uint64_t *)(packetData + 1);
node->setPingMs(pingTime / 1000);
break;
}
@ -422,7 +422,7 @@ void *pingUnknownNodes(void *args) {
}
}
long long usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend));
int usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend));
if (usecToSleep > 0) {
usleep(usecToSleep);
@ -443,7 +443,8 @@ void NodeList::stopPingUnknownNodesThread() {
void *removeSilentNodes(void *args) {
NodeList* nodeList = (NodeList*) args;
long long checkTimeUSecs, sleepTime;
uint64_t checkTimeUSecs;
int sleepTime;
while (!silentNodeThreadStopFlag) {
checkTimeUSecs = usecTimestampNow();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -29,7 +29,7 @@ private:
#endif
glBufferIndex _glBufferIndex;
bool _isDirty;
long long _lastChanged;
uint64_t _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(long long time) const { return (_lastChanged > time); };
bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); };
void markWithChangedTime() { _lastChanged = usecTimestampNow(); };
void handleSubtreeChanged(VoxelTree* myTree);

View file

@ -50,8 +50,8 @@ public:
bool getViewSent() const { return _viewSent; };
void setViewSent(bool viewSent) { _viewSent = viewSent; }
long long getLastTimeBagEmpty() const { return _lastTimeBagEmpty; };
void setLastTimeBagEmpty(long long lastTimeBagEmpty) { _lastTimeBagEmpty = lastTimeBagEmpty; };
uint64_t getLastTimeBagEmpty() const { return _lastTimeBagEmpty; };
void setLastTimeBagEmpty(uint64_t lastTimeBagEmpty) { _lastTimeBagEmpty = lastTimeBagEmpty; };
private:
@ -67,7 +67,7 @@ private:
int _maxLevelReachedInLastSearch;
ViewFrustum _currentViewFrustum;
ViewFrustum _lastKnownViewFrustum;
long long _lastTimeBagEmpty;
uint64_t _lastTimeBagEmpty;
};

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 long long VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
const int VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
const int VOXEL_LISTEN_PORT = 40106;
@ -119,7 +119,7 @@ void resInVoxelDistributor(NodeList* nodeList,
bool searchReset = false;
int searchLoops = 0;
int searchLevelWas = nodeData->getMaxSearchLevel();
long long start = usecTimestampNow();
uint64_t start = usecTimestampNow();
while (!searchReset && nodeData->nodeBag.isEmpty()) {
searchLoops++;
@ -138,7 +138,7 @@ void resInVoxelDistributor(NodeList* nodeList,
}
}
}
long long end = usecTimestampNow();
uint64_t end = usecTimestampNow();
int elapsedmsec = (end - start)/1000;
if (elapsedmsec > 100) {
if (elapsedmsec > 1000) {
@ -162,7 +162,7 @@ void resInVoxelDistributor(NodeList* nodeList,
int packetsSentThisInterval = 0;
int truePacketsSent = 0;
int trueBytesSent = 0;
long long start = usecTimestampNow();
uint64_t start = usecTimestampNow();
bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS);
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) {
@ -209,7 +209,7 @@ void resInVoxelDistributor(NodeList* nodeList,
trueBytesSent += envPacketLength;
truePacketsSent++;
}
long long end = usecTimestampNow();
uint64_t end = usecTimestampNow();
int elapsedmsec = (end - start)/1000;
if (elapsedmsec > 100) {
if (elapsedmsec > 1000) {
@ -248,7 +248,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
pthread_mutex_lock(&::treeLock);
int maxLevelReached = 0;
long long start = usecTimestampNow();
uint64_t start = usecTimestampNow();
// FOR NOW... node tells us if it wants to receive only view frustum deltas
bool wantDelta = nodeData->getWantDelta();
@ -267,7 +267,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
if (::debugVoxelSending) {
printf("(viewFrustumChanged=%s || nodeData->nodeBag.isEmpty() =%s)...\n",
debug::valueOf(viewFrustumChanged), debug::valueOf(nodeData->nodeBag.isEmpty()));
long long now = usecTimestampNow();
uint64_t now = usecTimestampNow();
if (nodeData->getLastTimeBagEmpty() > 0) {
float elapsedSceneSend = (now - nodeData->getLastTimeBagEmpty()) / 1000000.0f;
@ -306,7 +306,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
}
}
long long end = usecTimestampNow();
uint64_t end = usecTimestampNow();
int elapsedmsec = (end - start)/1000;
if (elapsedmsec > 100) {
if (elapsedmsec > 1000) {
@ -329,12 +329,12 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
int packetsSentThisInterval = 0;
int truePacketsSent = 0;
int trueBytesSent = 0;
long long start = usecTimestampNow();
uint64_t start = usecTimestampNow();
bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS);
while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) {
// Check to see if we're taking too long, and if so bail early...
long long now = usecTimestampNow();
uint64_t now = usecTimestampNow();
long elapsedUsec = (now - start);
long elapsedUsecPerPacket = (truePacketsSent == 0) ? 0 : (elapsedUsec / truePacketsSent);
long usecRemaining = (VOXEL_SEND_INTERVAL_USECS - elapsedUsec);
@ -396,7 +396,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
truePacketsSent++;
}
long long end = usecTimestampNow();
uint64_t end = usecTimestampNow();
int elapsedmsec = (end - start)/1000;
if (elapsedmsec > 100) {
if (elapsedmsec > 1000) {
@ -425,10 +425,10 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
pthread_mutex_unlock(&::treeLock);
}
long long lastPersistVoxels = 0;
uint64_t lastPersistVoxels = 0;
void persistVoxelsWhenDirty() {
long long now = usecTimestampNow();
long long sinceLastTime = (now - ::lastPersistVoxels) / 1000;
uint64_t now = usecTimestampNow();
int sinceLastTime = (now - ::lastPersistVoxels) / 1000;
// check the dirty bit and persist here...
if (::wantVoxelPersist && ::serverTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) {
@ -473,7 +473,7 @@ void *distributeVoxelsToListeners(void *args) {
}
// dynamically sleep until we need to fire off the next set of voxels
long long usecToSleep = VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
int usecToSleep = VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
if (usecToSleep > 0) {
usleep(usecToSleep);