Files
ClassicAPI/src/frame/ScriptSlots.h
T
Brues 6c5269e3e6 feat(profiling): add per-addon memory and CPU usage
Backport UpdateAddOnMemoryUsage / GetAddOnMemoryUsage and the script
profiling family (scriptProfile, GetFunctionCPUUsage, UpdateAddOnCPUUsage,
GetAddOnCPUUsage, GetFrameCPUUsage, GetEventCPUUsage, GetScriptCPUUsage,
ResetCPUUsage), mirroring 3.3.5's engine mechanism.

- Gc::Hooks owns the GC lifecycle hooks (luaC_link, newlstr,
  luaS_newudata, freeobj); Gc::Tag stamps each new object with the
  engine's context word (3.3.5's lua_tainted rule) and sums sizes with
  the engine's own free sizes.
- lua_gctag pins: the addon load window (two call patches in
  FUN_ADDON_LOAD_ONE) and template application (engine single-name
  sites + Xml::Inherits lists).
- Profile::Cpu keeps 3.3.5's per-closure Profile records through Lua's
  own call/return hook, installed only when scriptProfile is 1; tail
  calls, error unwinds and coroutines handled.
- ScriptArgs observers time every handler run; signals counted at each
  dispatcher (call-site redirect inside FUN_FIRE_EVENT, not a MinHook).
- Frame::ScriptSlots enumerates a frame's script slots without creating
  them, for GetFrameCPUUsage.
- Add the unordered_dense submodule (v5.3.2); share ResolveRecord via
  addons/Registry; fix the AddOnEntry inline-name comments.
2026-10-23 15:31:39 -05:00

46 lines
1.9 KiB
C++

// This file is part of ClassicAPI.
//
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <cstdint>
// Every script slot a frame holds — 4.3.4's per-class GetScriptTime walks
// its own slot members; 1.12 exposes a frame's slots only by name, through
// the script-name resolver at vtable slot 0xC (FUN_FRAME_SCRIPT_RESOLVER and
// each type's extension of it). `ForEach` asks it for every name the client's
// frame types define (benilla-re ui/xmltypes "Handler names by type", plus
// the base object's OnEvent and GameTooltip's three).
//
// Scripts ClassicAPI adds keep their slots outside the frame, and their
// resolver co-hooks CREATE a slot when asked for a name — right for
// SetScript, wrong for a read that visits every frame. So each such store
// registers an enumerator over the slots it already holds:
// static const Frame::ScriptSlots::AutoRegister _slots{&ForEachSlot};
namespace Frame::ScriptSlots {
// `slot` is the {handler ref, exec context} pair; the handler may be 0.
using Visit = void (*)(const uint32_t *slot, void *ctx);
using Enumerator = void (*)(const void *frame, Visit visit, void *ctx);
struct AutoRegister {
explicit AutoRegister(Enumerator fn);
Enumerator fn;
AutoRegister *next;
};
void ForEach(void *frame, Visit visit, void *ctx);
} // namespace Frame::ScriptSlots