Skip to content

Commit

Permalink
Merge branch 'release/0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
dualcoding committed Aug 22, 2017
2 parents fa4a40c + bec50fd commit 034bf48
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 95 deletions.
26 changes: 0 additions & 26 deletions CHANGELOG.md

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Niklas Waern

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ A profiler for WoW addons that tries to go deeper.
- Addons can easily improve functionality by exposing local tables globally like so:
`if Profiler then _G.PublicTable = privateTable end`

## Upcoming
- Add column for startup times.
- Make the UI a bit more user friendly and less ugly overall.
## Changes
Want to get an idea of what has changed since last time? I recommend checking out the [release](https://github.com/dualcoding/wow-profiler/releases) page.

## Latest release: [0.3] 2017-08-20
### Added
- Header showing column names
- Column "mem/ncalls" for memory and times called
- The sorting of entries can be changed by clicking on the header
## Roadmap
Want to know what comes next? [Milestones](https://github.com/dualcoding/wow-profiler/milestones) is the place to go to. In particular, have a look at features that are [currently](https://github.com/dualcoding/wow-profiler/milestones/current) in development, and those likely to be worked on [next](https://github.com/dualcoding/wow-profiler/milestones/next).

## Suggestions
Feel free to open issues and pull request, and let me know what you think!
1 change: 1 addition & 0 deletions src/addon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ profiler.events = {

PLAYER_ENTERING_WORLD = function(frame, ...)
profiler.ui.Window:init()
profiler.freezeStartup()
end,

}
Expand Down
37 changes: 36 additions & 1 deletion src/profiling.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
local OUR_NAME, profiler = ...


-- Add some Blizzard functions that we are probably exlusive users of to our namespace
profiler["Blizzard: UpdateAddOnCPUUsage"] = UpdateAddOnCPUUsage
profiler["Blizzard: UpdateAddOnMemoryUsage"] = UpdateAddOnMemoryUsage
profiler["Blizzard: GetFunctionCPUUsage"] = GetFunctionCPUUsage

function profiler.isFirstAddonLoaded()
-- Are any other addons loaded?
for i=1,GetNumAddOns() do
Expand Down Expand Up @@ -76,6 +81,28 @@ function profiler.registerNamespace(name, namespace, parent, seen)
end
end

function profiler.freezeStartup()
-- update the cpu value first
profiler.updateTimes(profiler.namespaces)
for name,addon in pairs(profiler.namespaces) do
profiler.updateTimes(addon)
end

local ns = profiler.namespaces
local stack = {}
repeat
for i=1,#ns do
local x = ns[i]
x.startup = x.cpu
stack[#stack+1] = x.namespace
end
ns = table.remove(stack)
until not ns
end

--
--
--

function profiler.updateTimes(namespace, sortby)
if namespace==profiler.namespaces then
Expand All @@ -101,7 +128,7 @@ function profiler.updateTimes(namespace, sortby)
totalCPU = totalCPU + x.cpu
totalMem = totalMem + (x.mem or 0)
end
sortby = sortby or "cpu"
sortby = sortby or "startup"
if sortby=="cpu" then
table.sort(namespace, function(a,b)
if a.cpu==b.cpu then
Expand All @@ -125,6 +152,14 @@ function profiler.updateTimes(namespace, sortby)
return acalls>bcalls
end
end)
elseif sortby=="startup" then
table.sort(namespace, function(a,b)
if a.startup==b.startup then
return a.name<b.name
else
return a.startup>b.startup
end
end)
end
return totalCPU, totalMem
end
38 changes: 32 additions & 6 deletions src/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,24 @@ function Window:init()
cpu:SetPoint("right")
cpu:SetSize(size.cpu, size.header)
cpu.text = cpu:CreateFontString(nil, "MEDIUM", fonts.text)
cpu.text:SetText("CPU")
cpu.text:SetText("after")
cpu.text:SetPoint("right", -2, 0)
header.cpu = cpu
cpu:SetScript("OnMouseDown", function(...) window.sortby="cpu" end)

local startup
startup = CreateFrame("Frame", nil, header)
startup:SetPoint("right", header.cpu, "left")
startup:SetSize(size.startup, size.header)
startup.text = startup:CreateFontString(nil, "MEDIUM", fonts.text)
startup.text:SetText("startup")
startup.text:SetPoint("right", -2, 0)
header.startup = startup
startup:SetScript("OnMouseDown", function(...) window.sortby="startup" end)

local ncalls
ncalls = CreateFrame("Frame", nil, header)
ncalls:SetPoint("right", header.cpu, "left")
ncalls:SetPoint("right", header.startup, "left")
ncalls:SetSize(size.ncalls, size.header)
ncalls.text = ncalls:CreateFontString(nil, "MEDIUM", fonts.text)
ncalls.text:SetText("mem/ncalls")
Expand Down Expand Up @@ -160,11 +170,21 @@ function Window:init()
cpu.text:SetText("0.0")
columns.cpu = cpu

local startup
startup = CreateFrame("Frame", nil, row)
bgcolor(startup, colors.startupbg)
startup:SetSize(size.startup, size.row)
startup:SetPoint("right", cpu, "left")
startup.text = startup:CreateFontString(nil, "MEDIUM", fonts.value)
startup.text:SetPoint("right", -2, 0)
startup.text:SetText("0")
columns.startup = startup

local ncalls
ncalls = CreateFrame("Frame", nil, row)
bgcolor(ncalls, colors.ncallsbg)
ncalls:SetSize(size.ncalls, size.row)
ncalls:SetPoint("RIGHT", cpu, "LEFT")
ncalls:SetPoint("RIGHT", startup, "LEFT")
ncalls.text = ncalls:CreateFontString(nil, "MEDIUM", fonts.value)
ncalls.text:SetPoint("RIGHT", -2, 0)
ncalls.text:SetText("0")
Expand Down Expand Up @@ -225,6 +245,10 @@ function Window:update()
row.id = info.name
row.columns.name.text:SetText(info.title)
row.columns.cpu.text:SetText(string.format("%6.0fms", info.cpu))
if info.startup then
row.columns.startup.text:SetText(string.format("%6.0fms", info.startup))
row.columns.cpu.text:SetText(string.format("%6.0fms", info.cpu - info.startup))
end
if info.mem then
row.columns.ncalls.text:SetText(string.format("%6.2fmb", info.mem/1024))
elseif info.ncalls then
Expand All @@ -240,10 +264,12 @@ function Window:update()
row.columns.name.text:SetTextColor(0.0, 0.0, 0.0)
end
else
-- The row has no data to show
row.id = nil
row.columns.name.text:SetText("")
row.columns.cpu.text:SetText("")
row.columns.ncalls.text:SetText("")
for name,f in pairs(row.columns) do
-- clear all texts
f.text:SetText("")
end
end
end
end
2 changes: 2 additions & 0 deletions src/ui_data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ui.data.colors = {
namebg = {0.90, 0.90, 0.90, 1.00},
cpubg = {0.90, 0.90, 0.90, 1.00},
ncallsbg = {0.90, 0.90, 0.90, 1.00},
startupbg = {0.90, 0.90, 0.90, 1.00},
}

ui.data.fonts = {
Expand All @@ -42,4 +43,5 @@ ui.data.size = {
row = 15,
cpu = 60,
ncalls = 60,
startup = 60,
}
55 changes: 1 addition & 54 deletions src/ui_utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function ui.utility.edgecolor(frame, color)
left:SetPoint("bottomleft", -1, -1)
left:SetWidth(1)
left:SetColorTexture(unpack(color))

local top = frame:CreateTexture(nil)
top:SetPoint("topleft", -1, 1)
top:SetPoint("topright", 1, 1)
Expand Down Expand Up @@ -52,63 +52,10 @@ end
local bgcolor = ui.utility.bgcolor



-- Placement and sizing

function ui.utility.align(frame, point, anchor, relativeTo, offsets)
local inset, gap, x, y = 0, 0, 0, 0
if offsets then
inset = offsets.inset or 0
gap = offsets.gap or 0
x = offsets.x or 0
y = offsets.y or 0
end
if point=="below" then
local rel = relativeTo or "bottom"
frame:SetPoint("topleft", anchor, rel.."left", inset, -gap)
frame:SetPoint("topright", anchor, rel.."right", -inset, -gap)
elseif point=="above" then
local rel = relativeTo or "top"
frame:SetPoint("bottomleft", anchor, rel.."left", inset, gap)
frame:SetPoint("bottomright", anchor, rel.."right", -inset, gap)
else
local rel = relativeTo or point
if anchor then
frame:SetPoint(point, anchor, rel, x, y)
else
frame:SetPoint(point, x, y)
end
end
end

function ui.utility.size(frame, width, height)
if width then frame:SetWidth(width) end
if height then frame:SetHeight(height) end
return frame
end

function ui.utility.height(frame, height)
frame:SetHeight(height)
return frame
end

function ui.utility.width(frame, width)
frame:SetWidth(width)
return frame
end



-- Elements

function ui.utility.box(parent, bg, name)
local frame = CreateFrame("Frame", name, parent)
if bg then bgcolor(frame, bg) end
return frame
end

function ui.utility.text(parent, text, font)
local fontstring = parent:CreateFontString(nil, "MEDIUM", font)
fontstring:SetText(text)
return fontstring
end

0 comments on commit 034bf48

Please sign in to comment.