Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Source/Managers/LuaMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,17 @@ int LuaStateWrapper::RunScriptFunctionObject(const LuabindObjectWrapper* functio
functionObjectArgument->GetLuabindObject()->push(m_State);
}
}

const std::string& path = functionObject->GetFilePath();

// Function object may be deleted during the Lua call, making `path` above invalid.
// Find and store the script timings entry now and write to it afterward.
PerformanceMan::ScriptTiming* timing = NULL;

// only track time in non-MT scripts, for now
if (&g_LuaMan.GetMasterScriptState() == this) {
timing = &m_ScriptTimings[path];
}

std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
{
ZoneScoped;
Expand All @@ -631,10 +640,9 @@ int LuaStateWrapper::RunScriptFunctionObject(const LuabindObjectWrapper* functio
}
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();

// only track time in non-MT scripts, for now
if (&g_LuaMan.GetMasterScriptState() == this) {
m_ScriptTimings[path].m_Time += std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count();
m_ScriptTimings[path].m_CallCount++;
if (timing != NULL) {
timing->m_Time += std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count();
timing->m_CallCount++;
}

lua_pop(m_State, 1);
Expand Down