Skip to content

Commit

Permalink
more data for profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
kodewdle committed Nov 13, 2024
1 parent 4f73d22 commit 1aede93
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
50 changes: 37 additions & 13 deletions ElvUI/Core/General/Commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,30 @@ do
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)
function E:BuildProfilerText(tbl, data)
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
else
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

text = format('%s\n', text)

wipe(temp)
wipe(list)
end
Expand All @@ -101,15 +120,25 @@ do

function E:SortProfilerData(module, data)
for key, value in next, data do
local clean = CopyTable(value)
clean.name = module..':'..key
local info = CopyTable(value)
info.module = module
info.key = key

tinsert(temp, clean)
tinsert(temp, info)
end

sort(temp, E.ProfilerSort)

E:ShowProfilerData(temp)
E:BuildProfilerText(temp, data)
end

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

text = ''
end

function E:GetProfilerData(msg)
Expand Down Expand Up @@ -163,12 +192,7 @@ do
end
end

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

text = ''
E:ShowProfilerText()
end
end

Expand Down
30 changes: 23 additions & 7 deletions ElvUI/Core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local SetCVar = C_CVar.SetCVar

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

local ProfilerData, Profiler = {}
local ProfilerData, Profiler = { _all = { total = 0, count = 0 } }
do -- not finished
local rawset = rawset
local unpack = unpack
Expand All @@ -47,13 +47,14 @@ do -- not finished
local args = { func(...) }
local finish = debugprofilestop() - start

local info = ProfilerData[object]
if not info then
info = {}
ProfilerData[object] = info
local obj = ProfilerData[object]
if not obj then
obj = { _module = { total = 0, count = 0 } }

ProfilerData[object] = obj
end

local data = info[key]
local data = obj[key]
if data then
data.count = data.count + 1

Expand All @@ -69,12 +70,27 @@ do -- not finished
data.average = data.total / data.count
else
data = { high = finish, low = finish, total = 0, count = 1 }
ProfilerData[object][key] = data
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
Expand Down

0 comments on commit 1aede93

Please sign in to comment.