Debugging and profiling
Debug drawing
The Debug service draws lines over the scene: where a ray went, a trigger's box, a path.
Debug:DrawRay(origin, direction, Color.new(0, 1, 0))
Debug:DrawBox(trigger.Transform, trigger.Size, nil, 2)
Debug:DrawPath(points, Color.new(1, 1, 0), 5)| Method | Draws |
|---|---|
DrawLine(from, to) | A line |
DrawRay(origin, direction) | A line from origin along direction |
DrawBox(transform, size) | A box's edges |
DrawSphere(center, radius) | Three circles |
DrawPath(points) | Lines joining the points |
Clear() | Removes everything |
GetLineCount() | How many lines are up |
Every draw call takes an optional Color (red by default) and a duration in seconds of game time. Without a duration the shape lasts one frame, so drawing every frame shows it move. Set Debug.Enabled = false to turn every call into a no-op, so you can leave them in a shipped game. Lines are thin glowing boxes, hidden behind whatever is in front.
Frame profiles
Gamma play MyGame --profile profile.txt --vsync off--profile writes, when the game exits:
- frame times: average, median, 99th percentile and max
- time per part of the frame: input,
RenderStepped, drawing, stepping - counters: parts drawn and culled, draw calls, GPU time in total and per render pass (such as
GPU Opaque ms) where the GPU can time them
--vsync off stops waiting for the display, so frame times show real work and not the refresh rate.
Add your own zones with debug.profilebegin(label) and debug.profileend(). They nest under whatever is running them.
Reading it: culling and packing run on every core, and bgfx renders each frame on its own thread while the next one is built. So the time spent presenting is how long the main thread waited on the render thread. If that's large, the bottleneck is the GPU, the driver, or the OS (which can throttle a hidden or covered window).
Script profiles
Gamma run --profile-scripts scripts.folded MyGameSamples the Luau call stack about a thousand times a second and writes folded stacks (outer;inner count per line) when the game ends. Open the file in speedscope or feed it to flamegraph.pl. Each frame is a function name with the file and line it was defined on. Time spent waiting, such as in task.wait, isn't sampled. Works with play too, with the flag before the project.
Stats
The Stats service reports how the game is running, for an in-game overlay:
| Member | Is |
|---|---|
FrameTime | Seconds the last step covered |
FramesPerSecond | Over the last second |
PhysicsStepTime | Seconds the last physics step took, 0 with physics off |
InstanceCount, PartCount | In the game |
GetTotalMemoryUsageMb() | RAM the process holds |
GetProfile() | Under --profile, the last frame's zones as tables of Name, Depth, Time (seconds) and Calls |