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
64#include "ScriptEngines.h"64#include "ScriptEngines.h"
65#include "TabletScriptingInterface.h"65#include "TabletScriptingInterface.h"
66 66
67#include <Profile.h>
68
67#include "MIDIEvent.h"69#include "MIDIEvent.h"
68 70
69static const QString SCRIPT_EXCEPTION_FORMAT = "[UncaughtException] %1 in %2:%3";71static 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
863}865}
864 866
865void ScriptEngine::run() {867void 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
866 if (DependencyManager::get<ScriptEngines>()->isStopped()) {872 if (DependencyManager::get<ScriptEngines>()->isStopped()) {
867 return; // bail early - avoid setting state in init(), as evaluate() will bail too873 return; // bail early - avoid setting state in init(), as evaluate() will bail too
868 }874 }
@@ -923,7 +929,10 @@ void ScriptEngine::run() { · 54 unmodified lines
923 bool processedEvents = false;929 bool processedEvents = false;
924 while (!_isFinished && clock::now() < sleepUntil) {930 while (!_isFinished && clock::now() < sleepUntil) {
925 931
926 QCoreApplication::processEvents(); // before we sleep again, give events a chance to process932 {
933 PROFILE_RANGE(script, "processEvents-sleep");
934 QCoreApplication::processEvents(); // before we sleep again, give events a chance to process
935 }
927 processedEvents = true;936 processedEvents = true;
928 937
929 // If after processing events, we're past due, exit asap938 // If after processing events, we're past due, exit asap
@@ -938,6 +947,8 @@ void ScriptEngine::run() { · 8 unmodified lines
938 std::this_thread::sleep_until(smallSleepUntil);947 std::this_thread::sleep_until(smallSleepUntil);
939 }948 }
940 949
950 PROFILE_RANGE(script, "ScriptMainLoop");
951
941#ifdef SCRIPT_DELAY_DEBUG952#ifdef SCRIPT_DELAY_DEBUG
942 {953 {
943 auto actuallySleptUntil = clock::now();954 auto actuallySleptUntil = clock::now();
@@ -961,6 +972,7 @@ void ScriptEngine::run() { · 17 unmodified lines
961 972
962 // Only call this if we didn't processEvents as part of waiting for next frame973 // Only call this if we didn't processEvents as part of waiting for next frame
963 if (!processedEvents) {974 if (!processedEvents) {
975 PROFILE_RANGE(script, "processEvents");
964 QCoreApplication::processEvents();976 QCoreApplication::processEvents();
965 }977 }
966 978
@@ -985,7 +997,10 @@ void ScriptEngine::run() { · 18 unmodified lines
985 float deltaTime = (float) (now - _lastUpdate) / (float) USECS_PER_SECOND;997 float deltaTime = (float) (now - _lastUpdate) / (float) USECS_PER_SECOND;
986 if (!_isFinished) {998 if (!_isFinished) {
987 auto preUpdate = clock::now();999 auto preUpdate = clock::now();
988 emit update(deltaTime);1000 {
1001 PROFILE_RANGE(script, "ScriptUpdate");
1002 emit update(deltaTime);
1003 }
989 auto postUpdate = clock::now();1004 auto postUpdate = clock::now();
990 auto elapsed = (postUpdate - preUpdate);1005 auto elapsed = (postUpdate - preUpdate);
991 totalUpdates += std::chrono::duration_cast<std::chrono::microseconds>(elapsed);1006 totalUpdates += std::chrono::duration_cast<std::chrono::microseconds>(elapsed);