Files

181 lines
9.6 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Frame-time probe: no Blizzard globals touched, no per-frame work unless a run is active.
local f = CreateFrame("Frame")
local samples, started, duration, n = {}, 0, 60, 0
local function finish()
f:SetScript("OnUpdate", nil)
table.sort(samples)
local total = 0
for i = 1, n do total = total + samples[i] end
local function pct(p) return samples[math.max(1, math.floor(n * p))] or 0 end
local onePctLow = 0
local k = math.max(1, math.floor(n * 0.01))
for i = n - k + 1, n do onePctLow = onePctLow + samples[i] end
onePctLow = onePctLow / k
local r = {
api = GetCVar("gxApi"), quality = GetCVar("graphicsQuality"), frames = n,
avg_fps = n / total, low1_fps = 1 / onePctLow,
p50_ms = pct(0.5) * 1000, p99_ms = pct(0.99) * 1000, worst_ms = samples[n] * 1000,
zone = GetRealZoneText(), when = date("%Y-%m-%d %H:%M:%S"),
}
OctoFrameProbeDB = OctoFrameProbeDB or {}
table.insert(OctoFrameProbeDB, r)
print(string.format("|cff33ff99FrameProbe|r %s: avg %.1f fps, 1%% low %.1f fps, p99 %.1f ms, worst %.1f ms (%d frames)",
r.api, r.avg_fps, r.low1_fps, r.p99_ms, r.worst_ms, n))
end
SLASH_OCTOFRAMEPROBE1 = "/fpsprobe"
SlashCmdList.OCTOFRAMEPROBE = function(msg)
duration = tonumber(msg) or 60
samples, n, started = {}, 0, GetTime()
print("|cff33ff99FrameProbe|r recording " .. duration .. "s on " .. GetCVar("gxApi") .. " - stand still")
f:SetScript("OnUpdate", function(_, elapsed)
n = n + 1; samples[n] = elapsed
if GetTime() - started >= duration then finish() end
end)
end
-- /fpsprobe addons: per-addon script time from the client's own C_AddOnProfiler (read-only).
local function addonReport()
local P, M = C_AddOnProfiler, Enum and Enum.AddOnProfilerMetric
if not (P and M and P.GetAddOnMetric) then print("|cff33ff99FrameProbe|r no C_AddOnProfiler in this client"); return end
local rows = {}
for i = 1, C_AddOns.GetNumAddOns() do
local name = C_AddOns.GetAddOnInfo(i)
if name and C_AddOns.IsAddOnLoaded(i) then
local peak = P.GetAddOnMetric(name, M.PeakTime) or 0
rows[#rows + 1] = {name = name, peak = peak,
avg = P.GetAddOnMetric(name, M.SessionAverageTime) or 0,
over100 = M.CountTimeOver100Ms and P.GetAddOnMetric(name, M.CountTimeOver100Ms) or 0,
over10 = M.CountTimeOver10Ms and P.GetAddOnMetric(name, M.CountTimeOver10Ms) or 0}
end
end
table.sort(rows, function(a, b) return a.peak > b.peak end)
local saved = {when = date("%Y-%m-%d %H:%M:%S"), enabled = P.IsEnabled and P.IsEnabled() or "?", addons = rows,
app_peak = P.GetApplicationMetric and P.GetApplicationMetric(M.PeakTime) or -1,
overall_peak = P.GetOverallMetric and P.GetOverallMetric(M.PeakTime) or -1}
OctoFrameProbeDB = OctoFrameProbeDB or {}
OctoFrameProbeDB.addons = saved
print(string.format("|cff33ff99FrameProbe|r addon profiler enabled=%s, all-addons peak %.0f ms, app peak %.0f ms",
tostring(saved.enabled), saved.overall_peak, saved.app_peak))
for i = 1, math.min(8, #rows) do
local r = rows[i]
print(string.format(" %s: peak %.0f ms, avg %.2f ms/frame, >10ms %d, >100ms %d", r.name, r.peak, r.avg, r.over10, r.over100))
end
end
local baseSlash = SlashCmdList.OCTOFRAMEPROBE
SlashCmdList.OCTOFRAMEPROBE = function(msg)
if msg and msg:lower():match("^%s*addons") then addonReport() else baseSlash(msg) end
end
-- Event census from load (cheap counter) + /fpsprobe cpu (needs /console scriptProfile 1 and a /reload).
local census, censusStart, bursts = {}, (GetTimePreciseSec or GetTime)(), {}
local clock = GetTimePreciseSec or GetTime
local ev = CreateFrame("Frame")
ev:RegisterAllEvents()
ev:SetScript("OnEvent", function(_, event)
census[event] = (census[event] or 0) + 1
local sec = math.floor(clock() - censusStart)
bursts[sec] = (bursts[sec] or 0) + 1
end)
local function cpuReport()
local rows, ev_rows = {}, {}
for name, n in pairs(census) do
local t = (GetEventCPUUsage and GetEventCPUUsage(name)) or 0
ev_rows[#ev_rows + 1] = {event = name, count = n, cpu_ms = t}
end
table.sort(ev_rows, function(a, b) return (a.cpu_ms * 1e6 + a.count) > (b.cpu_ms * 1e6 + b.count) end)
if UpdateAddOnCPUUsage then UpdateAddOnCPUUsage() end
for i = 1, C_AddOns.GetNumAddOns() do
local name = C_AddOns.GetAddOnInfo(i)
if name and C_AddOns.IsAddOnLoaded(i) then rows[#rows + 1] = {name = name, cpu_ms = GetAddOnCPUUsage and GetAddOnCPUUsage(i) or 0} end
end
table.sort(rows, function(a, b) return a.cpu_ms > b.cpu_ms end)
local busiest = {}
for sec, n in pairs(bursts) do busiest[#busiest + 1] = {sec = sec, events = n} end
table.sort(busiest, function(a, b) return a.events > b.events end)
while #busiest > 15 do table.remove(busiest) end
local top = {}
for i = 1, math.min(40, #ev_rows) do top[i] = ev_rows[i] end
OctoFrameProbeDB = OctoFrameProbeDB or {}
OctoFrameProbeDB.cpu = {when = date("%Y-%m-%d %H:%M:%S"), scriptProfile = GetCVar("scriptProfile"),
uptime_s = clock() - censusStart, addons = rows, events = top, busiest_seconds = busiest}
print(string.format("|cff33ff99FrameProbe|r scriptProfile=%s, %d event types seen. Top events:", tostring(GetCVar("scriptProfile")), #ev_rows))
for i = 1, math.min(6, #ev_rows) do local r = ev_rows[i]; print(string.format(" %s x%d, %.0f ms", r.event, r.count, r.cpu_ms)) end
for i = 1, math.min(5, #rows) do print(string.format(" addon %s: %.0f ms", rows[i].name, rows[i].cpu_ms)) end
print("|cff33ff99FrameProbe|r saved; /reload or log out to write it to disk")
end
local prevSlash = SlashCmdList.OCTOFRAMEPROBE
SlashCmdList.OCTOFRAMEPROBE = function(msg)
if msg and msg:lower():match("^%s*cpu") then cpuReport() else prevSlash(msg) end
end
-- Action-bar audit: which slots hold what, and whether the client treats the spell as known.
local function barsReport()
OctoFrameProbeDB = OctoFrameProbeDB or {}
local out = {time = time(), slots = {}}
for slot = 1, 180 do
local ok, kind, id, sub = pcall(GetActionInfo, slot)
if ok and kind then
local r = {slot = slot, kind = tostring(kind), id = tonumber(id) or tostring(id), sub = sub and tostring(sub)}
if kind == "spell" and type(id) == "number" then
r.player = IsPlayerSpell and IsPlayerSpell(id) or nil
r.known = C_SpellBook and C_SpellBook.IsSpellKnown and C_SpellBook.IsSpellKnown(id) or nil
local info = C_Spell.GetSpellInfo(id)
r.name = info and info.name; r.icon = info and info.iconID
end
local okT, tex = pcall(GetActionTexture, slot); r.texture = okT and tex or nil
out.slots[#out.slots + 1] = r
end
end
OctoFrameProbeDB.bars = out
print(("OctoFrameProbe: %d bar slots recorded"):format(#out.slots))
end
local barsFrame = CreateFrame("Frame")
barsFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
barsFrame:SetScript("OnEvent", function(self) self:UnregisterAllEvents(); barsReport(); C_Timer.After(30, barsReport) end)
local prevSlash2 = SlashCmdList.OCTOFRAMEPROBE
SlashCmdList.OCTOFRAMEPROBE = function(msg)
if msg and msg:lower():match("^%s*bars") then barsReport() else prevSlash2(msg) end
end
-- Login stall attribution: time between consecutive events and frames from load until 180 s after PLAYER_LOGIN.
do
local now = debugprofilestop
local t0, last, lastName, lastArg = now(), now(), "LOAD", nil
local gaps, frames, counts, stop = {}, {}, {}, nil
local lastFrame = now()
local f = CreateFrame("Frame")
local function keep(list, entry, cap)
list[#list + 1] = entry
if #list > cap * 2 then table.sort(list, function(a, b) return a.ms > b.ms end); for i = #list, cap + 1, -1 do list[i] = nil end end
end
f:RegisterAllEvents()
f:SetScript("OnEvent", function(_, event, a1)
local t = now()
if stop and t > stop then return end
keep(gaps, {ms = t - last, after = lastName, arg = lastArg, at = (t - t0) / 1000}, 40)
counts[event] = (counts[event] or 0) + 1
last, lastName = t, event
lastArg = (type(a1) == "string" or type(a1) == "number") and (not issecretvalue or not issecretvalue(a1)) and tostring(a1):sub(1, 40) or nil
if event == "ADDON_LOADED" and a1 == "OctoFrameProbe" then
OctoFrameProbeDB = OctoFrameProbeDB or {}
OctoFrameProbeDB.login = {gaps = gaps, frames = frames, counts = counts, when = date("%Y-%m-%d %H:%M:%S")}
end
if event == "PLAYER_LOGIN" then stop = t + 180000 end
if event == "PLAYER_LOGOUT" then
table.sort(gaps, function(a, b) return a.ms > b.ms end); for i = #gaps, 41, -1 do gaps[i] = nil end
table.sort(frames, function(a, b) return a.ms > b.ms end); for i = #frames, 41, -1 do frames[i] = nil end
local c = {}; for k, v in pairs(counts) do c[#c + 1] = {event = k, n = v} end
table.sort(c, function(a, b) return a.n > b.n end); for i = #c, 61, -1 do c[i] = nil end
OctoFrameProbeDB = OctoFrameProbeDB or {}
OctoFrameProbeDB.login = {gaps = gaps, frames = frames, counts = c, when = date("%Y-%m-%d %H:%M:%S")}
end
end)
f:SetScript("OnUpdate", function()
local t = now()
if not stop or t <= stop then keep(frames, {ms = t - lastFrame, at = (t - t0) / 1000, lastEvent = lastName}, 40) end
lastFrame = t
end)
end