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
154154 }
155155
156156 ScriptEngine::~ScriptEngine() {
157− qCDebug(scriptengine) << "Script Engine shutting down (destructor) for script:" << getFilename();
157+ qCDebug(scriptengine) << "Script Engine shutting down:" << getFilename();
158158
159159 auto scriptEngines = DependencyManager::get<ScriptEngines>();
160160 if (scriptEngines) {
@@ -291,11 +291,10 @@ void ScriptEngine::wait() { · 130 unmodified lines
291291 // We should never be waiting (blocking) on our own thread
292292 assert(workerThread != QThread::currentThread());
293293
294+ // Engine should be stopped already, but be defensive
294295 stop();
295296
296− QString scriptName = getFilename();
297297 auto startedWaiting = usecTimestampNow();
298−
299298 while (workerThread->isRunning()) {
300299 // NOTE: This will be called on the main application thread from stopAllScripts.
301300 // The application thread will need to continue to process events, because
@@ -310,13 +309,13 @@ void ScriptEngine::wait() { · 8 unmodified lines
310309 auto elapsedUsecs = usecTimestampNow() - startedWaiting;
311310 if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {
312311 qCDebug(scriptengine).nospace() <<
313− "Script " << scriptName << " has been running too long [" << elapsedUsecs << "usecs] quitting.";
312+ "Script Engine has been running too long, aborting:" << getFilename();
314313 abortEvaluation(); // break out of current evaluation
315314
316315 // Wait for the scripting thread to stop running
317316 if (!workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {
318317 qCWarning(scriptengine).nospace() <<
319− "Script " << scriptName << " has been quitting too long [" << elapsedUsecs << "usecs] terminating.";
318+ "Script Engine has been aborting too long, terminating:" << getFilename();
320319 workerThread->terminate();
321320 }
322321 }
@@ -324,6 +323,8 @@ void ScriptEngine::wait() { · 1 unmodified line
324323 // Avoid a pure busy wait
325324 QThread::yieldCurrentThread();
326325 }
326+
327+ qCDebug(scriptengine) << "Script Engine has stopped:" << getFilename();
327328 }
328329 }
329330
@@ -874,6 +875,8 @@ void ScriptEngine::run() { · 544 unmodified lines
874875 hadUncaughtExceptions(*this, _fileNameString);
875876 }
876877
878+ qCDebug(scriptengine) << "Script Engine stopping:" << getFilename();
879+
877880 stopAllTimers(); // make sure all our timers are stopped if the script is ending
878881 emit scriptEnding();
879882