Files
ClassicAPI/src/embed/AddOns/ClassicAPI_DebugTools/Profiler/EventsTab.lua
T
8e721237f6 feat(addons): zhCN localization for ClassicAPI_DebugTools and 6 missing globals fix (#141)
* feat(debugtools): add zhCN localization for ClassicAPI_DebugTools

* fix(locales): add 6 missing global strings to zhCN

* feat(debugtools): clean up slash command dispatch and add help subcommand

* fix(debugtools): use %s instead of %d in PROFILER_CALLS_FORMAT

ns.Count() always returns a string (either a formatted number or '-'),
never a number. Feeding it to %d causes format() to throw. Change the
locale template to %s so both '-', '1,234', etc. render correctly.

* fix(debugtools): repair regressions from the localization pass

- XML labels: 1.12's Button/FontString loader passes the text attribute
  verbatim to FrameScript_GetText (0x703BF0), which reads the global of
  exactly that name and falls back to the raw value. Nothing strips
  "$...$", so text="$TI_SHOW$" rendered as literal "$TI_SHOW$". Use the
  bare global name, as stock FrameXML does.
- Tabs: ns.AddTab(name, label) keeps a fixed English key for ns.ShowIn
  and a separate localized button label. Keying tabs by the translated
  name made ShowIn("Globals") return nil and error on a zhCN client.
- Frames tab state: restore visible / "shown, parent hidden" / hidden.
  The inverted branch reported a shown frame under a hidden parent as
  hidden and made the third state unreachable.
- /profiler: unknown or incomplete subcommands print the usage again
  instead of doing nothing.
- Deep Tracking / CPU Profiling buttons: split the label from ON/OFF so
  the state keeps its accent / grey colour.
- Restore the gap between owner and CPU time in the frame-stack and
  Frames-tab tooltips, and the leading space of " (replaced)".
- zhCN: ADDON_OPTIONS titles the shared Interface Options panel and the
  game-menu button, not ClassicAPI's own settings; revert to 插件设置.

---------

Co-authored-by: jilinge <jilinge@users.noreply.github.com>
Co-authored-by: Brues <5278969+brues-code@users.noreply.github.com>
2026-11-13 10:33:01 -06:00

125 lines
3.9 KiB
Lua

-- Events tab: how often each event fires while the analyzer is open, how
-- many frames listen to it, and (deep tracking) what its handlers cost.
local _, ns = ...
local track = ns.track
local function Tracked(fn)
return function(ev)
if track.deep then return fn(ev) end
end
end
local function Line(left, right)
GameTooltip:AddDoubleLine(left, right, 1, 1, 1, 1, 1, 1)
end
local function Tooltip(ev)
GameTooltip:AddLine(ev.name)
Line(PROFILER_LABEL_FIRED, ns.Count(ev.fires) .. ns.GREY .. " (" .. format("%.1f", ev.fireRate or 0) .. "/s)")
if track.deep then
Line(PROFILER_LABEL_HANDLERS_RAN, ns.Count(ev.dispatches))
if ns.profiling then Line(PROFILER_LABEL_HANDLER_CPU, ns.MS(ev.cpu)) end
Line(PROFILER_LABEL_ALLOCATED, ns.KB(ev.alloc))
end
local listeners = {}
for _, frame in ipairs({ GetFramesRegisteredForEvent(ev.name) }) do
if frame ~= track.capture then
local rec = track.frames[frame]
tinsert(listeners, { frame = frame, stat = rec and rec.events[ev.name] })
end
end
if #listeners == 0 then return end
table.sort(listeners, function(a, b)
local ca, cb = a.stat and a.stat.cpu or -1, b.stat and b.stat.cpu or -1
return ca > cb
end)
GameTooltip:AddLine(" ")
GameTooltip:AddLine(PROFILER_LABEL_LISTENERS, 1, .8, 0)
for i = 1, min(#listeners, 15) do
local frame, stat = listeners[i].frame, listeners[i].stat
local text = ns.GREY .. ns.OwnerLabel(ns.Owner(frame:GetScript("OnEvent") or frame))
if stat then
if ns.profiling then text = text .. " " .. ns.WHITE .. ns.MS(stat.cpu) end
text = text .. " " .. ns.WHITE .. ns.KB(stat.alloc)
end
Line(ns.FrameName(frame), text)
end
if #listeners > 15 then
GameTooltip:AddLine(format(PROFILER_MORE_LISTENERS, #listeners - 15), .6, .6, .6)
end
end
local tab = ns.AddTab("Events", PROFILER_TAB_EVENTS)
tab.list = ns.CreateList(tab.frame, {
sort = 2,
columns = {
{
title = PROFILER_EVENTS_COL_EVENT,
text = function(ev) return ev.name end,
value = function(ev) return ev.search end,
},
{
title = PROFILER_EVENTS_COL_FIRES_S, width = 60,
tip = PROFILER_EVENTS_TIP_FIRES_S,
text = function(ev) return ev.fireRate and format("%.1f", ev.fireRate) end,
value = function(ev) return ev.fireRate end,
},
{
title = PROFILER_EVENTS_COL_LISTENERS, width = 60,
tip = PROFILER_EVENTS_TIP_LISTENERS,
text = function(ev) return ev.listeners end,
value = function(ev) return ev.listeners end,
},
{
title = PROFILER_EVENTS_COL_CPU_S, width = 64,
tip = PROFILER_EVENTS_TIP_CPU_S,
text = Tracked(function(ev) return ns.profiling and ns.MS(ev.cpuRate) end),
value = Tracked(function(ev) return ns.profiling and ev.cpuRate or nil end),
},
{
title = PROFILER_EVENTS_COL_ALLOC_S, width = 72,
tip = PROFILER_EVENTS_TIP_ALLOC_S,
text = Tracked(function(ev) return ns.KBRate(ev.allocRate) end),
value = Tracked(function(ev) return ev.allocRate end),
},
{
title = PROFILER_EVENTS_COL_FIRED, width = 64,
tip = PROFILER_EVENTS_TIP_FIRED,
text = function(ev) return ns.Count(ev.fires) end,
value = function(ev) return ev.fires end,
},
},
tooltip = Tooltip,
menu = function(ev, root)
root:CreateTitle(ev.name)
root:CreateButton(PROFILER_EVENTS_MENU_COPY_NAME, function() ns.Copy(ev.name) end)
end,
})
tab.list:SetAllPoints()
local function Update(self)
local entries = {}
for _, ev in pairs(track.events) do tinsert(entries, ev) end
self.list:SetEntries(entries)
end
tab.OnSelect = Update
tab.OnSample = Update
function tab:Status()
local fires = 0
for _, ev in pairs(track.events) do fires = fires + (ev.fireRate or 0) end
local text = format(PROFILER_EVENTS_STATUS, #self.list.entries, fires)
if not track.deep then
return text .. " " .. ns.GOLD .. PROFILER_EVENTS_STATUS_PROMPT
end
return text
end