History

Add logging to ScriptEngine lifetime

Zach Pomerantz committed 10 years ago

Commit f2f89ca1 parent f40fe881 file · +8 −5Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+8−5
@@ -154,7 +154,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 153 unmodified lines
154}154}
155 155
156ScriptEngine::~ScriptEngine() {156ScriptEngine::~ScriptEngine() {
157 qCDebug(scriptengine) << "Script Engine shutting down (destructor) for script:" << getFilename();157 qCDebug(scriptengine) << "Script Engine shutting down:" << getFilename();
158 158
159 auto scriptEngines = DependencyManager::get<ScriptEngines>();159 auto scriptEngines = DependencyManager::get<ScriptEngines>();
160 if (scriptEngines) {160 if (scriptEngines) {
@@ -291,11 +291,10 @@ void ScriptEngine::wait() { · 130 unmodified lines
291 // We should never be waiting (blocking) on our own thread291 // We should never be waiting (blocking) on our own thread
292 assert(workerThread != QThread::currentThread());292 assert(workerThread != QThread::currentThread());
293 293
294 // Engine should be stopped already, but be defensive
294 stop();295 stop();
295 296
296 QString scriptName = getFilename();
297 auto startedWaiting = usecTimestampNow();297 auto startedWaiting = usecTimestampNow();
298
299 while (workerThread->isRunning()) {298 while (workerThread->isRunning()) {
300 // NOTE: This will be called on the main application thread from stopAllScripts.299 // NOTE: This will be called on the main application thread from stopAllScripts.
301 // The application thread will need to continue to process events, because300 // The application thread will need to continue to process events, because
@@ -310,13 +309,13 @@ void ScriptEngine::wait() { · 8 unmodified lines
310 auto elapsedUsecs = usecTimestampNow() - startedWaiting;309 auto elapsedUsecs = usecTimestampNow() - startedWaiting;
311 if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {310 if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {
312 qCDebug(scriptengine).nospace() <<311 qCDebug(scriptengine).nospace() <<
313 "Script " << scriptName << " has been running too long [" << elapsedUsecs << "usecs] quitting.";312 "Script Engine has been running too long, aborting:" << getFilename();
314 abortEvaluation(); // break out of current evaluation313 abortEvaluation(); // break out of current evaluation
315 314
316 // Wait for the scripting thread to stop running315 // Wait for the scripting thread to stop running
317 if (!workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {316 if (!workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {
318 qCWarning(scriptengine).nospace() <<317 qCWarning(scriptengine).nospace() <<
319 "Script " << scriptName << " has been quitting too long [" << elapsedUsecs << "usecs] terminating.";318 "Script Engine has been aborting too long, terminating:" << getFilename();
320 workerThread->terminate();319 workerThread->terminate();
321 }320 }
322 }321 }
@@ -324,6 +323,8 @@ void ScriptEngine::wait() { · 1 unmodified line
324 // Avoid a pure busy wait323 // Avoid a pure busy wait
325 QThread::yieldCurrentThread();324 QThread::yieldCurrentThread();
326 }325 }
326
327 qCDebug(scriptengine) << "Script Engine has stopped:" << getFilename();
327 }328 }
328}329}
329 330
@@ -874,6 +875,8 @@ void ScriptEngine::run() { · 544 unmodified lines
874 hadUncaughtExceptions(*this, _fileNameString);875 hadUncaughtExceptions(*this, _fileNameString);
875 }876 }
876 877
878 qCDebug(scriptengine) << "Script Engine stopping:" << getFilename();
879
877 stopAllTimers(); // make sure all our timers are stopped if the script is ending880 stopAllTimers(); // make sure all our timers are stopped if the script is ending
878 emit scriptEnding();881 emit scriptEnding();
879 882