Thread Tools Display Modes
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
02/12/16, 06:08 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
This method won't tell you anything at all about addon load times, because you never know what happens between two events.
For example there could be any number of controls being updated inbetween. Addons could also defer some work and either do it in a different event (player activated) or via zo_callLater.
In order to measure the loading time, you would need to edit the addons directly and add a StartMeasurement() and StopMeasurement() into the appropriate lines of code.
  Reply With Quote
02/12/16, 07:55 AM   #3
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
I have the impression that the last step of loading any add-on is to initialize the top level controls, so I'd test something like:

1. Saving the time in the first line of the very first file in your manifest.
2. Comparing it to the time of the OnInitialize callback from your top level control.

If you don't have any XML create an empty TopLevelControl with just the callback in question.

I might be wrong about this but I think it's worth a shot. The OnAddOnLoaded event is unreliable, as said by @sirinsidiat0r, the game might trigger it way after your add-on has actually been loaded.

Last edited by haggen : 02/12/16 at 01:27 PM.
  Reply With Quote
02/12/16, 09:56 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
To improve user loading time, don't look at your code, look at master merchant one
  Reply With Quote
02/12/16, 01:37 PM   #5
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
Originally Posted by sirinsidiator View Post
This method won't tell you anything at all about addon load times, because you never know what happens between two events.
For example there could be any number of controls being updated inbetween. Addons could also defer some work and either do it in a different event (player activated) or via zo_callLater.
In order to measure the loading time, you would need to edit the addons directly and add a StartMeasurement() and StopMeasurement() into the appropriate lines of code.
That's what I figured, it wasn't really important enough for me to edit other addons, I was mostly trying to find which addon was causing long load times, I ended up narrowing it down to craftstore which as adding around 4seconds.

To improve user loading time, don't look at your code, look at master merchant one
I didn't really see anything in there that would help load times but it was a jungle of code so I didn't know what I was looking for anyways.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Measuring addon load times?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off