profiler
Frame-level profiler capture, EMA stats, and named profiling blocks.
require("@builtin::modules.api.engine.profiler") -- profiler (also available as global 'profiler')
The profiler namespace: 68 functions.
globals/profiler/begin
profiler.begin(name: string)
Start a named profiling block. Call profiler.finish(name) to
record the duration. Blocks appear in profiler.stats() under
"script.<name>" and inside captures.
Parameters
namestring— Block name (e.g. "MyComponent.update").
profiler.begin("MyComponent.update"); ...; profiler.finish()
globals/profiler/captureFrames
profiler.captureFrames(label: string?, first: number?, count: number?) -> ({ CaptureFrame }?, string?)
Frames first .. first + count - 1 (numbered from 1) of a
stored capture, each { frame, total_ms, agent_ms, capture_ms, capture, cpu_ms, wait_ms, gpu_ms, t_ms, systems, agent_by_caller }
built straight from its records, frame numbered from 0 within the
capture. capture marks a capture frame: one that spent
capture_ms drawing renders a caller's tool call asked for or
copying their readbacks, or ran while such a readback was in flight
on the GPU. cpu_ms,
wait_ms and gpu_ms are the engine thread's CPU time, its wait
for a core and the engine's GPU time, each absent where the platform
gives none (frameCost says why). A read takes the memory of the
frames it asks for, so a long capture read a page at a time holds
one page at once. Empty past the capture's last frame.
Parameters
labelstring(optional) — The capture's label (default: the last completed capture).firstnumber(optional) — The first frame to read, from 1 (default 1).countnumber(optional) — How many frames to read (default: every frame fromfirst).
Returns ({ CaptureFrame }?, string?) — The frames, or nil and why there is no such capture, as profiler.captureInfo states it.
local page, why = profiler.captureFrames("combat", 1, 64)
globals/profiler/captureInfo
profiler.captureInfo(label: string?) -> (CaptureInfo?, string?)
A stored capture (a stopped recording, a retro snapshot or
drained watchdog hits) without its frames: { label, frame_count, started_at, ended_at, source, summary, callers, bytes, budget_bytes, dropped_for_budget, let_go, frame_cost }, the fields of
stopCapture but frames; frame_cost is the
profiler.frameCost report of its frames. It costs a few
kilobytes however many frames the capture holds; read them with
profiler.captureFrames. When there is no such capture it
answers nil and why: the capture was let go to keep the stored
captures inside their bound, no capture is stored under the
label, or none has completed yet.
Parameters
labelstring(optional) — The capture's label (default: the last completed capture).
Returns (CaptureInfo?, string?) — The capture's header, or nil and why there is none.
local info, why = profiler.captureInfo("combat")
globals/profiler/captureSeries
profiler.captureSeries(label: string?, series: "memory" | "gpu" | "jobs" | "hitches", first: number?, count: number?) -> (CaptureSeriesPage?, string?)
Items first .. first + count - 1 (from 1) of one series of a
stored capture, as { total, items }: "memory" (a recording at the
memory level or above; each item a CaptureMemorySample), "gpu"
(a comprehensive recording; each a CaptureGpuFrame), "jobs" (a
comprehensive recording; each a CaptureJob, in the order they
started) or "hitches" (every capture; each a CaptureHitch, the
frames at twice the median and 8 ms above it with the keys that took
the most of them and the jobs that ran across them). A series the capture's level did
not keep answers nil and the level that keeps it.
Parameters
labelstring(optional) — The capture's label (nil: the last completed capture).series"memory" | "gpu" | "jobs" | "hitches"—"memory","gpu","jobs"or"hitches".firstnumber(optional) — The first item to read, from 1 (default 1).countnumber(optional) — How many items to read (default: every item fromfirst).
Returns (CaptureSeriesPage?, string?) — The page, or nil and why there is none.
local mem = profiler.captureSeries("bench", "memory")
for _, m in mem.items do print(m.t_ms, m.private_bytes, m.vms.user.live_bytes) end
globals/profiler/counters
profiler.counters(pattern: string?) -> { ProfilerCount }
Get the profiler's counts: unitless per-frame tallies (for example
the waits the engine thread made on the process-wide lock, under
system.schedule.frame.process_local_waits), kept apart from the
millisecond timings of stats. frame is the tally of the frame in
progress, prev_frame the last complete frame's, max_frame the
highest complete-frame tally and total the tally since the profiler
started. Optional glob pattern filters by name (supports * and ?).
Parameters
patternstring(optional) — Filter pattern (e.g. "system.schedule.frame.*").
Returns { ProfilerCount } — Array of profiler counts.
for _, c in ipairs(profiler.counters("system.schedule.frame.*")) do print(c.name, c.prev_frame) end
globals/profiler/disableRing
profiler.disableRing()
Disable the ring buffer and clear its history.
profiler.disableRing()
globals/profiler/enableRing
profiler.enableRing(seconds: number?) -> boolean
Enable the always-recording ring buffer, retaining the last
seconds of per-frame data (default 20, 1 to 600) at any frame
rate, within a fixed memory budget (budget_bytes of
profiler.ringStatus(), 32 MiB): once the window's frames would
take more, the oldest leave first and dropped_for_budget counts
them. Query it AFTER the fact with profiler.retro() —
latency-immune, since the data is historical. Editor profile only:
returns false in the runtime profile. The enable is the gate; the
ring costs nothing until on. memory.report() states what the
frames hold as profiler.frames.
Parameters
secondsnumber(optional) — Seconds of history to retain (default 20, 1 to 600).
Returns boolean — True if enabled, false if refused (runtime profile).
if profiler.enableRing(30) then ... end
globals/profiler/exportCapture
profiler.exportCapture(label: string?, format: "json" | "csv" | "trace" | "stacks" | "scopes" | "stacksSvg" | "scopesSvg") -> (CaptureExport?, string?)
Where a stored capture reads out in format: a file of
/zero/runtime/profiler/, generated when it is read. "json" is the
whole capture (header, frames, series, hitches); "csv" one row per
frame with its times, counts, memory, each schedule's time and each
profiler count it tallied;
"trace" trace-event JSON Perfetto and chrome://tracing open
(frames as spans; schedules, memory, Luau heaps and GPU passes as
counter tracks; each pool worker's jobs as spans on a track of its
own; hitches as markers); "stacks" the sampled Luau
stacks folded root first (frame;frame;... microseconds, the form
speedscope, inferno and flamegraph.pl read); "scopes" the
engine's timed scopes folded, each by its own time in microseconds;
"stacksSvg" and "scopesSvg" the same drawn as a flame graph, an
SVG a browser opens (each frame as wide as its time, its time and
share in its tooltip).
The file is read from outside the engine like any VFS file (the
proxy's download_file, GET /engine/vfs/<path>), so a long capture
never passes through a call's answer.
Parameters
labelstring(optional) — The capture's label (nil: the last completed capture).format"json" | "csv" | "trace" | "stacks" | "scopes" | "stacksSvg" | "scopesSvg"—"json","csv","trace","stacks","scopes","stacksSvg"or"scopesSvg".
Returns (CaptureExport?, string?) — { path, format, bytes }, or nil and why: no such capture, or stacks a recording below comprehensive (or an engine with no sampler) did not take.
local trace = profiler.exportCapture("bench", "trace")
local flame = profiler.exportCapture("bench", "scopesSvg") -- an SVG a browser opens
globals/profiler/finish
profiler.finish(name: string?) -> number?
Finish a profiling block and record the elapsed duration as
"script.<name>". Without an argument, closes the most-recently-
begun block (LIFO stack). With a name, closes the most recent
block whose name matches — useful when blocks of different names
are nested.
Parameters
namestring(optional) — Block name to finish. Omit to pop the top of the stack.
Returns number? — Elapsed milliseconds, or nil if no matching block was active.
local ms = profiler.finish("MyComponent.update")
globals/profiler/frameCost
profiler.frameCost(opts: FrameCostOptions?) -> FrameCostReport
What the engine itself spent per frame over a window, beside the
wall time, so a frame cost read on a machine shared with other work
names how much of each frame was the engine and how much the
machine. With opts.seconds (default 5) it measures the frames of
the next that many seconds of wall clock and returns when they have
run (the calling task waits on the wall clock, so the window has the
same length at every engine.timeScale, 0 included; GPU timing runs
for the window); with
opts.last it reads the frames of the last that many seconds the
engine already holds, at once. cpu is the engine thread's CPU time
per frame from the thread's own clock (source = "thread_clock";
in a browser the worker's own time, the frame less the host's
waiting and busy, source = "worker", which still holds the
worker's waits for a core). waitingForCore is the
time per frame the thread was ready to run and waited for a core
other processes held, with its share of the wall time. gpu.own
is the engine's own GPU time per frame: the GPU driver's account of
the process on the busiest of the GPU's engines where it gives one
(drm_fdinfo), otherwise the
engine's timed passes (timestamp_queries, which other clients'
work on a busy GPU lengthens). hostBoundFps is the frame rate the
world would hold with the machine to itself, 1000 over the larger of
cpu.mean and gpu.own.mean, beside fps, the rate it ran at.
build, luau and drawn name the engine that produced the
numbers. Frames that drew a capture a caller's tool call asked for
are left out and counted under excluded.capture. A caller's queued
work (an execute, the shell command reading the window) is taken
out of the wall and CPU time of the frames it ran in, so a window
read from the shell or a running call measures the world's frames;
a frame that spent half its wall time or more on it is left out and
counted under excluded.callerWork. A figure the platform does not give carries
available = false and the platform's reason, never a zero.
Parameters
optsFrameCostOptions(optional) —{ seconds = n }to measure the next n seconds (default 5, at most 120), or{ last = n }to read the last n seconds held.
Returns FrameCostReport — The window's frame cost.
local r = profiler.frameCost({ seconds = 10 }); print(r.fps, r.cpu.mean, r.waitingForCore.mean, r.hostBoundFps)
local r = profiler.frameCost({ last = 5 })
globals/profiler/gpuFrame
profiler.gpuFrame() -> GpuFrameReport
Label-aggregated GPU pass timings over the last window_frames
resolved frames, measured with GPU timestamp queries. supported
is false when the device lacks timestamp queries — spans stays
empty. Each span covers every render/compute pass recorded under
one label — compute.<shader> per compute dispatch, scene.* for
the scene passes, post.<effect> per post-process effect,
feature.* for render-feature passes: ms is the median of its
per-frame totals, min_ms/max_ms the range that median sits in,
count the passes per frame and frames how much of the window
carried it. at_floor marks a label whose every sample landed
within a few ticks of the device's timestamp counter (tick_ms) —
those passes ran and the device resolved no duration for them,
which is not the same as a measured zero. ran is whether the
label recorded a measured pass in the newest resolved frame, and
last_frame the newest frame that did. The window outlives the
work it describes, so a pass that stops being recorded leaves a row
standing for up to window_frames frames carrying the median of
the frames it did run in: read ran to answer whether a pass is
running, frame - last_frame for how many resolved frames ago it
last did, and ms as the cost of the frames it ran in.
frame_span_ms (first pass begin to last pass end) and
total_ms are medians too, so
rows do not sum to total_ms, and the GPU may overlap passes so
total_ms can exceed frame_span_ms. The readback is
asynchronous: the window lags the live frame by a few frames.
Returns GpuFrameReport — GPU timing window, spans ranked by median ms descending.
local g = profiler.gpuFrame(); print(g.frame_span_ms, g.spans[1] and g.spans[1].label)
globals/profiler/hits
profiler.hits(label: string?, opts: StopCaptureOptions?) -> string?
Drain the watchdog's recorded hit frames into a capture stored
under label (default "watch_hits") and clear the buffer.
Returns the capture JSON (same shape as stopCapture), or nil if
there were no hits. opts.frames = false leaves frames out; read
them a page at a time with profiler.captureFrames(label, first, count).
Parameters
labelstring(optional) — Capture label to store under (default "watch_hits").optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — Capture JSON of the hit frames, or nil if none.
local json = profiler.hits()
local head = profiler.hits("collapse", { frames = false })
globals/profiler/isCapturing
profiler.isCapturing() -> boolean
Check if a profiler capture is currently active.
Returns boolean — True if a capture is in progress.
if profiler.isCapturing() then ... end
globals/profiler/lastCapture
profiler.lastCapture(opts: StopCaptureOptions?) -> string?
Get the most recent completed capture result as a JSON string.
Same shape as profiler.stopCapture(). Returns nil if no capture
has been completed yet. opts.frames = false leaves frames out;
read them a page at a time with profiler.captureFrames.
Parameters
optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — JSON string of the last capture, or nil.
local last = profiler.lastCapture()
local head = profiler.lastCapture({ frames = false })
globals/profiler/perfLine
profiler.perfLine() -> string?
The engine's own one-line performance summary, exactly as it
rides a tool response: the headline frame time, and when the frame
is slow or CPU moved since the last edit, the severity marker, the
delta and the systems the time went to. A DIFFERENT measurement
from everything below: this is the published smoothed frame, while
stats and the profiler toolbox report the effective frame time
(wall clock minus the cost of the call doing the asking), so a line
composed from those disagrees with what other callers are told
about the same engine. Reading it does not move the edit-to-edit
baseline the delta is measured against.
Returns string? — The summary line, or nil before the first frame is published.
local line = profiler.perfLine()
globals/profiler/recordingHold
profiler.recordingHold() -> string?
Who holds the one windowed recording, as a JSON string
{ label, owner, started_at, stops_in_seconds?, held_seconds, frames, bytes, budget_bytes, dropped_for_budget, span_seconds }, or nil when
nothing is recording. stops_in_seconds is how long until a recording
started with seconds stops on its own. frames and bytes are what the recording
holds, budget_bytes the most it may, dropped_for_budget the
oldest frames that left to keep it there, and span_seconds the
seconds between the oldest and the newest frame it holds. owner is the caller key of whoever called
startCapture, the same value vfs.currentAuthor().id reads for
the calling caller, so a caller refused the slot tells its own
earlier recording from a sibling session's; it is absent when that
call attested no caller. Several agent sessions share one engine and
one recording, which is why a refusal is answered with this.
Returns string? — JSON hold description, or nil when no recording is active.
local held = profiler.recordingHold()
globals/profiler/retro
profiler.retro(seconds: number?, label: string?) -> { [string]: any }?
Retroactively aggregate the last seconds of the ring (default:
the whole ring). The full per-frame capture is retained under label
(default "retro") for in-engine drill-down (the frame / hotspots
tools);
this RETURNS a compact structured aggregate table (frame-time distribution
- per-system summary), never the raw per-frame array — bounded, so it is
safe over the ZeroMind bridge. Code-facing primitive; the
retrotool renders the agent-facing report. Latency-immune: the data is historical.
Parameters
secondsnumber(optional) — How many seconds back to include (default: whole ring).labelstring(optional) — Capture label to store under (default "retro").
Returns { [string]: any }? — A compact aggregate { label, source, frames, seconds, exclude_agent, agent_frames, dt = { avg, p50, p90, p99, max, min }, summary = {...} }, or nil if the ring holds nothing.
local agg = profiler.retro(8, "collapse")
globals/profiler/ringStatus
profiler.ringStatus() -> string
Ring buffer status as a JSON string: { enabled, frames, seconds, span_seconds, bytes, budget_bytes, dropped_for_budget }.
seconds is the retention asked for and span_seconds the span
held; bytes is what the held frames take and budget_bytes the
most they may; dropped_for_budget counts the frames that left
inside the retention window to keep the ring in its budget.
Returns string — JSON status string.
local s = profiler.ringStatus()
globals/profiler/setStoredBudget
profiler.setStoredBudget(bytes: number?) -> number
Hold the stored captures to bytes in all, at most the default
of 64 MiB; nil restores the default. Captures past the new budget
are let go at once, the least recently stored or read first and the
last completed capture kept.
Parameters
bytesnumber(optional) — The most the stored captures may hold (default and most 67108864).
Returns number — The budget the stored captures now hold to, in bytes.
profiler.setStoredBudget(8 * 1024 * 1024)
globals/profiler/startCapture
profiler.startCapture(label: string?, opts: (CaptureOptions | number)?) -> boolean
Start recording every frame, held by the calling caller, until
stopCapture(). The engine records each frame in Rust as it closes:
no Luau runs and nothing is allocated in Luau for the recording, in
the editor and the runtime profile alike, so a benchmark measures its
run rather than its collection. opts.level chooses what is kept:
"frames" (the default) keeps each frame's wall time, the engine
thread's CPU time and wait for a core, the engine's GPU time, every
profiler key's time (each schedule, system and script block, the GC
step, each VM's tick) and its counts (entities, draws, instances,
Luau bytes allocated); "memory" adds a memory sample every
opts.memoryIntervalMs (default 100): the process's private and
resident bytes, the allocator's live heap, every source
memory.report() names (GPU textures, meshes, geometry, shadow
pool, the VFS store...) and each Luau VM's heap; "comprehensive"
adds every GPU frame the timer resolves with each pass's time, every
job the worker pools run (asset decodes and imports, shader compiles,
module loads, each with its pool, kind, worker, start and length), and
the user VM's Luau call stacks sampled at opts.stackHz (default 1000)
for a flame graph. Read it back with captureInfo (which names its
hitches), captureFrames and captureSeries; read it out as a CSV, a
trace Perfetto and chrome://tracing open, flame graphs as SVGs a
browser opens, or folded stacks with exportCapture. guides { path = "topics/profiling" } covers
recording a benchmark and what each level costs. A number in place of
opts is budgetBytes. A recording holds at most
budgetBytes of frame records (default and most 32 MiB), however
long it stays open and at any frame rate: past it the oldest frames
leave first, and profiler.recordingHold() and the stopped capture
state bytes, budget_bytes and dropped_for_budget. The
recording is one engine-wide slot, so a start while another
recording holds it returns false and profiler.recordingHold()
names the label and the caller holding it. The stopped capture is
stored under its label beside the other stored captures, which hold
to their own bound (profiler.storedCaptures()).
Parameters
labelstring(optional) — Capture label (default"capture").opts(CaptureOptions | number)(optional) —{ level, memoryIntervalMs, stackHz, budgetBytes, seconds }, or the budget in bytes alone;secondsstops the recording on its own at the first frame past that many seconds, stored under its label asstopCapturestores it.
Returns boolean — True if capture started, false when another recording holds the slot.
if profiler.startCapture("frame-spike") then ... end
profiler.startCapture("bench", { level = "comprehensive" })
globals/profiler/stats
profiler.stats(pattern: string?) -> { ProfilerStat }
Get current EMA profiling statistics from the SystemProfiler.
Optional glob pattern filters by metric name (supports * and ?
wildcards). Each entry carries two averages: avg_ms averages one
RUN of the block and is folded when the block runs, so a block that
has stopped running keeps the last value it saw; avg_frame_ms
averages one FRAME and is folded every frame, including the frames
the block did not run in, so it is the block's share of the current
frame and falls back to zero once the block stops running.
Parameters
patternstring(optional) — Filter pattern (e.g. "schedule.", "system.schedule.render.").
Returns { ProfilerStat } — Array of profiler block stats.
for _, s in ipairs(profiler.stats("schedule.*")) do print(s.name, s.avg_frame_ms) end
globals/profiler/stopCapture
profiler.stopCapture(opts: StopCaptureOptions?) -> string?
Stop the active profiler capture and return its result as a
JSON string. The capture is stored under its label, read back at
/zero/runtime/profiler/<label>.json, while the stored captures'
byte bound keeps it. Top-level fields: label,
frame_count, started_at, ended_at, frames, summary,
callers, bytes, budget_bytes, dropped_for_budget, let_go. Compute
duration as ended_at - started_at. callers holds { caller, total_ms, max_ms, frames } per caller whose queued Luau ran in the
window, heaviest first, and each frame carries its own split as
agent_by_caller. frame_count is the frames the recording held
when it stopped, and dropped_for_budget the older frames it let go
to stay inside budget_bytes; once it let any go, started_at is
the oldest frame it held, so ended_at - started_at is the span its
frames cover. let_go names the stored captures that storing this
one let go to keep the stored captures inside their bound
(profiler.storedCaptures()). opts.frames = false leaves frames
out, so the string costs a few kilobytes however long the recording
was; read the frames a page at a time with profiler.captureFrames.
Parameters
optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — JSON capture result, or nil if no capture was active.
local json = profiler.stopCapture()
local head = profiler.stopCapture({ frames = false })
globals/profiler/storedCaptures
profiler.storedCaptures() -> StoredCaptures
What the stored captures (stopped recordings, retro
snapshots, drained watchdog hits) hold and what they let go. They
hold at most budget_bytes in all (64 MiB unless set lower with
profiler.setStoredBudget), each counted with every frame it holds:
past it the capture least recently stored or read leaves first, and
the capture just stored stays. labels names the stored captures,
the next to leave first; let_go and let_go_bytes count every
capture let go since the engine started and what they held;
let_go_labels names the newest 256 of them, oldest first.
memory.report() states the same under profiler.frames.
Returns StoredCaptures — { captures, labels, bytes, budget_bytes, let_go, let_go_bytes, let_go_labels }.
local stored = profiler.storedCaptures()
globals/profiler/unwatch
profiler.unwatch()
Disarm the watchdog. Recorded hits are kept for a final
profiler.hits().
profiler.unwatch()
globals/profiler/watch
profiler.watch(ceilingMs: number, mode: string?, excludeAgent: boolean?, maxHits: number?) -> boolean
Arm the frame-time watchdog. When a frame's EFFECTIVE time
(total minus agent-injected execute cost) crosses ceilingMs,
mode "record" logs every offending frame (read with
profiler.hits()), and mode "pause" pauses gameplay ONCE to
freeze the bad state, then disarms. Editor profile only: returns
false in the runtime profile. excludeAgent (default true) keeps
the agent's own calls, its captures included, from tripping it.
Parameters
ceilingMsnumber— Effective frame-time ceiling in ms.modestring(optional) — "record" (default) or "pause".excludeAgentboolean(optional) — Subtract agent cost before comparing and pass over frames that did an agent's capture work (default true).maxHitsnumber(optional) — Max frames retained in record mode (default 240).
Returns boolean — True if armed, false if refused (runtime profile).
if profiler.watch(50, "pause") then ... end
globals/profiler/watchStatus
profiler.watchStatus() -> string
Watchdog status as a JSON string: { armed, ceiling_ms, mode, exclude_agent, hits, dropped_hits, tripped }.
Returns string — JSON status string.
local s = profiler.watchStatus()
tools/profiler/compare
profiler.compare(before?: string, after?: string) -> string
Diff two recordings (made with record): the change in avg/p90 frametime, and the systems that moved the most between them. Record a baseline, make a change, record again, then compare to see whether the change helped and which system it moved. A positive frametime delta means B is slower than A.
Parameters
beforestring(optional)afterstring(optional)
Returns string
"baseline", "optimized" -- did 'optimized' beat 'baseline', and where
tools/profiler/cost
profiler.cost(seconds?: number, last?: number) -> string
What the engine itself spent per frame over a window of frames, beside the wall time: the engine thread's CPU time, the time per frame it waited for a core other processes held, the engine's own GPU time, the GPU share other processes used where the platform states it, the kind of cores the thread ran on, and the frame rate the world would hold with the machine to itself (bounded by the larger of the CPU and GPU time per frame) next to the rate it ran at. Names the build, the Luau configuration and the drawn size of the engine that produced it. By default it measures the next seconds of frames and returns when they have run; pass last to read the frames of the last seconds the engine already holds. Frames that drew a capture a caller asked for are left out and counted. A caller's queued work, this command's own included, is taken out of the frames it ran in, so it measures the world's frames when run from the shell; a frame spent mostly on that work is left out and counted. A figure the platform does not give is stated as unavailable with its reason.
Parameters
secondsnumber(optional)lastnumber(optional)
Returns string
-- measure the next 5 s
20 -- measure the next 20 s
nil, 10 -- read the last 10 s held, at once
tools/profiler/flamegraph
profiler.flamegraph(seconds?: number, mode?: ("run" | "start" | "stop" | "snapshot"), label?: string) -> string
Sample the Luau call stack to find the hottest code paths — the depth view under a hot component or task_scheduler. flamegraph(seconds) runs the sampler for that many seconds of wall clock (resetting first), the same length at every engine.timeScale, 0 included, and returns the top stacks plus a folded-stack file for flamegraph rendering. mode picks a manual phase instead: "start" / "stop" a long session, or "snapshot" the current top stacks without stopping.
Parameters
secondsnumber(optional)mode("run" | "start" | "stop" | "snapshot")(optional)labelstring(optional)
Returns string
-- 3s sample, top stacks + folded file
5 -- 5s sample
0, "snapshot" -- top stacks right now without stopping a session
tools/profiler/frame
profiler.frame(source?: string, which?: ("worst" | "typical"), minMs?: number) -> string
The current frame's time as a self-accounting tree: schedule -> system -> sub-timing, each row showing SELF (own time excluding children), TOTAL, calls, and % of frame. Time no schedule covers (the frame limiter / vsync wait, GPU present, event loop) shows as present / idle; each expensive component's update(dt) is listed by component + entity under lua_update.vm_call. Read the live frame with source "now", or a stopped recording by its label (its worst or typical frame). Read from top: the row with the largest SELF time is where the frame time actually goes.
Parameters
sourcestring(optional)which("worst" | "typical")(optional)minMsnumber(optional)
Returns string
-- live frame, full attributed tree
"combat", "worst" -- the worst frame of the 'combat' recording
"combat", "typical" -- the typical (average) frame of that recording
tools/profiler/gpu
profiler.gpu(n?: number) -> string
GPU pass timings over the last resolved frames, from GPU timestamp queries. Each row is one label: the median of its per-frame total, the min/max that median sits in, the passes per frame, and how many of the window's frames carried it. A row marked floor ran but the device resolved no duration for it — its two timestamps retired within a few ticks of each other. The last column is how many resolved frames ago the label last recorded a pass: now is a pass running in the frame the table describes, and anything else is a row the window still holds after the work under it stopped. The readback is asynchronous, so the window lags the live frame by a few frames. Use this when frame shows the time under present / idle (GPU-bound) and you need to know which passes the GPU spends it on.
Parameters
nnumber(optional)
Returns string
-- top 20 GPU spans of the window
40 -- top 40
tools/profiler/heap
profiler.heap(root?: string, top?: number) -> string
Account for the Luau heap. With no root, counts the whole heap by object type and memory category. With a Luau expression naming a value (require("@builtin::systems.procgen.proc"), entity("ent_x").component.get("Generator")), reports how many bytes that value reaches and how many only it holds, how they split by the first reference taken from it (a field name, metatable, or the name of a variable a closure captured), and the largest objects with the references that reach each. Walks every object of the VM, so the call takes time in proportion to the heap.
Parameters
rootstring(optional)topnumber(optional)
Returns string
-- the whole heap by type and memory category
"require('@builtin::systems.procgen.proc')" -- what the procgen module holds
tools/profiler/hits
profiler.hits(label?: string, spikeMs?: number) -> string
Drain the frames a record-mode watch caught and report them as a spike-cluster distribution — every caught frame grouped by its dominant hotspot, so repeated hitches collapse to their handful of causes instead of a wall of individual frames. Draining clears the buffer. The snapshot is stored under label — drill into any cluster with frame <label> / hotspots <label>. Arm the watchdog first with watch <ceilingMs>.
Parameters
labelstring(optional)spikeMsnumber(optional)
Returns string
-- review everything the watchdog caught
"collapse_hits" -- store under a name for later drill-down
tools/profiler/hotspots
profiler.hotspots(n?: number, source?: string, which?: ("worst" | "typical")) -> string
Rank the frame's costs by SELF time (a node's own cost, excluding its children) and return the top n as a flat table. Because it ranks by SELF, the top rows are the actual expensive leaves — a system's own work or a single heavy component's update(dt) — not the schedules that merely contain them. This is the "just tell me what's slow" tool; follow a hit down with frame. Reads the live frame ("now") or a stopped recording's worst/typical frame (pass its label).
Parameters
nnumber(optional)sourcestring(optional)which("worst" | "typical")(optional)
Returns string
-- top 12 costs in the live frame
20 -- top 20
12, "combat" -- top 12 in the worst frame of the 'combat' recording
tools/profiler/memory
profiler.memory(n?: number) -> string
Where the engine's memory is. First the whole engine: the process's private bytes as the operating system charges them, the allocator's live bytes, each subsystem's share (the Luau heap, the VFS store, substrate buffers, read-backs, plugins, textures and meshes on the device, ...) and what no subsystem names. Then the Luau VM's GC state and the components retaining the most of it. Take it before and after a piece of work: the part that grew is where the work left memory held. memory.report() returns the same figures as a table.
Parameters
nnumber(optional)
Returns string
-- the whole engine, then the top 20 components by retained memory
10 -- the same with the top 10 components
tools/profiler/record
profiler.record(action?: ("start" | "stop" | "status"), label?: string, level?: ("frames" | "memory" | "comprehensive"), seconds?: number, spikeMs?: number) -> string
Start / stop / check a background profiling recording that spans a play session. record("start", label) begins capturing every frame; play or test the game across as many turns as you want, then record("stop", label) returns the windowed breakdown: avg / p50 / p90 / p99 / max frametime, spike count, the single WORST frame's attributed tree, and a typical-frame tree. A recording holds at most 32 MiB of frames however long it runs: past that its oldest frames leave, and the report says how many and that it describes the newest frames held. Recording is one engine-wide slot, so a start while another recording runs is refused with the label of that recording, the caller holding it, and how long it has been held; record("status") answers with the same. A stopped recording is kept under its label beside the other stored captures, which hold at most 64 MiB in all: past it the least recently stored or read leave first, and the report names the ones storing it let go. Analyse it later with frame, hotspots, or flamegraph (pass the label as their source), or diff two of them with compare. The recording holds every frame from its start, edit-mode frames too, and records the client it runs in: to benchmark play, start it and enter play in the same execute (engine.mode = "play"), in the client that presents the frames.
Parameters
action("start" | "stop" | "status")(optional)labelstring(optional)level("frames" | "memory" | "comprehensive")(optional)secondsnumber(optional)spikeMsnumber(optional)
Returns string
"start", "combat" -- begin recording a combat encounter
"stop", "combat" -- end it, get the windowed breakdown
"status" -- is a recording running right now?
"start", "bench", "comprehensive" -- every frame, memory, GPU passes, jobs and stacks
"start", "bench", "comprehensive", 10 -- the same, stopping itself after 10 s
tools/profiler/retro
profiler.retro(seconds?: number, label?: string, spikeMs?: number) -> string
Retroactively read the ring buffer's last seconds of frames (default: the whole ring) as a spike-cluster report — the latency-immune profiler. Enable the ring first (ring on), drive the scene, then call this AFTER the spike: the data is historical, so your call's timing does not matter. The report groups every spike frame by its dominant hotspot (so one call shows the full distribution of what's slow, not one anecdote), on EFFECTIVE frame time (your own execute cost excluded). The snapshot is stored under label — drill into any cluster with frame <label> / hotspots <label>.
Parameters
secondsnumber(optional)labelstring(optional)spikeMsnumber(optional)
Returns string
-- the whole ring, clustered
8 -- just the last 8 seconds
8, "collapse" -- last 8s, stored as 'collapse' for drill-down
tools/profiler/ring
profiler.ring(action?: ("on" | "off" | "status"), seconds?: number) -> string
Control the retroactive ring buffer — an always-recording, bounded history of the last N seconds of per-frame data you query AFTER the fact with retro. ring("on", seconds) starts it (default 20s); ring("off") stops and clears it; ring("status") reports whether it's on, how many frames and seconds it holds and the memory they take against its budget. Editor profile only — a no-op in the runtime profile. The ring is off until you turn it on, so it costs nothing until then. This is the fix for "I can't profile a spike I only see afterwards".
Parameters
action("on" | "off" | "status")(optional)secondsnumber(optional)
Returns string
"on", 30 -- keep the last 30 seconds, always
"status" -- is the ring on? how much does it hold?
"off" -- stop recording and clear the history
tools/profiler/scripts
profiler.scripts(n?: number, minMs?: number, type_?: string) -> string
Rank components by update(dt) cost — the content view of where the frame's script time goes. Rolled up per component type by default (many instances of a type collapse to Type xN with summed cost; a lone instance keeps its @ entity), so it stays readable whether a world has three scripts or three hundred. Pass a type to drill into that one type's individual instances (which entity is the heavy one). Use it after hotspots/frame point at lua_update.vm_call. Counts COMPONENT update loops; a scene entrypoint's per-frame update / editorUpdate runs on the scheduler, and scene.cost ranks the loaded scenes by what theirs costs.
Parameters
nnumber(optional)minMsnumber(optional)type_string(optional)
Returns string
-- every component type, heaviest first
10 -- the 10 heaviest types
20, 0.5, "MyMover" -- instances of MyMover costing >= 0.5ms, by entity
tools/profiler/summary
profiler.summary() -> string?
The engine's own one-line performance summary, exactly as it rides a tool response: the headline frame time, and — when the frame is slow or CPU moved since the last edit — the severity marker, the delta, and the systems the time went to. Read this rather than composing a line from profiler.frame or profiler.hotspots: those report the profiler's effective frame time (wall clock minus the cost of the call asking), while this reports the published smoothed frame, so the two do not agree and only this one matches what other callers are told.
Returns string?
-- "12.4ms frame"
tools/profiler/tasks
profiler.tasks(n?: number, minMs?: number) -> string
Rank components by the time the scheduler spent resuming their coroutines this frame — the content breakdown of task_scheduler — with what the Luau allocator handed out while they ran, which is the garbage the collector pays for. Rolled up per component type (many instances collapse to Type xN; a lone instance keeps its @ entity). Use this when frame/hotspots show task_scheduler hot and you need to know whose task.spawn / task.wait work is behind it.
Parameters
nnumber(optional)minMsnumber(optional)
Returns string
-- every component's coroutine cost, heaviest first
10 -- the 10 heaviest
tools/profiler/watch
profiler.watch(ceilingMs?: (number | "off" | "status"), mode?: ("record" | "pause"), excludeAgent?: boolean) -> string
Arm a frame-time watchdog that catches bad frames without you having to poll (which always lands seconds late). Call with a number to arm: watch(50) records every frame whose EFFECTIVE time (agent cost excluded) is >= 50ms; watch(50, "pause") instead pauses gameplay the first time the ceiling is crossed, freezing the bad state for you to inspect (then read it with retro). watch("off") disarms; watch("status") (or no arg) reports state and hit count. Read recorded hits with the hits tool. Editor profile only — returns a refusal in the runtime profile. excludeAgent (default true) keeps your own execute/write/capture frames from tripping it.
Parameters
ceilingMs(number | "off" | "status")(optional)mode("record" | "pause")(optional)excludeAgentboolean(optional)
Returns string
50 -- record every frame over 50ms effective
50, "pause" -- pause gameplay the first time a frame exceeds 50ms
"status" -- armed? how many hits so far?
"off" -- disarm
typed/builtin//modules/api/engine/profiler/profiler/begin
profiler.begin(name: string)
Start a named profiling block. Call profiler.finish(name) to
record the duration. Blocks appear in profiler.stats() under
"script.<name>" and inside captures.
Parameters
namestring— Block name (e.g. "MyComponent.update").
profiler.begin("MyComponent.update"); ...; profiler.finish()
typed/builtin//modules/api/engine/profiler/profiler/captureFrames
profiler.captureFrames(label: string?, first: number?, count: number?) -> ({ CaptureFrame }?, string?)
Frames first .. first + count - 1 (numbered from 1) of a
stored capture, each { frame, total_ms, agent_ms, capture_ms, capture, cpu_ms, wait_ms, gpu_ms, t_ms, systems, agent_by_caller }
built straight from its records, frame numbered from 0 within the
capture. capture marks a capture frame: one that spent
capture_ms drawing renders a caller's tool call asked for or
copying their readbacks, or ran while such a readback was in flight
on the GPU. cpu_ms,
wait_ms and gpu_ms are the engine thread's CPU time, its wait
for a core and the engine's GPU time, each absent where the platform
gives none (frameCost says why). A read takes the memory of the
frames it asks for, so a long capture read a page at a time holds
one page at once. Empty past the capture's last frame.
Parameters
labelstring(optional) — The capture's label (default: the last completed capture).firstnumber(optional) — The first frame to read, from 1 (default 1).countnumber(optional) — How many frames to read (default: every frame fromfirst).
Returns ({ CaptureFrame }?, string?) — The frames, or nil and why there is no such capture, as profiler.captureInfo states it.
local page, why = profiler.captureFrames("combat", 1, 64)
typed/builtin//modules/api/engine/profiler/profiler/captureInfo
profiler.captureInfo(label: string?) -> (CaptureInfo?, string?)
A stored capture (a stopped recording, a retro snapshot or
drained watchdog hits) without its frames: { label, frame_count, started_at, ended_at, source, summary, callers, bytes, budget_bytes, dropped_for_budget, let_go, frame_cost }, the fields of
stopCapture but frames; frame_cost is the
profiler.frameCost report of its frames. It costs a few
kilobytes however many frames the capture holds; read them with
profiler.captureFrames. When there is no such capture it
answers nil and why: the capture was let go to keep the stored
captures inside their bound, no capture is stored under the
label, or none has completed yet.
Parameters
labelstring(optional) — The capture's label (default: the last completed capture).
Returns (CaptureInfo?, string?) — The capture's header, or nil and why there is none.
local info, why = profiler.captureInfo("combat")
typed/builtin//modules/api/engine/profiler/profiler/captureSeries
profiler.captureSeries(label: string?, series: "memory" | "gpu" | "jobs" | "hitches", first: number?, count: number?) -> (CaptureSeriesPage?, string?)
Items first .. first + count - 1 (from 1) of one series of a
stored capture, as { total, items }: "memory" (a recording at the
memory level or above; each item a CaptureMemorySample), "gpu"
(a comprehensive recording; each a CaptureGpuFrame), "jobs" (a
comprehensive recording; each a CaptureJob, in the order they
started) or "hitches" (every capture; each a CaptureHitch, the
frames at twice the median and 8 ms above it with the keys that took
the most of them and the jobs that ran across them). A series the capture's level did
not keep answers nil and the level that keeps it.
Parameters
labelstring(optional) — The capture's label (nil: the last completed capture).series"memory" | "gpu" | "jobs" | "hitches"—"memory","gpu","jobs"or"hitches".firstnumber(optional) — The first item to read, from 1 (default 1).countnumber(optional) — How many items to read (default: every item fromfirst).
Returns (CaptureSeriesPage?, string?) — The page, or nil and why there is none.
local mem = profiler.captureSeries("bench", "memory")
for _, m in mem.items do print(m.t_ms, m.private_bytes, m.vms.user.live_bytes) end
typed/builtin//modules/api/engine/profiler/profiler/counters
profiler.counters(pattern: string?) -> { ProfilerCount }
Get the profiler's counts: unitless per-frame tallies (for example
the waits the engine thread made on the process-wide lock, under
system.schedule.frame.process_local_waits), kept apart from the
millisecond timings of stats. frame is the tally of the frame in
progress, prev_frame the last complete frame's, max_frame the
highest complete-frame tally and total the tally since the profiler
started. Optional glob pattern filters by name (supports * and ?).
Parameters
patternstring(optional) — Filter pattern (e.g. "system.schedule.frame.*").
Returns { ProfilerCount } — Array of profiler counts.
for _, c in ipairs(profiler.counters("system.schedule.frame.*")) do print(c.name, c.prev_frame) end
typed/builtin//modules/api/engine/profiler/profiler/disableRing
profiler.disableRing()
Disable the ring buffer and clear its history.
profiler.disableRing()
typed/builtin//modules/api/engine/profiler/profiler/enableRing
profiler.enableRing(seconds: number?) -> boolean
Enable the always-recording ring buffer, retaining the last
seconds of per-frame data (default 20, 1 to 600) at any frame
rate, within a fixed memory budget (budget_bytes of
profiler.ringStatus(), 32 MiB): once the window's frames would
take more, the oldest leave first and dropped_for_budget counts
them. Query it AFTER the fact with profiler.retro() —
latency-immune, since the data is historical. Editor profile only:
returns false in the runtime profile. The enable is the gate; the
ring costs nothing until on. memory.report() states what the
frames hold as profiler.frames.
Parameters
secondsnumber(optional) — Seconds of history to retain (default 20, 1 to 600).
Returns boolean — True if enabled, false if refused (runtime profile).
if profiler.enableRing(30) then ... end
typed/builtin//modules/api/engine/profiler/profiler/exportCapture
profiler.exportCapture(label: string?, format: "json" | "csv" | "trace" | "stacks" | "scopes" | "stacksSvg" | "scopesSvg") -> (CaptureExport?, string?)
Where a stored capture reads out in format: a file of
/zero/runtime/profiler/, generated when it is read. "json" is the
whole capture (header, frames, series, hitches); "csv" one row per
frame with its times, counts, memory, each schedule's time and each
profiler count it tallied;
"trace" trace-event JSON Perfetto and chrome://tracing open
(frames as spans; schedules, memory, Luau heaps and GPU passes as
counter tracks; each pool worker's jobs as spans on a track of its
own; hitches as markers); "stacks" the sampled Luau
stacks folded root first (frame;frame;... microseconds, the form
speedscope, inferno and flamegraph.pl read); "scopes" the
engine's timed scopes folded, each by its own time in microseconds;
"stacksSvg" and "scopesSvg" the same drawn as a flame graph, an
SVG a browser opens (each frame as wide as its time, its time and
share in its tooltip).
The file is read from outside the engine like any VFS file (the
proxy's download_file, GET /engine/vfs/<path>), so a long capture
never passes through a call's answer.
Parameters
labelstring(optional) — The capture's label (nil: the last completed capture).format"json" | "csv" | "trace" | "stacks" | "scopes" | "stacksSvg" | "scopesSvg"—"json","csv","trace","stacks","scopes","stacksSvg"or"scopesSvg".
Returns (CaptureExport?, string?) — { path, format, bytes }, or nil and why: no such capture, or stacks a recording below comprehensive (or an engine with no sampler) did not take.
local trace = profiler.exportCapture("bench", "trace")
local flame = profiler.exportCapture("bench", "scopesSvg") -- an SVG a browser opens
typed/builtin//modules/api/engine/profiler/profiler/finish
profiler.finish(name: string?) -> number?
Finish a profiling block and record the elapsed duration as
"script.<name>". Without an argument, closes the most-recently-
begun block (LIFO stack). With a name, closes the most recent
block whose name matches — useful when blocks of different names
are nested.
Parameters
namestring(optional) — Block name to finish. Omit to pop the top of the stack.
Returns number? — Elapsed milliseconds, or nil if no matching block was active.
local ms = profiler.finish("MyComponent.update")
typed/builtin//modules/api/engine/profiler/profiler/frameCost
profiler.frameCost(opts: FrameCostOptions?) -> FrameCostReport
What the engine itself spent per frame over a window, beside the
wall time, so a frame cost read on a machine shared with other work
names how much of each frame was the engine and how much the
machine. With opts.seconds (default 5) it measures the frames of
the next that many seconds of wall clock and returns when they have
run (the calling task waits on the wall clock, so the window has the
same length at every engine.timeScale, 0 included; GPU timing runs
for the window); with
opts.last it reads the frames of the last that many seconds the
engine already holds, at once. cpu is the engine thread's CPU time
per frame from the thread's own clock (source = "thread_clock";
in a browser the worker's own time, the frame less the host's
waiting and busy, source = "worker", which still holds the
worker's waits for a core). waitingForCore is the
time per frame the thread was ready to run and waited for a core
other processes held, with its share of the wall time. gpu.own
is the engine's own GPU time per frame: the GPU driver's account of
the process on the busiest of the GPU's engines where it gives one
(drm_fdinfo), otherwise the
engine's timed passes (timestamp_queries, which other clients'
work on a busy GPU lengthens). hostBoundFps is the frame rate the
world would hold with the machine to itself, 1000 over the larger of
cpu.mean and gpu.own.mean, beside fps, the rate it ran at.
build, luau and drawn name the engine that produced the
numbers. Frames that drew a capture a caller's tool call asked for
are left out and counted under excluded.capture. A caller's queued
work (an execute, the shell command reading the window) is taken
out of the wall and CPU time of the frames it ran in, so a window
read from the shell or a running call measures the world's frames;
a frame that spent half its wall time or more on it is left out and
counted under excluded.callerWork. A figure the platform does not give carries
available = false and the platform's reason, never a zero.
Parameters
optsFrameCostOptions(optional) —{ seconds = n }to measure the next n seconds (default 5, at most 120), or{ last = n }to read the last n seconds held.
Returns FrameCostReport — The window's frame cost.
local r = profiler.frameCost({ seconds = 10 }); print(r.fps, r.cpu.mean, r.waitingForCore.mean, r.hostBoundFps)
local r = profiler.frameCost({ last = 5 })
typed/builtin//modules/api/engine/profiler/profiler/gpuFrame
profiler.gpuFrame() -> GpuFrameReport
Label-aggregated GPU pass timings over the last window_frames
resolved frames, measured with GPU timestamp queries. supported
is false when the device lacks timestamp queries — spans stays
empty. Each span covers every render/compute pass recorded under
one label — compute.<shader> per compute dispatch, scene.* for
the scene passes, post.<effect> per post-process effect,
feature.* for render-feature passes: ms is the median of its
per-frame totals, min_ms/max_ms the range that median sits in,
count the passes per frame and frames how much of the window
carried it. at_floor marks a label whose every sample landed
within a few ticks of the device's timestamp counter (tick_ms) —
those passes ran and the device resolved no duration for them,
which is not the same as a measured zero. ran is whether the
label recorded a measured pass in the newest resolved frame, and
last_frame the newest frame that did. The window outlives the
work it describes, so a pass that stops being recorded leaves a row
standing for up to window_frames frames carrying the median of
the frames it did run in: read ran to answer whether a pass is
running, frame - last_frame for how many resolved frames ago it
last did, and ms as the cost of the frames it ran in.
frame_span_ms (first pass begin to last pass end) and
total_ms are medians too, so
rows do not sum to total_ms, and the GPU may overlap passes so
total_ms can exceed frame_span_ms. The readback is
asynchronous: the window lags the live frame by a few frames.
Returns GpuFrameReport — GPU timing window, spans ranked by median ms descending.
local g = profiler.gpuFrame(); print(g.frame_span_ms, g.spans[1] and g.spans[1].label)
typed/builtin//modules/api/engine/profiler/profiler/hits
profiler.hits(label: string?, opts: StopCaptureOptions?) -> string?
Drain the watchdog's recorded hit frames into a capture stored
under label (default "watch_hits") and clear the buffer.
Returns the capture JSON (same shape as stopCapture), or nil if
there were no hits. opts.frames = false leaves frames out; read
them a page at a time with profiler.captureFrames(label, first, count).
Parameters
labelstring(optional) — Capture label to store under (default "watch_hits").optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — Capture JSON of the hit frames, or nil if none.
local json = profiler.hits()
local head = profiler.hits("collapse", { frames = false })
typed/builtin//modules/api/engine/profiler/profiler/isCapturing
profiler.isCapturing() -> boolean
Check if a profiler capture is currently active.
Returns boolean — True if a capture is in progress.
if profiler.isCapturing() then ... end
typed/builtin//modules/api/engine/profiler/profiler/lastCapture
profiler.lastCapture(opts: StopCaptureOptions?) -> string?
Get the most recent completed capture result as a JSON string.
Same shape as profiler.stopCapture(). Returns nil if no capture
has been completed yet. opts.frames = false leaves frames out;
read them a page at a time with profiler.captureFrames.
Parameters
optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — JSON string of the last capture, or nil.
local last = profiler.lastCapture()
local head = profiler.lastCapture({ frames = false })
typed/builtin//modules/api/engine/profiler/profiler/perfLine
profiler.perfLine() -> string?
The engine's own one-line performance summary, exactly as it
rides a tool response: the headline frame time, and when the frame
is slow or CPU moved since the last edit, the severity marker, the
delta and the systems the time went to. A DIFFERENT measurement
from everything below: this is the published smoothed frame, while
stats and the profiler toolbox report the effective frame time
(wall clock minus the cost of the call doing the asking), so a line
composed from those disagrees with what other callers are told
about the same engine. Reading it does not move the edit-to-edit
baseline the delta is measured against.
Returns string? — The summary line, or nil before the first frame is published.
local line = profiler.perfLine()
typed/builtin//modules/api/engine/profiler/profiler/recordingHold
profiler.recordingHold() -> string?
Who holds the one windowed recording, as a JSON string
{ label, owner, started_at, stops_in_seconds?, held_seconds, frames, bytes, budget_bytes, dropped_for_budget, span_seconds }, or nil when
nothing is recording. stops_in_seconds is how long until a recording
started with seconds stops on its own. frames and bytes are what the recording
holds, budget_bytes the most it may, dropped_for_budget the
oldest frames that left to keep it there, and span_seconds the
seconds between the oldest and the newest frame it holds. owner is the caller key of whoever called
startCapture, the same value vfs.currentAuthor().id reads for
the calling caller, so a caller refused the slot tells its own
earlier recording from a sibling session's; it is absent when that
call attested no caller. Several agent sessions share one engine and
one recording, which is why a refusal is answered with this.
Returns string? — JSON hold description, or nil when no recording is active.
local held = profiler.recordingHold()
typed/builtin//modules/api/engine/profiler/profiler/retro
profiler.retro(seconds: number?, label: string?) -> { [string]: any }?
Retroactively aggregate the last seconds of the ring (default:
the whole ring). The full per-frame capture is retained under label
(default "retro") for in-engine drill-down (the frame / hotspots
tools);
this RETURNS a compact structured aggregate table (frame-time distribution
- per-system summary), never the raw per-frame array — bounded, so it is
safe over the ZeroMind bridge. Code-facing primitive; the
retrotool renders the agent-facing report. Latency-immune: the data is historical.
Parameters
secondsnumber(optional) — How many seconds back to include (default: whole ring).labelstring(optional) — Capture label to store under (default "retro").
Returns { [string]: any }? — A compact aggregate { label, source, frames, seconds, exclude_agent, agent_frames, dt = { avg, p50, p90, p99, max, min }, summary = {...} }, or nil if the ring holds nothing.
local agg = profiler.retro(8, "collapse")
typed/builtin//modules/api/engine/profiler/profiler/ringStatus
profiler.ringStatus() -> string
Ring buffer status as a JSON string: { enabled, frames, seconds, span_seconds, bytes, budget_bytes, dropped_for_budget }.
seconds is the retention asked for and span_seconds the span
held; bytes is what the held frames take and budget_bytes the
most they may; dropped_for_budget counts the frames that left
inside the retention window to keep the ring in its budget.
Returns string — JSON status string.
local s = profiler.ringStatus()
typed/builtin//modules/api/engine/profiler/profiler/setStoredBudget
profiler.setStoredBudget(bytes: number?) -> number
Hold the stored captures to bytes in all, at most the default
of 64 MiB; nil restores the default. Captures past the new budget
are let go at once, the least recently stored or read first and the
last completed capture kept.
Parameters
bytesnumber(optional) — The most the stored captures may hold (default and most 67108864).
Returns number — The budget the stored captures now hold to, in bytes.
profiler.setStoredBudget(8 * 1024 * 1024)
typed/builtin//modules/api/engine/profiler/profiler/startCapture
profiler.startCapture(label: string?, opts: (CaptureOptions | number)?) -> boolean
Start recording every frame, held by the calling caller, until
stopCapture(). The engine records each frame in Rust as it closes:
no Luau runs and nothing is allocated in Luau for the recording, in
the editor and the runtime profile alike, so a benchmark measures its
run rather than its collection. opts.level chooses what is kept:
"frames" (the default) keeps each frame's wall time, the engine
thread's CPU time and wait for a core, the engine's GPU time, every
profiler key's time (each schedule, system and script block, the GC
step, each VM's tick) and its counts (entities, draws, instances,
Luau bytes allocated); "memory" adds a memory sample every
opts.memoryIntervalMs (default 100): the process's private and
resident bytes, the allocator's live heap, every source
memory.report() names (GPU textures, meshes, geometry, shadow
pool, the VFS store...) and each Luau VM's heap; "comprehensive"
adds every GPU frame the timer resolves with each pass's time, every
job the worker pools run (asset decodes and imports, shader compiles,
module loads, each with its pool, kind, worker, start and length), and
the user VM's Luau call stacks sampled at opts.stackHz (default 1000)
for a flame graph. Read it back with captureInfo (which names its
hitches), captureFrames and captureSeries; read it out as a CSV, a
trace Perfetto and chrome://tracing open, flame graphs as SVGs a
browser opens, or folded stacks with exportCapture. guides { path = "topics/profiling" } covers
recording a benchmark and what each level costs. A number in place of
opts is budgetBytes. A recording holds at most
budgetBytes of frame records (default and most 32 MiB), however
long it stays open and at any frame rate: past it the oldest frames
leave first, and profiler.recordingHold() and the stopped capture
state bytes, budget_bytes and dropped_for_budget. The
recording is one engine-wide slot, so a start while another
recording holds it returns false and profiler.recordingHold()
names the label and the caller holding it. The stopped capture is
stored under its label beside the other stored captures, which hold
to their own bound (profiler.storedCaptures()).
Parameters
labelstring(optional) — Capture label (default"capture").opts(CaptureOptions | number)(optional) —{ level, memoryIntervalMs, stackHz, budgetBytes, seconds }, or the budget in bytes alone;secondsstops the recording on its own at the first frame past that many seconds, stored under its label asstopCapturestores it.
Returns boolean — True if capture started, false when another recording holds the slot.
if profiler.startCapture("frame-spike") then ... end
profiler.startCapture("bench", { level = "comprehensive" })
typed/builtin//modules/api/engine/profiler/profiler/stats
profiler.stats(pattern: string?) -> { ProfilerStat }
Get current EMA profiling statistics from the SystemProfiler.
Optional glob pattern filters by metric name (supports * and ?
wildcards). Each entry carries two averages: avg_ms averages one
RUN of the block and is folded when the block runs, so a block that
has stopped running keeps the last value it saw; avg_frame_ms
averages one FRAME and is folded every frame, including the frames
the block did not run in, so it is the block's share of the current
frame and falls back to zero once the block stops running.
Parameters
patternstring(optional) — Filter pattern (e.g. "schedule.", "system.schedule.render.").
Returns { ProfilerStat } — Array of profiler block stats.
for _, s in ipairs(profiler.stats("schedule.*")) do print(s.name, s.avg_frame_ms) end
typed/builtin//modules/api/engine/profiler/profiler/stopCapture
profiler.stopCapture(opts: StopCaptureOptions?) -> string?
Stop the active profiler capture and return its result as a
JSON string. The capture is stored under its label, read back at
/zero/runtime/profiler/<label>.json, while the stored captures'
byte bound keeps it. Top-level fields: label,
frame_count, started_at, ended_at, frames, summary,
callers, bytes, budget_bytes, dropped_for_budget, let_go. Compute
duration as ended_at - started_at. callers holds { caller, total_ms, max_ms, frames } per caller whose queued Luau ran in the
window, heaviest first, and each frame carries its own split as
agent_by_caller. frame_count is the frames the recording held
when it stopped, and dropped_for_budget the older frames it let go
to stay inside budget_bytes; once it let any go, started_at is
the oldest frame it held, so ended_at - started_at is the span its
frames cover. let_go names the stored captures that storing this
one let go to keep the stored captures inside their bound
(profiler.storedCaptures()). opts.frames = false leaves frames
out, so the string costs a few kilobytes however long the recording
was; read the frames a page at a time with profiler.captureFrames.
Parameters
optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — JSON capture result, or nil if no capture was active.
local json = profiler.stopCapture()
local head = profiler.stopCapture({ frames = false })
typed/builtin//modules/api/engine/profiler/profiler/storedCaptures
profiler.storedCaptures() -> StoredCaptures
What the stored captures (stopped recordings, retro
snapshots, drained watchdog hits) hold and what they let go. They
hold at most budget_bytes in all (64 MiB unless set lower with
profiler.setStoredBudget), each counted with every frame it holds:
past it the capture least recently stored or read leaves first, and
the capture just stored stays. labels names the stored captures,
the next to leave first; let_go and let_go_bytes count every
capture let go since the engine started and what they held;
let_go_labels names the newest 256 of them, oldest first.
memory.report() states the same under profiler.frames.
Returns StoredCaptures — { captures, labels, bytes, budget_bytes, let_go, let_go_bytes, let_go_labels }.
local stored = profiler.storedCaptures()
typed/builtin//modules/api/engine/profiler/profiler/unwatch
profiler.unwatch()
Disarm the watchdog. Recorded hits are kept for a final
profiler.hits().
profiler.unwatch()
typed/builtin//modules/api/engine/profiler/profiler/watch
profiler.watch(ceilingMs: number, mode: string?, excludeAgent: boolean?, maxHits: number?) -> boolean
Arm the frame-time watchdog. When a frame's EFFECTIVE time
(total minus agent-injected execute cost) crosses ceilingMs,
mode "record" logs every offending frame (read with
profiler.hits()), and mode "pause" pauses gameplay ONCE to
freeze the bad state, then disarms. Editor profile only: returns
false in the runtime profile. excludeAgent (default true) keeps
the agent's own calls, its captures included, from tripping it.
Parameters
ceilingMsnumber— Effective frame-time ceiling in ms.modestring(optional) — "record" (default) or "pause".excludeAgentboolean(optional) — Subtract agent cost before comparing and pass over frames that did an agent's capture work (default true).maxHitsnumber(optional) — Max frames retained in record mode (default 240).
Returns boolean — True if armed, false if refused (runtime profile).
if profiler.watch(50, "pause") then ... end
typed/builtin//modules/api/engine/profiler/profiler/watchStatus
profiler.watchStatus() -> string
Watchdog status as a JSON string: { armed, ceiling_ms, mode, exclude_agent, hits, dropped_hits, tripped }.
Returns string — JSON status string.
local s = profiler.watchStatus()