Skip to content

KernelAPI reference

Class FrameProfiler

Namespace: MicroEngine.Core
Assembly: MicroEngine.dll
Guide: Game lifecycle and time

Measures a run frame by frame and the phases of its start, for –profile and benchmarks. It only measures what the engine itself sees: when EndFrame returns, not when the display shows the frame (presentation times need the platform’s own tools). Samples go into a buffer allocated up front, so profiling adds no allocations to the frames it measures; a run without a profiler does not measure anything.

C#
public sealed class FrameProfiler

Inheritance

object ← FrameProfiler

Constructors

FrameProfiler(int)

Creates a profiler that keeps the last capacity frames (36,000 by default: ten minutes at 60 frames per second).

C#
public FrameProfiler(int capacity = 36000)

Parameters

capacity int

Properties

DisplayRate

The refresh rate of the display pacing the run (IDisplayPacing), or 0 when unknown. With it, motion is judged against the whole refresh periods each frame stayed on screen rather than against the loop’s irregular wake-ups; the loop sets it when the run starts.

C#
public double DisplayRate { get; set; }

Property Value

double

Environment

Free-form facts about the run (machine, platform, renderer, display), written with the results.

C#
public IDictionary<string, string> Environment { get; }

Property Value

IDictionary<string, string>

FrameCount

Frames measured since the start (including those no longer kept).

C#
public long FrameCount { get; }

Property Value

long

Phases

The start phases recorded with Phase, in order, with their durations in milliseconds.

C#
public IReadOnlyList<(string Phase, double Milliseconds)> Phases { get; }

Property Value

IReadOnlyList<(string Phase, double Milliseconds)>

Samples

The kept frames, oldest first.

C#
public IReadOnlyList<FrameSample> Samples { get; }

Property Value

IReadOnlyList<FrameSample>

Methods

Add(in FrameSample)

Records a frame.

C#
public void Add(in FrameSample sample)

Parameters

sample FrameSample

Phase(string)

Ends the current start phase: records the time since the previous phase ended (or since the profiler was created) under name.

C#
public void Phase(string name)

Parameters

name string

Save(string, int)

Writes ToJson to path, or ToCsv when it ends in “.csv”.

C#
public void Save(string path, int warmup = 0)

Parameters

path string

warmup int

Summarize(int)

Statistics of the kept frames, skipping the first warmup (start-up and JIT).

C#
public FrameSummary Summarize(int warmup = 0)

Parameters

warmup int

Returns

FrameSummary

ToCsv()

Every kept frame as CSV, one row per frame.

C#
public string ToCsv()

Returns

string

ToJson(int)

The results as JSON: environment, start phases, summary and every kept frame.

C#
public string ToJson(int warmup = 0)

Parameters

warmup int

Returns

string