Skip to content

FrameProfiler

namespace Griff.Runtime;
public sealed class FrameProfiler

Keeps the last few seconds of a running game’s frames (see FrameSample), for a profiler to show. Set one as Profiler and whatever runs the game (the editor’s Game tab, a game’s own window) adds each frame it shows; with none set, nothing is timed. Frames held still (paused) aren’t added.

While it’s set, the game also times each of its steps, each kind of script and each system a script added, and the garbage each makes (see AddCost), and building its picture times what each kind of component draws and each part of the build (see Build); Costs sums them up. What’s added between one frame and the next counts in the next frame added. Keeping track of a cost allocates nothing once it’s been seen, so it doesn’t count as garbage itself.

public int Capacity { get; }

How many frames it keeps: adding one more forgets the oldest.

public int Count { get; }

How many frames it holds now.

public FrameSample this[int index] { get; }

A frame it holds, from 0 (the oldest) to Count - 1 (the newest).

public FrameSample Latest { get; }

The newest frame, or none (all zeros) when it holds none.

public long Recorded { get; }

Every frame added since it was made or cleared, kept or not: it changes with each one.

public void Add(in FrameSample sample)
public void AddCost(Type script, long ticks, long allocated)

Adds what scripts of type script took to the frame under way, as AddCost does.

public void AddCost(string name, FrameCostKind kind, long ticks, long allocated)

Adds what a step of the frame (or a system a script added, or the editor’s own work) took to the frame under way: ticks of Stopwatch time, making allocated bytes of garbage (as AllocatedBytes counts them). A name added twice in a frame adds up.

public void AddCost(Type type, FrameCostKind kind, long ticks, long allocated)

Adds what things of type type took to the frame under way, counted as kind (a script’s Update is a Script, its drawing part of the Build), as AddCost does. It’s named for the type.

public void BeginFrame()

Forgets the costs added since the last frame: the next frame’s start from nothing.

public void Clear()

Forgets every frame.

public int CopyTo(Span<FrameSample> into)

Copies the frames it holds into into, oldest first, as many as fit (the newest ones). Returns how many.

public IReadOnlyList<FrameCost> Costs(int frames = 2147483647)

What each step of the frame, kind of script and system cost a frame over the newest frames frames (all it holds, by default), the most first; things that didn’t run in them are left out.

public FrameSummary Summarize(int frames = 2147483647)

How the newest frames frames went (all it holds, by default).

public const int DefaultCapacity

Ten seconds at 60 frames a second.