History

Add tracing to ScriptEngine and EntitiesScriptingInterface

Ryan Huffman committed 9 years ago

Commit 55df6f81 parent ce9f8be4 files · +66 −2Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+13−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";
@@ -927,7 +929,10 @@ void ScriptEngine::run() { · 857 unmodified lines
927 bool processedEvents = false;929 bool processedEvents = false;
928 while (!_isFinished && clock::now() < sleepUntil) {930 while (!_isFinished && clock::now() < sleepUntil) {
929 931
930 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 }
931 processedEvents = true;936 processedEvents = true;
932 937
933 // If after processing events, we're past due, exit asap938 // If after processing events, we're past due, exit asap
@@ -942,6 +947,8 @@ void ScriptEngine::run() { · 8 unmodified lines
942 std::this_thread::sleep_until(smallSleepUntil);947 std::this_thread::sleep_until(smallSleepUntil);
943 }948 }
944 949
950 PROFILE_RANGE(script, "ScriptMainLoop");
951
945#ifdef SCRIPT_DELAY_DEBUG952#ifdef SCRIPT_DELAY_DEBUG
946 {953 {
947 auto actuallySleptUntil = clock::now();954 auto actuallySleptUntil = clock::now();
@@ -965,6 +972,7 @@ void ScriptEngine::run() { · 17 unmodified lines
965 972
966 // 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
967 if (!processedEvents) {974 if (!processedEvents) {
975 PROFILE_RANGE(script, "processEvents");
968 QCoreApplication::processEvents();976 QCoreApplication::processEvents();
969 }977 }
970 978
@@ -989,7 +997,10 @@ void ScriptEngine::run() { · 18 unmodified lines
989 float deltaTime = (float) (now - _lastUpdate) / (float) USECS_PER_SECOND;997 float deltaTime = (float) (now - _lastUpdate) / (float) USECS_PER_SECOND;
990 if (!_isFinished) {998 if (!_isFinished) {
991 auto preUpdate = clock::now();999 auto preUpdate = clock::now();
992 emit update(deltaTime);1000 {
1001 PROFILE_RANGE(script, "ScriptUpdate");
1002 emit update(deltaTime);
1003 }
993 auto postUpdate = clock::now();1004 auto postUpdate = clock::now();
994 auto elapsed = (postUpdate - preUpdate);1005 auto elapsed = (postUpdate - preUpdate);
995 totalUpdates += std::chrono::duration_cast<std::chrono::microseconds>(elapsed);1006 totalUpdates += std::chrono::duration_cast<std::chrono::microseconds>(elapsed);