Merge pull request #7303 from jherico/watchdog

Update the watchdog heartbeat manually during startup
This commit is contained in:
Chris Collins 2016-03-09 19:11:30 -08:00
commit f98b6c3a28

View file

@ -250,9 +250,9 @@ public:
setObjectName("Deadlock Watchdog"); setObjectName("Deadlock Watchdog");
QTimer* heartbeatTimer = new QTimer(); QTimer* heartbeatTimer = new QTimer();
// Give the heartbeat an initial value // Give the heartbeat an initial value
_heartbeat = usecTimestampNow(); updateHeartbeat();
connect(heartbeatTimer, &QTimer::timeout, [this] { connect(heartbeatTimer, &QTimer::timeout, [this] {
_heartbeat = usecTimestampNow(); updateHeartbeat();
}); });
heartbeatTimer->start(HEARTBEAT_UPDATE_INTERVAL_SECS * MSECS_PER_SECOND); heartbeatTimer->start(HEARTBEAT_UPDATE_INTERVAL_SECS * MSECS_PER_SECOND);
connect(qApp, &QCoreApplication::aboutToQuit, [this] { connect(qApp, &QCoreApplication::aboutToQuit, [this] {
@ -260,6 +260,10 @@ public:
}); });
} }
void updateHeartbeat() {
_heartbeat = usecTimestampNow();
}
void deadlockDetectionCrash() { void deadlockDetectionCrash() {
uint32_t* crashTrigger = nullptr; uint32_t* crashTrigger = nullptr;
*crashTrigger = 0xDEAD10CC; *crashTrigger = 0xDEAD10CC;
@ -505,7 +509,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
// Set up a watchdog thread to intentionally crash the application on deadlocks // Set up a watchdog thread to intentionally crash the application on deadlocks
(new DeadlockWatchdogThread())->start(); auto deadlockWatchdog = new DeadlockWatchdogThread();
deadlockWatchdog->start();
qCDebug(interfaceapp) << "[VERSION] Build sequence:" << qPrintable(applicationVersion()); qCDebug(interfaceapp) << "[VERSION] Build sequence:" << qPrintable(applicationVersion());
@ -539,7 +544,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
audioThread->setObjectName("Audio Thread"); audioThread->setObjectName("Audio Thread");
auto audioIO = DependencyManager::get<AudioClient>(); auto audioIO = DependencyManager::get<AudioClient>();
audioIO->setPositionGetter([this]{ return getMyAvatar()->getPositionForAudio(); }); audioIO->setPositionGetter([this]{ return getMyAvatar()->getPositionForAudio(); });
audioIO->setOrientationGetter([this]{ return getMyAvatar()->getOrientationForAudio(); }); audioIO->setOrientationGetter([this]{ return getMyAvatar()->getOrientationForAudio(); });
@ -557,7 +561,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
}); });
auto& audioScriptingInterface = AudioScriptingInterface::getInstance(); auto& audioScriptingInterface = AudioScriptingInterface::getInstance();
connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start); connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit); connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater); connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
@ -580,6 +583,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
audioThread->start(); audioThread->start();
ResourceManager::init(); ResourceManager::init();
// Make sure we don't time out during slow operations at startup
deadlockWatchdog->updateHeartbeat();
// Setup MessagesClient // Setup MessagesClient
auto messagesClient = DependencyManager::get<MessagesClient>(); auto messagesClient = DependencyManager::get<MessagesClient>();
@ -634,6 +639,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
// set the account manager's root URL and trigger a login request if we don't have the access token // set the account manager's root URL and trigger a login request if we don't have the access token
accountManager.setIsAgent(true); accountManager.setIsAgent(true);
accountManager.setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL); accountManager.setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL);
UserActivityLogger::getInstance().launch(applicationVersion()); UserActivityLogger::getInstance().launch(applicationVersion());
// once the event loop has started, check and signal for an access token // once the event loop has started, check and signal for an access token
@ -723,8 +729,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
_offscreenContext->create(_glWidget->context()->contextHandle()); _offscreenContext->create(_glWidget->context()->contextHandle());
_offscreenContext->makeCurrent(); _offscreenContext->makeCurrent();
initializeGL(); initializeGL();
_offscreenContext->makeCurrent(); _offscreenContext->makeCurrent();
// Make sure we don't time out during slow operations at startup
deadlockWatchdog->updateHeartbeat();
// Tell our entity edit sender about our known jurisdictions // Tell our entity edit sender about our known jurisdictions
_entityEditSender.setServerJurisdictions(&_entityServerJurisdictions); _entityEditSender.setServerJurisdictions(&_entityServerJurisdictions);
@ -735,6 +742,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
_entityEditSender.setPacketsPerSecond(3000); // super high!! _entityEditSender.setPacketsPerSecond(3000); // super high!!
_overlays.init(); // do this before scripts load _overlays.init(); // do this before scripts load
// Make sure we don't time out during slow operations at startup
deadlockWatchdog->updateHeartbeat();
connect(this, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); connect(this, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
@ -886,8 +895,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
scriptEngines->setScriptsLocation(scriptEngines->getScriptsLocation()); scriptEngines->setScriptsLocation(scriptEngines->getScriptsLocation());
// do this as late as possible so that all required subsystems are initialized // do this as late as possible so that all required subsystems are initialized
scriptEngines->loadScripts(); scriptEngines->loadScripts();
// Make sure we don't time out during slow operations at startup
deadlockWatchdog->updateHeartbeat();
loadSettings(); loadSettings();
// Make sure we don't time out during slow operations at startup
deadlockWatchdog->updateHeartbeat();
int SAVE_SETTINGS_INTERVAL = 10 * MSECS_PER_SECOND; // Let's save every seconds for now int SAVE_SETTINGS_INTERVAL = 10 * MSECS_PER_SECOND; // Let's save every seconds for now
connect(&_settingsTimer, &QTimer::timeout, this, &Application::saveSettings); connect(&_settingsTimer, &QTimer::timeout, this, &Application::saveSettings);
connect(&_settingsThread, SIGNAL(started()), &_settingsTimer, SLOT(start())); connect(&_settingsThread, SIGNAL(started()), &_settingsTimer, SLOT(start()));
@ -1000,6 +1014,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
} }
}); });
// Make sure we don't time out during slow operations at startup
deadlockWatchdog->updateHeartbeat();
connect(this, &Application::applicationStateChanged, this, &Application::activeChanged); connect(this, &Application::applicationStateChanged, this, &Application::activeChanged);
qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)startupTimer.elapsed() / 1000.0); qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)startupTimer.elapsed() / 1000.0);