View Single Post
09/11/15, 10:49 AM   #58
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
Originally Posted by merlight View Post
GetFrameTimeMilliseconds() returns the same value during a single UI frame, yes.

GetGameTimeMilliseconds() returns actual time since the game was started, so it basically works for measuring time spent within a function, but the results are not very consistent. They depend on thread scheduling (how much CPU time the Lua VM is given), how it struggles with memory allocations etc. If you want to evaluate whether func1 is more efficient than func2, you'll have to call them hundreds of thousands of times to get some usable averages.
I might have missed GetGameTimeMilliseconds. The other time functions that I tested returned the same value every time.
What I did was something like this:
Lua Code:
  1. local GetTime = WhateverTimeFunction
  2. function SomeFunction()
  3.   local start = GetTime()
  4.   -- do something that makes the game freeze for a second
  5.   df("This took %d", GetTime() - start)
  6. end
That's pretty tedious to add to every function though.

Best case we would get a value in UserSettings.txt which enables a profiling event that returns data for each frame.
EVENT_FRAME_EXECUTION_TIMES ( integer frameTime, integer cpuPercent, integer memoryAllocation, object callstack, object addonData )
Callstack would contain all calls that happened during the frame in tree form:
Lua Code:
  1. callstack = {
  2.   [1] = {
  3.     functionName = "MyFunction",
  4.     callTime = 123456789, -- nanoseconds?
  5.     file = "MyAddon.lua",
  6.     line = "123"
  7.     callstack = {
  8.       [1] = { ... }, -- same as before
  9.       [2] = { ... }
  10.     },
  11.     [2] = { ... },
  12. }
AddonData shows the cpuPercent and memoryAllocation for individual addons.
Lua Code:
  1. addonData = {
  2.   [1] = {
  3.     addonName = "MyAddon",
  4.     cpuPercent = 12, -- %
  5.     memoryAllocation = 123456 -- Bytes
  6.   }
  7. }
  Reply With Quote