Add thread names and scripts to chrome traces
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 10 files). Show all
Unified · Split
| @@ -64,6 +64,8 @@ · 63 unmodified lines | ||
| 64 | 64 | #include "ScriptEngines.h" |
| 65 | 65 | #include "TabletScriptingInterface.h" |
| 66 | 66 | |
| 67 | +#include <Profile.h> | |
| 68 | + | |
| 67 | 69 | #include "MIDIEvent.h" |
| 68 | 70 | |
| 69 | 71 | 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 | ||
| 863 | 865 | } |
| 864 | 866 | |
| 865 | 867 | 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 | + | |
| 866 | 872 | if (DependencyManager::get<ScriptEngines>()->isStopped()) { |
| 867 | 873 | 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 | 929 | bool processedEvents = false; |
| 924 | 930 | while (!_isFinished && clock::now() < sleepUntil) { |
| 925 | 931 | |
| 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 | + } | |
| 927 | 936 | processedEvents = true; |
| 928 | 937 | |
| 929 | 938 | // If after processing events, we're past due, exit asap |
| @@ -938,6 +947,8 @@ void ScriptEngine::run() { · 8 unmodified lines | ||
| 938 | 947 | std::this_thread::sleep_until(smallSleepUntil); |
| 939 | 948 | } |
| 940 | 949 | |
| 950 | + PROFILE_RANGE(script, "ScriptMainLoop"); | |
| 951 | + | |
| 941 | 952 | #ifdef SCRIPT_DELAY_DEBUG |
| 942 | 953 | { |
| 943 | 954 | auto actuallySleptUntil = clock::now(); |
| @@ -961,6 +972,7 @@ void ScriptEngine::run() { · 17 unmodified lines | ||
| 961 | 972 | |
| 962 | 973 | // Only call this if we didn't processEvents as part of waiting for next frame |
| 963 | 974 | if (!processedEvents) { |
| 975 | + PROFILE_RANGE(script, "processEvents"); | |
| 964 | 976 | QCoreApplication::processEvents(); |
| 965 | 977 | } |
| 966 | 978 | |
| @@ -985,7 +997,10 @@ void ScriptEngine::run() { · 18 unmodified lines | ||
| 985 | 997 | float deltaTime = (float) (now - _lastUpdate) / (float) USECS_PER_SECOND; |
| 986 | 998 | if (!_isFinished) { |
| 987 | 999 | auto preUpdate = clock::now(); |
| 988 | − emit update(deltaTime); | |
| 1000 | + { | |
| 1001 | + PROFILE_RANGE(script, "ScriptUpdate"); | |
| 1002 | + emit update(deltaTime); | |
| 1003 | + } | |
| 989 | 1004 | auto postUpdate = clock::now(); |
| 990 | 1005 | auto elapsed = (postUpdate - preUpdate); |
| 991 | 1006 | totalUpdates += std::chrono::duration_cast<std::chrono::microseconds>(elapsed); |