Add Commander as optional dependency and make the profiler use Commander
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
## Notes: Frames that work for me
|
## Notes: Frames that work for me
|
||||||
## SavedVariables: OmicronFramesDB
|
## SavedVariables: OmicronFramesDB
|
||||||
## Version: 0.1.0-alpha
|
## Version: 0.1.0-alpha
|
||||||
|
## OptionalDeps: Commander
|
||||||
|
|
||||||
main.lua
|
main.lua
|
||||||
|
|
||||||
|
@@ -16,23 +16,35 @@
|
|||||||
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
|
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
|
||||||
local addonName, omi = ...
|
local addonName, omi = ...
|
||||||
|
|
||||||
local public = omi.GetModule("public")
|
-- Profiler is only active if the optional Commander dependency is included
|
||||||
|
if not Commander then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local PrintLn = Commander.PrintLn
|
||||||
|
local Printf = Commander.Printf
|
||||||
|
|
||||||
local types = omi.GetModule("types")
|
local types = omi.GetModule("types")
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
function public.StartProfiler()
|
Commander.RegisterCommand("omi-pstart", {
|
||||||
|
description="Start/reset the OmicronFrames profiler",
|
||||||
|
command=function()
|
||||||
local profiler = C_CVar.GetCVar("scriptProfile")
|
local profiler = C_CVar.GetCVar("scriptProfile")
|
||||||
if profiler ~= "1" then
|
if profiler ~= "1" then
|
||||||
print("scriptProfiler is off", profiler)
|
PrintLn("scriptProfiler is off")
|
||||||
print("set it to on with `/console scriptProfile 1`, then reload the UI.")
|
PrintLn("set it to on with `/console scriptProfile 1`, then reload the UI.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
print("OmicronFrames: start profiling")
|
PrintLn("OmicronFrames: start profiling")
|
||||||
ResetCPUUsage()
|
ResetCPUUsage()
|
||||||
end
|
end
|
||||||
|
})
|
||||||
|
|
||||||
function public.StopProfiler()
|
Commander.RegisterCommand("omi-pstop", {
|
||||||
print("OmicronFrames: stop profiling")
|
description="Stop the OmicronFrames profiler",
|
||||||
|
command=function()
|
||||||
|
PrintLn("OmicronFrames: stop profiling")
|
||||||
UpdateAddOnCPUUsage()
|
UpdateAddOnCPUUsage()
|
||||||
local total = GetAddOnCPUUsage(addonName)
|
local total = GetAddOnCPUUsage(addonName)
|
||||||
data = {{
|
data = {{
|
||||||
@@ -56,55 +68,14 @@ function public.StopProfiler()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(data, function(a, b) return a.time > b.time end)
|
table.sort(data, function(a, b) return a.time > b.time end)
|
||||||
end
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
local profileFrame
|
Commander.RegisterCommand("omi-pprint", {
|
||||||
local profileText
|
description="Print the collected OmicronFrames profiling data",
|
||||||
|
command=function()
|
||||||
function public.PrintProfilerData()
|
|
||||||
profileFrame:Show()
|
|
||||||
profileText:SetText("")
|
|
||||||
for _, item in ipairs(data) do
|
for _, item in ipairs(data) do
|
||||||
local line = string.format("% 5.1f%% % 5fms %s\n", item.pct*100, item.time, item.name)
|
Printf("% 5.1f%% % 5fms %s\n", item.pct*100, item.time, item.name)
|
||||||
profileText:Insert(line)
|
|
||||||
end
|
end
|
||||||
profileText:SetFocus()
|
|
||||||
end
|
end
|
||||||
|
})
|
||||||
local function CreateProfileFrame()
|
|
||||||
profileFrame = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
|
|
||||||
local frame = profileFrame
|
|
||||||
frame.backdropInfo = {
|
|
||||||
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
|
|
||||||
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
|
||||||
tile = true,
|
|
||||||
tileEdge = true,
|
|
||||||
tileSize = 8,
|
|
||||||
edgeSize = 8,
|
|
||||||
insets = { left = 1, right = 1, top = 1, bottom = 1 },
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Output wrap
|
|
||||||
frame:ApplyBackdrop()
|
|
||||||
frame:SetBackdropColor(0, 0, 0, 1)
|
|
||||||
frame:SetSize(640, 480)
|
|
||||||
frame:SetPoint("TOPRIGHT")
|
|
||||||
frame:SetFrameStrata("DIALOG")
|
|
||||||
frame:Hide()
|
|
||||||
|
|
||||||
local scrollFrame = CreateFrame("ScrollFrame", nil, frame, "UIPanelScrollFrameTemplate")
|
|
||||||
scrollFrame:SetSize(640-16-20, 480-16)
|
|
||||||
scrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 8, -8)
|
|
||||||
|
|
||||||
profileText = CreateFrame("EditBox", nil, scrollFrame)
|
|
||||||
profileText:SetFontObject(ChatFontNormal)
|
|
||||||
profileText:SetWidth(640-16-20)
|
|
||||||
profileText:SetMultiLine(true)
|
|
||||||
profileText:SetAutoFocus(false)
|
|
||||||
scrollFrame:SetScrollChild(profileText)
|
|
||||||
|
|
||||||
profileText:SetScript("OnEscapePressed", function(self)
|
|
||||||
frame:Hide()
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
omi.SetEventHandler("OMICRON_LOADING", CreateProfileFrame)
|
|
||||||
|
Reference in New Issue
Block a user