feat(debugtools): fold pfDebug in as /profiler

pfDebug was a separate addon that profiled through ClassicAPI's own
APIs: GetAddOnMemoryUsage and GetAddOnCPUUsage, GetFrameCPUUsage,
GetFunctionCPUUsage, GetEventCPUUsage, and the intrinsic precall and
postcall script hooks. Its code now lives in ClassicAPI_DebugTools
under Profiler/, with its MIT notice (Copyright (c) 2018 Shagu). The
analyzer tabs (Addons, Frames, Events, Globals) and the widget are
pfDebug's, with the frame and template names renamed to
ClassicAPIProfiler*.

/profiler and /prof load DebugTools on demand through the same stub as
/dump, then toggle the analyzer. The subcommands widget, reset and
profile on|off are pfDebug's.

What changed in the move:

- The sampler starts only when the widget or the analyzer first opens,
  so a load for /dump costs nothing. It first takes every counter as it
  is, so the first CPU/s and KB/s cover one second, not the session.
- Whether profiling runs is probed, not read from the cvar: a function
  is called once and GetFunctionCPUUsage must count that call. The
  scriptProfile cvar can already hold the next session's value.
- A frame record starts at the frame's current CPU time and call count,
  and opening the analyzer takes every frame and event counter again,
  because the frame totals and the deep hooks keep counting while it is
  closed. pfDebug started records at 0, so the first scan and each
  reopen showed a frame's whole session as one second.
- The /fstack lines (owner, OnUpdate and OnEvent owner and CPU, all
  scripts, deep allocations) are added at the end of
  FrameStackTooltip_OnTooltipSetFrameStack, not by hooking
  OnTooltipSetFrameStack.
- No pfUI skin and no SavedVariables. The plain backdrop is pfDebug's
  own fallback. The widget no longer opens at login, because that would
  load DebugTools at login.

README's Debug tools table gains /profiler and the new /fstack lines.
This commit is contained in:
Brues
2026-10-31 23:16:01 -05:00
parent 4509da0966
commit f19f13d44c
14 changed files with 1762 additions and 2 deletions
@@ -0,0 +1,39 @@
-- /fstack: the owner, script CPU time and allocations of the highlighted
-- frame, which FrameStackTooltip_OnTooltipSetFrameStack adds to the tooltip.
local _, ns = ...
local function Line(tooltip, left, right)
tooltip:AddDoubleLine(left, right, .2, 1, .8, 1, 1, 1)
end
function ns.AddFrameStackLines(tooltip, region)
if not region then return end
-- a texture or font string runs no scripts: report its frame's
local frame = region.GetScript and region or region:GetParent()
tooltip:AddLine(" ")
Line(tooltip, "Owner", ns.OwnerLabel(ns.Owner(region)))
if not frame then return end
for _, script in ipairs({ "OnUpdate", "OnEvent" }) do
local fn = frame:GetScript(script)
if fn then
local text = ns.OwnerLabel(ns.Owner(fn))
if ns.profiling then
local ms, calls = GetFunctionCPUUsage(fn)
text = text .. ns.GREY .. " " .. ns.MS(ms) .. " in " .. ns.Count(calls) .. " calls"
end
Line(tooltip, script, text)
end
end
if ns.profiling then
local ms, calls = GetFrameCPUUsage(frame, false)
Line(tooltip, "All scripts", ns.MS(ms) .. ns.GREY .. " in " .. ns.Count(calls) .. " calls")
end
local rec = ns.track.frames[frame]
if rec and (rec.hookedUpdate or rec.hookedEvent) then
Line(tooltip, "Allocated", ns.KB(rec.alloc) .. ns.GREY .. " (" .. ns.KBRate(rec.allocRate) .. ")")
end
end