Skip to content

Commit

Permalink
Add live debugging when a callback takes a long time
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed Sep 4, 2023
1 parent e5a4c05 commit 0b6f7ee
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/SimCallbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,25 @@ local IssueFerry = IssueFerry
local CategoriesTransportation = categories.TRANSPORTATION

--- List of callbacks that is being populated throughout this file
---@type table<string, function>
---@type table<string, fun(data: table, units?: Unit[])>
local Callbacks = {}

---@param name string
---@param data table
---@param units? Unit[]
function DoCallback(name, data, units)
local start = GetSystemTimeSecondsOnlyForProfileUse()
local fn = Callbacks[name];
if fn then
fn(data, units)
else
SPEW('No callback named: ' .. repr(name))
end

local timeTaken = GetSystemTimeSecondsOnlyForProfileUse() - start
if (timeTaken > 0.005) then
SPEW(string.format("Time to process %s: %f", name, timeTaken))
end
end

--- Common utility function to retrieve the actual units.
Expand Down

0 comments on commit 0b6f7ee

Please sign in to comment.