Skip to content

Commit

Permalink
* Fixed sorting not working correctly when you had include modules en…
Browse files Browse the repository at this point in the history
…abled

* Fixed sorting not using average CPU when scan finished
* Fixed module detection, now attempts to use <parent>_<module> to find the owner first, then it falls back to check if it has only one dependency and associates it that way
* Changed to formating to the second decimal place instead of the first for all stats
* Changed to chat frame background as it's easier to read the text when the frame isn't 70% alpha
  • Loading branch information
Shadowed committed Jun 23, 2009
1 parent ec97cfc commit 8735b10
Showing 1 changed file with 83 additions and 44 deletions.
127 changes: 83 additions & 44 deletions AddonProfiler.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,37 +32,61 @@ local L = {
["Garbage"] = "Garbage", ["Garbage"] = "Garbage",
} }


local memory local memory, garbage, data
local function profileMemory() local function profileMemory()
-- We're done profiling, so force a full garbage collection to get the total GC -- We're done profiling, so force a full garbage collection to get the total GC
if( GetTime() <= profileEndTime ) then if( GetTime() <= profileEndTime ) then
collectgarbage("collect") collectgarbage("collect")
end end


UpdateAddOnMemoryUsage() UpdateAddOnMemoryUsage()
for _, id in pairs(addonList) do profileData[id].totalMemory = 0 end
for _, id in pairs(addonList) do for _, id in pairs(addonList) do
memory = GetAddOnMemoryUsage(id) memory = GetAddOnMemoryUsage(id)
data = profileData[id]


-- Memory was reduced, meaning garbage was created. -- Memory was reduced, meaning garbage was created.
if( memory <= profileData[id].totalMemory ) then if( memory <= data.lastMemory ) then
profileData[id].garbage = profileData[id].garbage + (profileData[id].totalMemory - memory) garbage = data.lastMemory - memory

data.garbage = data.garbage + garbage

if( data.parent ) then
profileData[data.parent].garbage = profileData[data.parent].garbage + garbage
end
end end


profileData[id].totalMemory = memory data.lastMemory = memory
data.totalMemory = data.totalMemory + memory

if( data.parent ) then
profileData[data.parent].totalMemory = profileData[data.parent].totalMemory + memory
end
end end
end end


local cpu, cpuDiff local cpu, cpuDiff
local function profileCPU() local function profileCPU()
UpdateAddOnCPUUsage() UpdateAddOnCPUUsage()

for _, id in pairs(addonList) do profileData[id].totalCPU = 0 end
for _, id in pairs(addonList) do for _, id in pairs(addonList) do
data = profileData[id]
cpu = GetAddOnCPUUsage(id) cpu = GetAddOnCPUUsage(id)
cpuDiff = cpu - profileData[id].totalCPU cpuDiff = cpu - data.lastCPU

data.cpuSecond = cpuDiff
data.cpuAverage = data.cpuAverage + cpuDiff
data.cpuChecks = data.cpuChecks + 1
data.lastCPU = cpu
data.totalCPU = data.totalCPU + cpu


profileData[id].cpuSecond = cpuDiff if( data.parent ) then
profileData[id].cpuAverage = profileData[id].cpuAverage + cpuDiff profileData[data.parent].cpuAverage = profileData[data.parent].cpuAverage + cpuDiff
profileData[id].cpuChecks = profileData[id].cpuChecks + 1 profileData[data.parent].cpuChecks = profileData[data.parent].cpuChecks + 1
profileData[id].totalCPU = cpu profileData[data.parent].cpuSecond = profileData[data.parent].cpuSecond + cpuDiff
profileData[data.parent].totalCPU = profileData[data.parent].totalCPU + cpu
end
end end
end end


Expand Down Expand Up @@ -115,24 +139,40 @@ local function startProfiling()
if( IsAddOnLoaded(id) ) then if( IsAddOnLoaded(id) ) then
local name = GetAddOnInfo(id) local name = GetAddOnInfo(id)
if( not AP.db.filter or AP.db.filter == "" or string.match(name, AP.db.filter) ) then if( not AP.db.filter or AP.db.filter == "" or string.match(name, AP.db.filter) ) then
local requiredDep, hasSecond = GetAddOnDependencies(id) table.insert(addonList, name)
local parent = not hasSecond and requiredDep

profileData[name] = profileData[name] or {} profileData[name] = profileData[name] or {}
profileData[name].totalCPU = GetAddOnCPUUsage(id) profileData[name].lastCPU = GetAddOnCPUUsage(id)
profileData[name].totalMemory = GetAddOnMemoryUsage(id) profileData[name].lastMemory = GetAddOnMemoryUsage(id)
profileData[name].totalCPU = profileData[name].lastCPU
profileData[name].totalMemory = profileData[name].lastMemory
profileData[name].cpuSecond = 0 profileData[name].cpuSecond = 0
profileData[name].cpuAverage = 0 profileData[name].cpuAverage = 0
profileData[name].cpuChecks = 0 profileData[name].cpuChecks = 0
profileData[name].garbage = 0 profileData[name].garbage = 0
profileData[name].parent = parent


-- Indicates that when we display the parents addon, we need to find it's children too -- Indicates that when we display the parents addon, we need to find it's children too
if( parent and AP.db.includeModules ) then if( AP.db.includeModules ) then
hasModules[parent] = true local requiredDep, hasSecond = GetAddOnDependencies(id)
-- Try and detect the parent through (.+)_ blah
local parent
if( not parent and string.match(name, "%_") ) then
local parentName = string.match(name, "(.+)_")
if( parentName and GetAddOnInfo(parentName) and IsAddOnLoaded(parentName) ) then
parent = parentName
end
end

