PerfStats

Collects frame times and named stage times (e.g. Renderer.getStageMsLastFrame()) over an interval, and summarizes them: fps, mean frame time, percentiles, the longest frame, spikes and each stage's average. Game.debugPrintPerfStats() uses one; a game can keep its own for its own report.

Properties

  • percentiles (Array.<float>)
  • spikeFactor (float)
  • stageNames (Array.<string>) — Stages to report, in order; empty reports every stage in the order first seen
  • runId (string)

Example

CODE
stats = new BGE.Debug.PerfStats({runId: "a"})
' each frame
stats.addFrame(dt * 1000, renderer.getStageMsLastFrame(), renderer.getStageCountsLastFrame())
' every few seconds
print "PERF " + stats.format(stats.getSummary())
stats.reset()

Constructor

new PerfStats(options?: BGE.Debug.PerfStatsOptions): PerfStats

Parameters

  • options (BGE.Debug.PerfStatsOptions, optional, default: "{}") — stageNames, percentiles, spikeFactor, runId

Instance Methods

addFrame( frameMs: float, stageMs?: roAssociativeArray, stageCounts?: roAssociativeArray, ): void

Adds one frame.

Parameters

  • frameMs (float) — the frame's time in milliseconds
  • stageMs (roAssociativeArray, optional, default: "{}") — stage name to milliseconds this frame
  • stageCounts (roAssociativeArray, optional, default: "{}") — stage name to how many times it ran this frame

Returns

  • void

getFrameCount(): integer

Returns

  • integer — frames added since the last reset()

reset(): void

Clears the frames, to start the next interval.

Returns

  • void

getSummary(): BGE.Debug.PerfStatsSummary

Summarizes the frames added since the last reset(). With no frames, every time is 0.

Returns

  • BGE.Debug.PerfStatsSummary

format(summary: BGE.Debug.PerfStatsSummary): string

A one-line report: "fps 30 frameMs 33.3 | | med 33 p90 40 max 51 spikes 2/90 | run a" (no stages or run when there are none).

Parameters

  • summary (BGE.Debug.PerfStatsSummary)

Returns

  • string

formatStages(summary: BGE.Debug.PerfStatsSummary): string

" | ms x" for each stage, or "" with none.

Parameters

  • summary (BGE.Debug.PerfStatsSummary)

Returns

  • string

formatFrameTimes(summary: BGE.Debug.PerfStatsSummary): string

" | med 33 p90 40 max 51 spikes 2/90" (whole milliseconds), or "" with no frames.

Parameters

  • summary (BGE.Debug.PerfStatsSummary)

Returns

  • string