Skip to content

Commit

Permalink
Merge branch 'main' into ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Luckyone961 committed Nov 14, 2024
2 parents 65e1693 + 7004772 commit 035e21a
Show file tree
Hide file tree
Showing 3 changed files with 288 additions and 44 deletions.
173 changes: 157 additions & 16 deletions ElvUI/Core/General/Commands.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -70,6 +73,141 @@ function E:LuaError(msg)
end
end

do
local temp = {}
local list = {}
local text = ''

function E:BuildProfilerText(tbl, data, overall)
for _, info in ipairs(tbl) do
if info.key == '_module' then
local all = E.profiler.data._all
if all then
local total = info.total or 0
local percent = (total / all.total) * 100
text = format('%s%s > count: %d | total: %0.2fms (addon %0.2f%%)\n', text, info.module or '', info.count or 0, total, percent)
end
elseif not overall then
local total = info.total or 0
local modulePercent = (total / data._module.total) * 100

local all, allPercent = E.profiler.data._all
if all then
allPercent = (total / all.total) * 100
end

text = format('%s%s:%s > count: %d | avg: %0.4fms | high: %0.4fms | total: %0.2fms (module %0.2f%% | addon %0.2f%%)\n', text, info.module or '', info.key or '', info.count or 0, info.average or 0, info.high or 0, total, modulePercent, allPercent or 0)
end
end

if not overall then
text = format('%s\n', text)
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, overall)
for key, value in next, data do
local info = CopyTable(value)
info.module = module
info.key = key

tinsert(temp, info)
end

sort(temp, E.ProfilerSort)

E:BuildProfilerText(temp, data, overall)
end

function E:ShowProfilerText()
if text ~= '' then
CH.CopyChatFrameEditBox:SetText(text)
CH.CopyChatFrame:Show()
end

text = ''
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

local function FetchAll(overall)
local data = E.profiler.data[E]
if data then
E:SortProfilerData('E', data, overall)
end

for key, module in next, E.modules do
local info = E.profiler.data[module]
if info then
E:SortProfilerData(key, info, overall)
end
end
end

function E:FetchProfilerData(msg)
local switch = lower(msg)
if switch ~= '' then
if switch == 'reset' then
E.profiler.reset()

return E:Print('Reset profiler.')
elseif switch == 'all' then
FetchAll(true)
elseif switch == 'e' then
local data = E.profiler.data[E]
if data then
E:SortProfilerData('E', data)
end
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
FetchAll()
end

E:ShowProfilerText()
end
end

function E:DisplayCommands()
print(L["EHELP_COMMANDS"])
end
Expand Down Expand Up @@ -251,25 +389,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
4 changes: 2 additions & 2 deletions ElvUI/Core/Modules/Chat/Chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
155 changes: 129 additions & 26 deletions ElvUI/Core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
]]

local _G = _G
local gsub, tinsert, next, type = gsub, tinsert, next, type
local gsub, tinsert, next, type, wipe = gsub, tinsert, next, type, wipe
local tostring, tonumber, strfind, strmatch = tostring, tonumber, strfind, strmatch

local CreateFrame = CreateFrame
Expand All @@ -30,11 +30,114 @@ local SetCVar = C_CVar.SetCVar

-- GLOBALS: ElvCharacterDB, ElvPrivateDB, ElvDB, ElvCharacterData, ElvPrivateData, ElvData

local ProfilerData, ProfilerReset, 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 obj = ProfilerData[object]
if not obj then
obj = { _module = { total = 0, count = 0 } }

ProfilerData[object] = obj
end

local data = obj[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 }
obj[key] = data
end

-- update data
data.start = start
data.finish = finish

local module = obj._module
if module then -- module totals
module.total = module.total + finish
module.count = module.count + 1
module.average = module.total / module.count
end

local all = ProfilerData._all
if all then -- overall totals
all.total = all.total + finish
all.count = all.count + 1
all.average = all.total / all.count
end

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

ProfilerReset = function()
wipe(ProfilerData)

ProfilerData._all = { total = 0, count = 0 }
end

ProfilerReset() -- set up the data

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, reset = ProfilerReset} -- 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)
Expand All @@ -51,30 +154,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
Expand Down

0 comments on commit 035e21a

Please sign in to comment.