-- Pattern failed, so will default
if( not parent and not hasSecond and requiredDep ) then
parent = requiredDep
end

if( parent ) then
hasModules[parent] = true
profileData[name].parent = parent
end
end end

table.insert(addonList, name)
end end
end end
end end
Expand All @@ -158,6 +198,19 @@ local function stopProfiling()
end end


local function sortAddons(a, b) local function sortAddons(a, b)
-- use average cpu stats not pcu per second when we're not scanning
if( not AP.selectFrame.start.isStarted and sortKey == "cpuSecond" ) then
local aAvg = profileData[a].cpuAverage / profileData[a].cpuChecks
local bAvg = profileData[b].cpuAverage / profileData[b].cpuChecks
if( aAvg == bAvg ) then
return a < b
elseif( not sortOrder ) then
return aAvg < bAvg
end

return aAvg > bAvg
end

if( profileData[a][sortKey] == profileData[b][sortKey] ) then if( profileData[a][sortKey] == profileData[b][sortKey] ) then
return a < b return a < b
elseif( not sortOrder ) then elseif( not sortOrder ) then
Expand All @@ -168,6 +221,7 @@ local function sortAddons(a, b)
end end


local rowList = {} local rowList = {}
local performanceTotals = {}
function AP:UpdateFrame() function AP:UpdateFrame()
if( not AP.frame:IsVisible() ) then return end if( not AP.frame:IsVisible() ) then return end


Expand Down Expand Up @@ -231,38 +285,23 @@ function AP:UpdateFrame()
row:SetText(title) row:SetText(title)
end end


local totalCPU, cpuSecond, cpuAverage, cpuChecks, totalMemory, garbage = profileData[name].totalCPU, profileData[name].cpuSecond, profileData[name].cpuAverage, profileData[name].cpuChecks, profileData[name].totalMemory, profileData[name].garbage
-- Grab all of the modules settings
if( hasModules[name] ) then
for _, data in pairs(profileData) do
if( data.parent == name ) then
totalCPU = totalCPU + data.totalCPU
cpuSecond = cpuSecond + data.cpuSecond
cpuAverage = cpuAverage + data.cpuAverage
cpuChecks = cpuChecks + data.cpuChecks
totalMemory = totalMemory + data.totalMemory
garbage = garbage + data.garbage
end
end
end

-- Set CPU stats if they're enabled -- Set CPU stats if they're enabled
if( cpuProfiling ) then if( cpuProfiling ) then
row.totalCPU:SetFormattedText("%.1f", totalCPU) row.totalCPU:SetFormattedText("%.2f", profileData[name].totalCPU)
row.cpu:SetFormattedText("%.1f", profiling and cpuSecond or (cpuAverage / cpuChecks)) row.cpu:SetFormattedText("%.2f", profiling and profileData[name].cpuSecond or (profileData[name].cpuAverage / profileData[name].cpuChecks))
end end


-- Set memory stats -- Set memory stats
if( totalMemory > 1024 ) then if( profileData[name].totalMemory > 1024 ) then
row.totalMemory:SetFormattedText("%.1f %s", totalMemory / 1024, "MiB") row.totalMemory:SetFormattedText("%.2f %s", profileData[name].totalMemory / 1024, "MiB")
else else
row.totalMemory:SetFormattedText("%.1f %s", totalMemory, "KiB") row.totalMemory:SetFormattedText("%.2f %s", profileData[name].totalMemory, "KiB")
end end


if( garbage > 1024 ) then if( profileData[name].garbage > 1024 ) then
row.garbage:SetFormattedText("%.1f %s", garbage / 1024, "MiB") row.garbage:SetFormattedText("%.2f %s", profileData[name].garbage / 1024, "MiB")
else else
row.garbage:SetFormattedText("%.1f %s", garbage, "KiB") row.garbage:SetFormattedText("%.2f %s", profileData[name].garbage, "KiB")
end end


rowID = rowID + 1 rowID = rowID + 1
Expand All @@ -273,7 +312,7 @@ end
function AP:CreateFrame() function AP:CreateFrame()
if( self.frame ) then return end if( self.frame ) then return end
local backdrop = { local backdrop = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeSize = 1, edgeSize = 1,
insets = {left = 1, right = 1, top = 1, bottom = 1}} insets = {left = 1, right = 1, top = 1, bottom = 1}}
Expand Down Expand Up @@ -350,7 +389,7 @@ function AP:CreateFrame()
row.totalMemory:SetPoint("TOPLEFT", row.cpu, "TOPLEFT", 55, 0) row.totalMemory:SetPoint("TOPLEFT", row.cpu, "TOPLEFT", 55, 0)


row.garbage = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") row.garbage = row:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
row.garbage:SetPoint("TOPLEFT", row.totalMemory, "TOPLEFT", 70, 0) row.garbage:SetPoint("TOPLEFT", row.totalMemory, "TOPLEFT", 75, 0)


if( id > 1 ) then if( id > 1 ) then
row:SetPoint("TOPLEFT", self.rows[id - 1], "BOTTOMLEFT", 0, -2) row:SetPoint("TOPLEFT", self.rows[id - 1], "BOTTOMLEFT", 0, -2)
Expand Down

0 comments on commit 8735b10

Please sign in to comment.