Advertisement
Kuipo

WarmUp 5.0.5

Nov 3rd, 2012
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.41 KB | None | 0 0
  1. -- Updated WarmUp by Cybeloras of Mal'Ganis. Uses debugprofile start/stop instead of GetTime because it seems that GetTime() is not updated during loading screens anymore.
  2. -- Updated WarmUp again by Kuipo of Hyjal. Updated to work with WoW v5.0.5
  3.  
  4. collectgarbage("stop")
  5. collectgarbage("collect")
  6. local initmem = collectgarbage("count")
  7. local longesttime, biggestmem, totalmem, totalgarbage, mostgarbage, gctime = 0, 0, 0, 0, 0, 0
  8. local totaltime = 0
  9. local eventcounts, combatframe = {}, ChatFrame2
  10. local eventargs = {}
  11. local threshtimes, threshmems = {1.0, 0.5, 0.1}, {1000, 500, 100}
  12. local threshcolors = {"|cffff0000", "|cffff8000", "|cffffff80", "|cff80ff80"}
  13. local outframe, sv, intransit, reloading, longestaddon, biggestaddon, varsloadtime, logging, mostgarbageaddon, leftworld
  14. local memstack = {initmem}
  15.  
  16. local usecombatframe = false
  17.  
  18. local timerIsLocked
  19. local function start()
  20.     if timerIsLocked then
  21.     --  outframe:AddMessage("ATTEMPTED TO START TIMER WHILE LOCKED")
  22.     --  outframe:AddMessage(debugstack())
  23.     end
  24.    
  25.     timerIsLocked = true
  26.     debugprofilestart()
  27. end
  28.  
  29. local function stop()
  30.     if not timerIsLocked then
  31.     --  outframe:AddMessage("ATTEMPTED TO STOP TIMER WHILE UNLOCKED")
  32.     --  outframe:AddMessage(debugstack())
  33.     end
  34.    
  35.     timerIsLocked = false
  36.     return debugprofilestop()
  37. end
  38.  
  39. start()
  40.  
  41.     --[[ (insert a space between the dashes and brackets)
  42.     LoadAddOn("Blizzard_DebugTools")
  43.     EventTraceFrame_HandleSlashCmd ("")
  44.     EVENT_TRACE_MAX_ENTRIES = 10000
  45.     --]]
  46.  
  47. local frame = CreateFrame("Frame", "WarmupFrame", UIParent)
  48. Warmup = {}
  49.  
  50. frame:SetScript("OnEvent", function(self, event, ...)
  51.     if eventcounts then
  52.         eventcounts[event] = (eventcounts[event] or 0) + 1
  53.         eventargs[event] = max(select("#", ...), eventargs[event] or 0)
  54.     end
  55.     if Warmup[event] then Warmup[event](Warmup, ...) end
  56. end)
  57.  
  58.  
  59. local function GetThreshColor(set, value)
  60.     local t = set == "mem" and threshmems or threshtimes
  61.     for i,v in pairs(t) do
  62.         if value >= v then return threshcolors[i] end
  63.     end
  64.     return threshcolors[4]
  65. end
  66.  
  67.  
  68. local function PutOut(txt, color, time, mem, gc)
  69.     local outstr = (time and string.format("%.3f sec | ", time) or "")..
  70.         color.. txt.. (mem and string.format(" (%d KiB", mem) or "")..
  71.         (gc and string.format(" - %d KiB)", gc) or mem and ")" or "")
  72.  
  73.     if usecombatframe then combatframe:AddMessage(outstr) end
  74.     outframe:AddMessage(outstr)
  75. end
  76.  
  77.  
  78. local function PutOutAO(name, time, mem, garbage)
  79.     outframe:AddMessage(string.format("%s%.3f sec|r | %s (%s%d KiB|r - %s%d KiB|r)", GetThreshColor("time", time), time,
  80.         name, GetThreshColor("mem", mem), mem, GetThreshColor("mem", garbage), garbage))
  81.     return string.format("%.3f sec | %s (%d KiB - %d KiB)", time, name, mem, garbage)
  82. end
  83.  
  84.  
  85.  
  86. do
  87.     local loadandpop = function(...)
  88.         local newm, newt = table.remove(memstack)
  89.         local oldm, oldt = table.remove(memstack)
  90.         local origm, origt = table.remove(memstack)
  91.         table.insert(memstack, origm + newm - oldm)
  92.         return ...
  93.     end
  94.     local lao = LoadAddOn
  95.     LoadAddOn = function (...)
  96.         if timerIsLocked then
  97.             stop() -- stop any runaway timers
  98.         end
  99.        
  100.         start()
  101.         collectgarbage("collect")
  102.         gctime = gctime + stop()/1000
  103.        
  104.         local newmem = collectgarbage("count")
  105.         table.insert(memstack, newmem)
  106.         table.insert(memstack, newmem)
  107.         start() -- start the timer for ADDON_LOADED to finish
  108.         return loadandpop(lao(...))
  109.     end
  110. end
  111.  
  112.  
  113. function Warmup:OnLoad()
  114.     table.insert(UISpecialFrames, "WarmupOutputFrame")
  115.     frame:RegisterAllEvents()
  116. end
  117.  
  118. function Warmup:Init()
  119.     if not WarmupSV then WarmupSV = {} end
  120.     sv = WarmupSV
  121.     sv.addoninfo = {}
  122.  
  123.     outframe = WarmupChatFrame
  124.  
  125.     do
  126.         for i=1,GetNumAddOns() do
  127.             if IsAddOnLoaded(i) then
  128.                 if GetAddOnInfo(i) ~= "!!Warmup" then
  129.                     if usecombatframe then combatframe:AddMessage("Addon loaded before Warmup: ".. GetAddOnInfo(i)) end
  130.                     outframe:AddMessage("Addon loaded before Warmup: ".. GetAddOnInfo(i))
  131.                 end
  132.             end
  133.         end
  134.     end
  135. end
  136.  
  137.  
  138. function Warmup:DumpEvents()
  139.     local sortt = {}
  140.     for ev,val in pairs(eventcounts) do table.insert(sortt, ev) end
  141.  
  142.     table.sort(sortt)
  143.  
  144.     for i,ev in pairs(sortt) do
  145.         outframe:AddMessage(string.format(threshcolors[1].."%d|r (%d) | %s%s|r", eventcounts[ev], eventargs[ev], threshcolors[4], ev))
  146.     end
  147.     outframe:AddMessage("------------")
  148. end
  149.  
  150.  
  151. function Warmup:ADDON_LOADED(addon)
  152.     local addonmem = collectgarbage("count")
  153.     local lastmem = table.remove(memstack)
  154.     local lasttime = stop()/1000
  155.     local diff = addonmem - lastmem
  156.    
  157.     totaltime = totaltime + lasttime
  158.    
  159.     start()
  160.     collectgarbage("collect")
  161.     gctime = gctime + stop()/1000
  162.    
  163.     local gcmem = collectgarbage("count")
  164.     local garbage = addonmem - gcmem
  165.  
  166.     if not outframe or not sv then self:Init() end
  167.  
  168.     table.insert(sv.addoninfo, PutOutAO(addon, lasttime, diff - garbage, garbage))
  169.  
  170.     if lasttime > longesttime then
  171.         longesttime = lasttime
  172.         longestaddon = addon
  173.     end
  174.     if (diff - garbage) > biggestmem then
  175.         biggestmem = diff - garbage
  176.         biggestaddon = addon
  177.     end
  178.     if garbage > mostgarbage then
  179.         mostgarbage = garbage
  180.         mostgarbageaddon = addon
  181.     end
  182.     totalgarbage = totalgarbage + garbage
  183.     totalmem = totalmem + diff
  184.     table.insert(memstack, gcmem)
  185.     start()
  186. end
  187.  
  188.  
  189. function Warmup:VARIABLES_LOADED()
  190.     if varsloadtime then return end
  191.     stop() -- stop the timer (it is still running from the last addon loaded
  192.    
  193.     start()
  194.     collectgarbage("collect")
  195.     gctime = gctime + stop()/1000
  196.  
  197.     local lastmem = collectgarbage("count")
  198.  
  199.     varsloadtime = GetTime()
  200.     PutOut("Addon Loadup", threshcolors[4], totaltime, lastmem - initmem, totalgarbage)
  201.     PutOut("Warmup's Garbage Collection", threshcolors[4], gctime)
  202.     PutOut("Longest addon: ".. longestaddon, threshcolors[2], longesttime)
  203.     PutOut("Biggest addon: ".. biggestaddon, threshcolors[2], nil, biggestmem)
  204.     PutOut("Most Garbage: "..mostgarbageaddon, threshcolors[2], nil, mostgarbage)
  205.  
  206.     frame:RegisterEvent("PLAYER_LOGIN")
  207.  
  208.     SlashCmdList["RELOAD"] = ReloadUI
  209.     SLASH_RELOAD1 = "/rl"
  210.  
  211.     SlashCmdList["RELOADNODISABLE"] = function()
  212.         sv.time = GetTime()
  213.         reloading = true
  214.         EnableAddOn("!!Warmup")
  215.         ReloadUI()
  216.     end
  217.     SLASH_RELOADNODISABLE1 = "/rlnd"
  218.  
  219.     SlashCmdList["WARMUP"] = function()
  220.         if WarmupOutputFrame:IsVisible() then WarmupOutputFrame:Hide()
  221.         else WarmupOutputFrame:Show() end
  222.     end
  223.  
  224.     SLASH_WARMUP1 = "/wu"
  225.     SLASH_WARMUP2 = "/warmup"
  226.  
  227.     collectgarbage("restart")
  228.     -- DisableAddOn("!!Warmup")
  229.     start()
  230. end
  231.  
  232.  
  233. function Warmup:PLAYER_LOGIN()
  234.     logging = true
  235.     frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  236. end
  237.  
  238.  
  239. function Warmup:PLAYER_ENTERING_WORLD()
  240.     if logging then
  241.         local entrytime = stop()/1000
  242.  
  243.         PutOut("World entry", threshcolors[4], entrytime)
  244.  
  245.         PutOut("Total time", threshcolors[4], entrytime + totaltime + gctime)
  246.  
  247.         sv.time = nil
  248.         varsloadtime = nil
  249.     elseif leftworld then
  250.         PutOut("Zoning", threshcolors[4], stop()/1000)
  251.         leftworld = nil
  252.     end
  253.    
  254.     logging = nil
  255.     frame:RegisterAllEvents()
  256.     frame:UnregisterEvent("PLAYER_LOGIN")
  257.     frame:UnregisterEvent("PLAYER_LOGOUT")
  258.     frame:UnregisterEvent("PLAYER_ENTERING_WORLD")
  259.  
  260.     self:DumpEvents()
  261.     eventcounts = nil
  262. end
  263.  
  264.  
  265. function Warmup:PLAYER_LEAVING_WORLD()
  266.     --sv.time = GetTime()
  267.     frame:RegisterAllEvents()
  268.     frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  269.     frame:RegisterEvent("PLAYER_LOGOUT")
  270.  
  271.     eventcounts = {}
  272.     if timerIsLocked then
  273.         stop() -- stop any runaway timers
  274.     end
  275.     start()
  276.     leftworld = true
  277. end
  278.  
  279.  
  280. function Warmup:PLAYER_LOGOUT()
  281.     if not reloading then sv.time = nil end
  282. end
  283.  
  284.  
  285. Warmup:OnLoad()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement