Might be another interesting excercise
Imagine an addon that hooks EVENT_MANAGER:RegisterForEvent (right away, not in it's OnLoaded handler), and reports how much time various handlers take.
Lua Code:
local EM = GetEventManager()
local originalRegisterForEvent = EM.RegisterForEvent
local function RegisterForEventHook(self, tag, event, handler)
if event ~= EVENT_INVENTORY_SINGLE_SLOT_UPDATE then
-- for events we're not interested in, just call the original
return originalRegisterForEvent(self, tag, event, handler)
end
local function wrapped_handler(evt, ...)
local t1 = GetGameTimeMilliseconds()
handler(evt, ...)
local t2 = GetGameTimeMilliseconds()
d(("'%s' spent %.0fms handling event %s"):format(tag, t2 - t1, evt))
end
return originalRegisterForEvent(self, tag, event, wrapped_handler)
end
getmetatable(EM).__index.RegisterForEvent = RegisterForEventHook
edit: fixed missing ')' and tested, it works