diff --git a/ElvUI/Core/General/Commands.lua b/ElvUI/Core/General/Commands.lua index b2ebcced27..e655221ac9 100644 --- a/ElvUI/Core/General/Commands.lua +++ b/ElvUI/Core/General/Commands.lua @@ -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 @@ -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) @@ -163,12 +192,7 @@ do end end - if text ~= '' then - CH.CopyChatFrameEditBox:SetText(text) - CH.CopyChatFrame:Show() - end - - text = '' + E:ShowProfilerText() end end diff --git a/ElvUI/Core/init.lua b/ElvUI/Core/init.lua index e3f47e9cb5..6bf09cb052 100644 --- a/ElvUI/Core/init.lua +++ b/ElvUI/Core/init.lua @@ -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 @@ -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 @@ -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