Logo Mibo

FrameProfiler Type

Collects frame measurements for the running game and serves screenshot requests.

Build one, pass it to the program with withProfiler, and the host registers it in the GameContext and measures every frame. When no profiler is supplied, nothing runs and nothing is registered. Read it with Diagnostics.tryGetProfiler from a renderer, a subscription, or a context taking update.

All members are for the frame thread only. The stamp methods allocate nothing and box nothing, so a host can call them every frame.

Constructors

Constructor Description

FrameProfiler(window)

Full Usage: FrameProfiler(window)

Parameters:
Returns: FrameProfiler

Creates a profiler that cannot take screenshots. Headless hosts use this form.

window : TimeSpan
Returns: FrameProfiler

FrameProfiler(window, canScreenshot)

Full Usage: FrameProfiler(window, canScreenshot)

Parameters:
    window : TimeSpan
    canScreenshot : bool

Returns: FrameProfiler
window : TimeSpan
canScreenshot : bool
Returns: FrameProfiler

Instance members

Instance member Description

this.AddSimSteps

Full Usage: this.AddSimSteps

Parameters:
    steps : int
    dropped : bool

Counts simulation steps that ran in this frame. The shared loop calls this once per frame. dropped marks that the fixed step hit its step cap and threw time away.

steps : int
dropped : bool

this.BeginDraw

Full Usage: this.BeginDraw

Starts the draw phase. Hosts call this right before they draw. Headless runners never call it, so draw fields stay ValueNone there.

this.BeginFrame

Full Usage: this.BeginFrame

Starts a host frame. Hosts call this first in the frame, before input polling and the update phase.

When the window has elapsed, this call first freezes the finished window into FrameProfiler.Snapshot and then starts the next window.

this.CanScreenshot

Full Usage: this.CanScreenshot

Returns: bool

Whether this runtime can capture the screen.

Returns: bool

this.DrainScreenshot

Full Usage: this.DrainScreenshot

Returns: string voption

Takes the pending screenshot request, if any. Hosts call this at the end of draw, then write the file themselves.

Returns: string voption

this.Enabled

Full Usage: this.Enabled

Returns: bool

Whether measurement runs. On by default.

Turn it off and on at any time. While it is off every stamp and every request does nothing. Turning it back on starts a fresh window, so the time spent off never shows up as a frame spike.

Returns: bool

this.EndDraw

Full Usage: this.EndDraw

Ends the draw phase. Hosts call this after the last draw call of the frame, before they present.

this.EndUpdate

Full Usage: this.EndUpdate

Ends the update phase. Hosts call this after the update work of the frame is done, before any drawing.

this.NoteSlowFrame

Full Usage: this.NoteSlowFrame

Counts one frame that ran behind. MonoGame hosts call this when the fixed step catch up flag is set.

this.PublishGpuMetrics

Full Usage: this.PublishGpuMetrics

Parameters:
    drawCalls : int64
    primitives : int64
    textureBinds : int64

Publishes the graphics counters of the frame that just drew. MonoGame hosts call this at the end of draw. Other backends never call it, so the fields stay ValueNone.

drawCalls : int64
primitives : int64
textureBinds : int64

this.RequestScreenshot

Full Usage: this.RequestScreenshot

Parameters:
    path : string

Asks the host to save a screenshot at the given path at the end of the current frame.

The request does nothing when FrameProfiler.CanScreenshot is false, which is the case on headless runners. Check that property beforehand when the difference matters.

The file is written when the frame finishes drawing. The capture reads the whole screen and encodes a PNG, so expect one slow frame per request.

path : string

this.Snapshot

Full Usage: this.Snapshot

Returns: FrameStats

The measurements of the last completed window.

Zeroed out until the first window completes.

Returns: FrameStats

Static members

Static member Description

FrameProfiler.DefaultWindow

Full Usage: FrameProfiler.DefaultWindow

Returns: TimeSpan

The default measurement window of half a second.

Returns: TimeSpan

Type something to start searching.