History

Merge pull request #9603 from huffman/feat/trace-thread-script

Add thread names and scripts to chrome traces

Brad Hefta-Gaub committed 9 years ago

Commit 74f10a12 parents bc22326 aba441e10 files · +132 −20Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+17−2
@@ -64,6 +64,8 @@ · 63 unmodified lines
6464 #include "ScriptEngines.h"
6565 #include "TabletScriptingInterface.h"
6666
67+#include <Profile.h>
68+
6769 #include "MIDIEvent.h"
6870
6971 static const QString SCRIPT_EXCEPTION_FORMAT = "[UncaughtException] %1 in %2:%3";
@@ -863,6 +865,10 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi · 793 unmodified lines
863865 }
864866
865867 void ScriptEngine::run() {
868+ auto filenameParts = _fileNameString.split("/");
869+ auto name = filenameParts.size() > 0 ? filenameParts[filenameParts.size() - 1] : "unknown";
870+ PROFILE_SET_THREAD_NAME("Script: " + name);
871+
866872 if (DependencyManager::get<ScriptEngines>()->isStopped()) {
867873 return; // bail early - avoid setting state in init(), as evaluate() will bail too
868874 }
@@ -923,7 +929,10 @@ void ScriptEngine::run() { · 54 unmodified lines
923929 bool processedEvents = false;
924930 while (!_isFinished && clock::now() < sleepUntil) {
925931
926− QCoreApplication::processEvents(); // before we sleep again, give events a chance to process
932+ {
933+ PROFILE_RANGE(script, "processEvents-sleep");
934+ QCoreApplication::processEvents(); // before we sleep again, give events a chance to process
935+ }
927936 processedEvents = true;
928937
929938 // If after processing events, we're past due, exit asap
@@ -938,6 +947,8 @@ void ScriptEngine::run() { · 8 unmodified lines
938947 std::this_thread::sleep_until(smallSleepUntil);
939948 }
940949
950+ PROFILE_RANGE(script, "ScriptMainLoop");
951+
941952 #ifdef SCRIPT_DELAY_DEBUG
942953 {
943954 auto actuallySleptUntil = clock::now();
@@ -961,6 +972,7 @@ void ScriptEngine::run() { · 17 unmodified lines
961972
962973 // Only call this if we didn't processEvents as part of waiting for next frame
963974 if (!processedEvents) {
975+ PROFILE_RANGE(script, "processEvents");
964976 QCoreApplication::processEvents();
965977 }
966978
@@ -985,7 +997,10 @@ void ScriptEngine::run() { · 18 unmodified lines
985997 float deltaTime = (float) (now - _lastUpdate) / (float) USECS_PER_SECOND;
986998 if (!_isFinished) {
987999 auto preUpdate = clock::now();
988− emit update(deltaTime);
1000+ {
1001+ PROFILE_RANGE(script, "ScriptUpdate");
1002+ emit update(deltaTime);
1003+ }
9891004 auto postUpdate = clock::now();
9901005 auto elapsed = (postUpdate - preUpdate);
9911006 totalUpdates += std::chrono::duration_cast<std::chrono::microseconds>(elapsed);