View Single Post
02/12/16, 02:40 AM   #1
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
Measuring addon load times?

I'm wondering if there is a way (maybe built-in) to measure the load time of all addons, I've tried measuring the time between EVENT_ADD_ON_LOADED calls, but results seem to be wrong (maybe due to how the events are called), or measuring something else.

what I tried:
Lua Code:
  1. AddonLoadingTime = {
  2.     name = "AddonLoadingTime",
  3.     author = "",
  4.     version = "100013.000",
  5. }
  6.  
  7. local GetTime = GetGameTimeMilliseconds
  8. local loadingTimes = {}
  9. local lastAddonName = nil
  10. local lastTick = GetTime()
  11.  
  12. function AddonLoadingTime.OnAddOnLoaded(event, addonName)
  13.     if lastAddonName then
  14.         loadingTimes[lastAddonName] = (GetTime() - lastTick)
  15.     end
  16.  
  17.     lastAddonName = addonName
  18.     lastTick = GetTime()
  19. end
  20.  
  21. function AddonLoadingTime.OnPlayerActivated(event)
  22.     for k,v in pairs(loadingTimes) do
  23.         if not string.match(k, '^ZO_') then
  24.             d(string.format("%s took %s ms", k, tostring(v)))
  25.         end
  26.     end
  27.  
  28.     EVENT_MANAGER:UnregisterForEvent(AddonLoadingTime.name, EVENT_PLAYER_ACTIVATED)
  29. end
  30.  
  31. EVENT_MANAGER:RegisterForEvent(AddonLoadingTime.name, EVENT_ADD_ON_LOADED, AddonLoadingTime.OnAddOnLoaded)
  32. EVENT_MANAGER:RegisterForEvent(AddonLoadingTime.name, EVENT_PLAYER_ACTIVATED, AddonLoadingTime.OnPlayerActivated)

example output:
Lua Code:
  1. merTorchbug took 4 ms
  2. SkyShards took 7 ms
  3. HarvensExtendedStats took 0 ms
  4. DeveloperSuite took 0 ms
  5. AddonLoadingTime took 4 ms
  6. BankManagerRevived took 88 ms
  7. HarvestMapDC took 0 ms
  8. WidgetTest took 9 ms
  9. Destinations took 0 ms
  10. ImmersionToggles took 38 ms
  11. SimpleXPBar took 10 ms
  12. HarvestMap took 4 ms
  13. AUI took 0 ms
  14. AwesomeInfo took 120 ms
  15. Ledger took 0 ms
  16. HarvestMapEP took 0 ms
  17. DevTools took 0 ms
  18. JunkIt took 182 ms
  19. AddonTemplate took 12 ms

One of the reasons I think this is wrong is because ImmersionToggles is taking 38ms while Destinations is taking 0ms this is pretty much nonsense, since ~3 times as much work is going on at the startup of Destinations. These results are pretty consistent though even when the load order is different, so I don't think its noise from calls in-between. Am I doing this wrong? or is it even possible to measure these correctly?

EDIT: So after thinking about it a bit more, I can only assume the my results are scewed because of the order in which the events are called, e.g. sometimes AddonLoadingTime.OnAddOnLoaded is being called before the target addon and sometimes after. So maybe measuring this isn't doable, or I may need to use another method.

[sorry if this is the wrong subforum wasn't sure which to post this in]

Last edited by Terrillyn : 02/12/16 at 03:13 AM.
  Reply With Quote