From fd2fd514f88844b6c17c84903cb9c0e936f74e06 Mon Sep 17 00:00:00 2001 From: Simpy Date: Wed, 13 Nov 2024 06:52:18 -0500 Subject: [PATCH] module profiler (similar to old ElvUI_CPU) with temp commands to check profiler data, will make a display later --- ElvUI/Core/General/Commands.lua | 131 +++++++++++++++++++++++++++---- ElvUI/Core/Modules/Chat/Chat.lua | 4 +- ElvUI/Core/init.lua | 129 ++++++++++++++++++++++++------ 3 files changed, 221 insertions(+), 43 deletions(-) diff --git a/ElvUI/Core/General/Commands.lua b/ElvUI/Core/General/Commands.lua index 09ac2400f5..8775d1c639 100644 --- a/ElvUI/Core/General/Commands.lua +++ b/ElvUI/Core/General/Commands.lua @@ -1,10 +1,13 @@ local E, L, V, P, G = unpack(ElvUI) +local CH = E:GetModule('Chat') local DT = E:GetModule('DataTexts') local AB = E:GetModule('ActionBars') -local type, pairs, tonumber = type, pairs, tonumber +local type, pairs, sort, tonumber = type, pairs, sort, tonumber local lower, wipe, next, print = strlower, wipe, next, print +local ipairs, format, tinsert = ipairs, format, tinsert +local CopyTable = CopyTable local ReloadUI = ReloadUI local DisableAddOn = C_AddOns.DisableAddOn @@ -70,6 +73,99 @@ function E:LuaError(msg) end end +do + local temp = {} + local list = {} + local text = '' + + function E:ShowProfilerData(data) + for _, info in ipairs(data) do + text = text .. format('%s - count: %d, avg: %0.3f, high: %0.3f, total: %0.3f\n', info.name, info.count or 0, info.average or 0, info.high or 0, info.total or 0) + end + + wipe(temp) + wipe(list) + end + + function E:ProfilerSort(second) + if self.total == second.total and self.high == self.high then + return self.count > second.count + end + + if self.total == second.total then + return self.high > second.high + end + + return self.total > second.total + end + + function E:SortProfilerData(module, data) + for key, value in next, data do + local clean = CopyTable(value) + clean.name = module..':'..key + + tinsert(temp, clean) + end + + sort(temp, E.ProfilerSort) + + E:ShowProfilerData(temp) + end + + function E:GetProfilerData(msg) + local switch = lower(msg) + if switch ~= '' then + if switch == 'e' then + local data = E.profiler.data[E] + if data then + E:Dump(data, true) + end + else + for key, module in next, E.modules do + local data = switch == lower(key) and E.profiler.data[module] + if data then + E:Dump(data, true) + end + end + end + end + end + + function E:FetchProfilerData(msg) + local switch = lower(msg) + if switch ~= '' then + if switch == 'e' then + E:SortProfilerData('E', E.profiler.data[E]) + else + for key, module in next, E.modules do + local data = switch == lower(key) and E.profiler.data[module] + if data then + E:SortProfilerData(key, data) + + break + end + end + end + else + E:SortProfilerData('E', E.profiler.data[E]) + + for key, module in next, E.modules do + local data = E.profiler.data[module] + if data then + E:SortProfilerData(key, data) + end + end + end + + if text ~= '' then + CH.CopyChatFrameEditBox:SetText(text) + CH.CopyChatFrame:Show() + end + + text = '' + end +end + function E:DisplayCommands() print(L["EHELP_COMMANDS"]) end @@ -251,25 +347,28 @@ end function E:LoadCommands() if E.private.actionbar.enable then - self:RegisterChatCommand('kb', AB.ActivateBindMode) + E:RegisterChatCommand('kb', AB.ActivateBindMode) end - self:RegisterChatCommand('ec', 'ToggleOptions') - self:RegisterChatCommand('elvui', 'ToggleOptions') + E:RegisterChatCommand('ec', 'ToggleOptions') + E:RegisterChatCommand('elvui', 'ToggleOptions') + + E:RegisterChatCommand('bgstats', DT.ToggleBattleStats) - self:RegisterChatCommand('bgstats', DT.ToggleBattleStats) + E:RegisterChatCommand('moveui', 'ToggleMoveMode') + E:RegisterChatCommand('resetui', 'ResetUI') - self:RegisterChatCommand('moveui', 'ToggleMoveMode') - self:RegisterChatCommand('resetui', 'ResetUI') + E:RegisterChatCommand('emove', 'ToggleMoveMode') + E:RegisterChatCommand('ereset', 'ResetUI') + E:RegisterChatCommand('edebug', 'LuaError') - self:RegisterChatCommand('emove', 'ToggleMoveMode') - self:RegisterChatCommand('ereset', 'ResetUI') - self:RegisterChatCommand('edebug', 'LuaError') + E:RegisterChatCommand('eprofile', 'GetProfilerData') -- temp until we make display window + E:RegisterChatCommand('eprofiler', 'FetchProfilerData') -- temp until we make display window - self:RegisterChatCommand('ehelp', 'DisplayCommands') - self:RegisterChatCommand('ecommands', 'DisplayCommands') - self:RegisterChatCommand('eblizzard', 'EnableBlizzardAddOns') - self:RegisterChatCommand('estatus', 'ShowStatusReport') - self:RegisterChatCommand('efixdb', 'DBConvertProfile') - self:RegisterChatCommand('egrid', 'Grid') + E:RegisterChatCommand('ehelp', 'DisplayCommands') + E:RegisterChatCommand('ecommands', 'DisplayCommands') + E:RegisterChatCommand('eblizzard', 'EnableBlizzardAddOns') + E:RegisterChatCommand('estatus', 'ShowStatusReport') + E:RegisterChatCommand('efixdb', 'DBConvertProfile') + E:RegisterChatCommand('egrid', 'Grid') end diff --git a/ElvUI/Core/Modules/Chat/Chat.lua b/ElvUI/Core/Modules/Chat/Chat.lua index 6df2b9412a..0db5edba0d 100644 --- a/ElvUI/Core/Modules/Chat/Chat.lua +++ b/ElvUI/Core/Modules/Chat/Chat.lua @@ -3302,7 +3302,7 @@ end function CH:BuildCopyChatFrame() local frame = CreateFrame('Frame', 'ElvUI_CopyChatFrame', E.UIParent) - tinsert(_G.UISpecialFrames, 'CopyChatFrame') + tinsert(_G.UISpecialFrames, 'ElvUI_CopyChatFrame') frame:SetTemplate('Transparent') frame:Size(700, 200) frame:Point('BOTTOM', E.UIParent, 'BOTTOM', 0, 3) @@ -3370,7 +3370,7 @@ function CH:BuildCopyChatFrame() editBox:Width(scrollFrame:GetWidth()) S:HandleScrollBar(scrollFrame.ScrollBar) - local close = CreateFrame('Button', 'CopyChatFrameCloseButton', frame, 'UIPanelCloseButton') + local close = CreateFrame('Button', 'ElvUI_CopyChatFrameCloseButton', frame, 'UIPanelCloseButton') close:Point('TOPRIGHT') close:SetFrameLevel(close:GetFrameLevel() + 1) close:EnableMouse(true) diff --git a/ElvUI/Core/init.lua b/ElvUI/Core/init.lua index e16480b81b..e3f47e9cb5 100644 --- a/ElvUI/Core/init.lua +++ b/ElvUI/Core/init.lua @@ -30,11 +30,90 @@ local SetCVar = C_CVar.SetCVar -- GLOBALS: ElvCharacterDB, ElvPrivateDB, ElvDB, ElvCharacterData, ElvPrivateData, ElvData +local ProfilerData, Profiler = {} +do -- not finished + local rawset = rawset + local unpack = unpack + local getmetatable = getmetatable + local setmetatable = setmetatable + local debugprofilestop = debugprofilestop + + local active = false -- active profiler + local function Generate(object, key, func) + -- print('Generate', object, key, func) + + return function(...) + local start = debugprofilestop() + local args = { func(...) } + local finish = debugprofilestop() - start + + local info = ProfilerData[object] + if not info then + info = {} + ProfilerData[object] = info + end + + local data = info[key] + if data then + data.count = data.count + 1 + + if data.finish > data.high then + data.high = data.finish + end + + if data.finish < data.low then + data.low = data.finish + end + + data.total = data.total + finish + data.average = data.total / data.count + else + data = { high = finish, low = finish, total = 0, count = 1 } + ProfilerData[object][key] = data + end + + data.start = start + data.finish = finish + + return unpack(args) + end + end + + local function Generator(object, key, value) + -- print('Generator', key, value) + + if type(value) == 'function' then + local func = Generate(object, key, value) + rawset(object, key, func) + else + rawset(object, key, value) + end + end + + Profiler = function(tbl, ...) + -- print('Profiler', tbl) + + if not active then + return tbl, ... + else + local t = getmetatable(tbl) + if t then + t.__newindex = Generator + + return tbl, ... + else + return setmetatable(tbl, { __newindex = Generator }), ... + end + end + end +end + local AceAddon, AceAddonMinor = _G.LibStub('AceAddon-3.0') local CallbackHandler = _G.LibStub('CallbackHandler-1.0') local AddOnName, Engine = ... -local E = AceAddon:NewAddon(AddOnName, 'AceConsole-3.0', 'AceEvent-3.0', 'AceTimer-3.0', 'AceHook-3.0') +local E = Profiler(AceAddon:NewAddon(AddOnName, 'AceConsole-3.0', 'AceEvent-3.0', 'AceTimer-3.0', 'AceHook-3.0')) +E.profiler = {func = Profiler, data = ProfilerData} -- ElvUI_CPU knock off by Simpy E.DF = {profile = {}, global = {}}; E.privateVars = {profile = {}} -- Defaults E.Options = {type = 'group', args = {}, childGroups = 'ElvUI_HiddenTree', get = E.noop, name = ''} E.callbacks = E.callbacks or CallbackHandler:New(E) @@ -51,30 +130,30 @@ _G.ElvUI = Engine E.oUF = _G.ElvUF assert(E.oUF, 'ElvUI was unable to locate oUF.') -E.ActionBars = E:NewModule('ActionBars','AceHook-3.0','AceEvent-3.0') -E.AFK = E:NewModule('AFK','AceEvent-3.0','AceTimer-3.0') -E.Auras = E:NewModule('Auras','AceHook-3.0','AceEvent-3.0') -E.Bags = E:NewModule('Bags','AceHook-3.0','AceEvent-3.0','AceTimer-3.0') -E.Blizzard = E:NewModule('Blizzard','AceEvent-3.0','AceHook-3.0') -E.Chat = E:NewModule('Chat','AceTimer-3.0','AceHook-3.0','AceEvent-3.0') -E.DataBars = E:NewModule('DataBars','AceEvent-3.0') -E.DataTexts = E:NewModule('DataTexts','AceTimer-3.0','AceHook-3.0','AceEvent-3.0') -E.DebugTools = E:NewModule('DebugTools','AceEvent-3.0','AceHook-3.0') -E.Distributor = E:NewModule('Distributor','AceEvent-3.0','AceTimer-3.0','AceComm-3.0','AceSerializer-3.0') -E.EditorMode = E:NewModule('EditorMode','AceEvent-3.0') -E.Layout = E:NewModule('Layout','AceEvent-3.0') -E.Minimap = E:NewModule('Minimap','AceHook-3.0','AceEvent-3.0','AceTimer-3.0') -E.Misc = E:NewModule('Misc','AceEvent-3.0','AceTimer-3.0','AceHook-3.0') -E.ModuleCopy = E:NewModule('ModuleCopy','AceEvent-3.0','AceTimer-3.0','AceComm-3.0','AceSerializer-3.0') -E.NamePlates = E:NewModule('NamePlates','AceHook-3.0','AceEvent-3.0','AceTimer-3.0') -E.PluginInstaller = E:NewModule('PluginInstaller') -E.PrivateAuras = E:NewModule('PrivateAuras') -E.RaidUtility = E:NewModule('RaidUtility','AceEvent-3.0') -E.Skins = E:NewModule('Skins','AceTimer-3.0','AceHook-3.0','AceEvent-3.0') -E.Tooltip = E:NewModule('Tooltip','AceTimer-3.0','AceHook-3.0','AceEvent-3.0') -E.TotemTracker = E:NewModule('TotemTracker','AceEvent-3.0') -E.UnitFrames = E:NewModule('UnitFrames','AceTimer-3.0','AceEvent-3.0','AceHook-3.0') -E.WorldMap = E:NewModule('WorldMap','AceHook-3.0','AceEvent-3.0','AceTimer-3.0') +E.ActionBars = Profiler(E:NewModule('ActionBars','AceHook-3.0','AceEvent-3.0')) +E.AFK = Profiler(E:NewModule('AFK','AceEvent-3.0','AceTimer-3.0')) +E.Auras = Profiler(E:NewModule('Auras','AceHook-3.0','AceEvent-3.0')) +E.Bags = Profiler(E:NewModule('Bags','AceHook-3.0','AceEvent-3.0','AceTimer-3.0')) +E.Blizzard = Profiler(E:NewModule('Blizzard','AceEvent-3.0','AceHook-3.0')) +E.Chat = Profiler(E:NewModule('Chat','AceTimer-3.0','AceHook-3.0','AceEvent-3.0')) +E.DataBars = Profiler(E:NewModule('DataBars','AceEvent-3.0')) +E.DataTexts = Profiler(E:NewModule('DataTexts','AceTimer-3.0','AceHook-3.0','AceEvent-3.0')) +E.DebugTools = Profiler(E:NewModule('DebugTools','AceEvent-3.0','AceHook-3.0')) +E.Distributor = Profiler(E:NewModule('Distributor','AceEvent-3.0','AceTimer-3.0','AceComm-3.0','AceSerializer-3.0')) +E.EditorMode = Profiler(E:NewModule('EditorMode','AceEvent-3.0')) +E.Layout = Profiler(E:NewModule('Layout','AceEvent-3.0')) +E.Minimap = Profiler(E:NewModule('Minimap','AceHook-3.0','AceEvent-3.0','AceTimer-3.0')) +E.Misc = Profiler(E:NewModule('Misc','AceEvent-3.0','AceTimer-3.0','AceHook-3.0')) +E.ModuleCopy = Profiler(E:NewModule('ModuleCopy','AceEvent-3.0','AceTimer-3.0','AceComm-3.0','AceSerializer-3.0')) +E.NamePlates = Profiler(E:NewModule('NamePlates','AceHook-3.0','AceEvent-3.0','AceTimer-3.0')) +E.PluginInstaller = Profiler(E:NewModule('PluginInstaller')) +E.PrivateAuras = Profiler(E:NewModule('PrivateAuras')) +E.RaidUtility = Profiler(E:NewModule('RaidUtility','AceEvent-3.0')) +E.Skins = Profiler(E:NewModule('Skins','AceTimer-3.0','AceHook-3.0','AceEvent-3.0')) +E.Tooltip = Profiler(E:NewModule('Tooltip','AceTimer-3.0','AceHook-3.0','AceEvent-3.0')) +E.TotemTracker = Profiler(E:NewModule('TotemTracker','AceEvent-3.0')) +E.UnitFrames = Profiler(E:NewModule('UnitFrames','AceTimer-3.0','AceEvent-3.0','AceHook-3.0')) +E.WorldMap = Profiler(E:NewModule('WorldMap','AceHook-3.0','AceEvent-3.0','AceTimer-3.0')) E.InfoColor = '|cff1784d1' -- blue E.InfoColor2 = '|cff9b9b9b' -- silver