GraphicsTimingLog

Package: Libraries.Game.Graphics.Timing · Inherits from: Libraries.Language.Object

A GraphicsTimingLog keeps the GPU times of frame after frame, as a GraphicsTimer reads them. Give it to the timer with GraphicsTimer:SetLog; it keeps the most recent frames, 1,000 by default (SetLimit). From what it keeps it can: - summarize each phase: its average, minimum, maximum, a percentile and its share of the frame; - write everything as JSON (ToJson, Write), laid out to be read by people and AI tools: units in the names, a summary first, then each frame; - give the data as a DataFrame (GetDataFrame, GetSummaryDataFrame), to chart, sort or analyze with the statistics library; - make ready charts with the charting library: a bar chart of the last frames by phase (GetBarChart), a pie chart of the average shares (GetPieChart), and a line chart of every frame (GetLineChart). How it keeps the frames is its own business: programs add, ask, chart and write.

Example Code

use Libraries.Game.Game
use Libraries.Game.Graphics.Timing.GraphicsTimingLog
use Libraries.System.File

class Main is Game
GraphicsTimingLog timings

action Main
    UseVulkan(true)
    StartGame()
end

action CreateGame
    SetGraphicsTiming(true)
    timings:SetLimit(600)
    timings:SetNote("scene", "My world")
    GetGraphicsTimer():SetLog(timings)
end

action WriteTimings
    File file
    file:SetPath("timings.json")
    timings:Write(file)
end
end

Variables

  • text WHOLE_FRAME: The phase name the frame's whole time goes under in data frames.

Actions

Add(Libraries.Game.Graphics.Timing.GraphicsTimingFrame frame)

This action adds a frame. The timer calls it for each frame it reads.

Parameters

Empty()

This action lets go of every frame kept. Notes stay.

GetAverage(text name)

This action returns a phase's average GPU time over the kept frames that have it. WHOLE_FRAME gives the whole frame's.

Parameters

  • name text: The phase

Returns

number: Milliseconds, or 0 if no kept frame has it

GetBarChart(integer frameCount)

This action returns a bar chart of the last kept frames: for each frame, in frame order, a bar per phase, colored by phase, in milliseconds. It is made with the charting library from GetDataFrame's columns (Milliseconds by the factors Frame and Phase), without the whole-frame rows.

Parameters

  • frameCount integer: How many of the latest frames to show

Returns

Libraries.Interface.Controls.Charts.BarChart: The chart

GetBarChart()

This action returns a bar chart of the last 30 kept frames: for each frame, in frame order, a bar per phase, colored by phase, in milliseconds.

Returns

Libraries.Interface.Controls.Charts.BarChart: The chart

GetDataFrame()

This action returns the kept frames as a DataFrame, one row per frame and phase, oldest frame first, with the columns Frame (integer), Phase (text), Milliseconds (number), Start (number, milliseconds after the frame started) and Calls (integer). Each frame's whole time is a row too, with the phase WHOLE_FRAME ("Whole frame").

Returns

Libraries.Compute.Statistics.DataFrame: The data frame

GetFrame(integer index)

This action returns a kept frame, oldest first.

Parameters

  • index integer: The frame, from 0

Returns

Libraries.Game.Graphics.Timing.GraphicsTimingFrame: The frame

GetFrameCount()

This action returns how many frames are kept.

Returns

integer: The count

GetLimit()

This action sets how many of the most recent frames are kept. Older ones are let go as new ones come. 0 keeps every frame.

Returns

integer

GetLineChart()

This action returns a line chart of every kept frame: frame number across, milliseconds up, one line per phase, to see spikes and trends over a whole recording. It is made with the charting library from a data frame with a Frame column and one column per phase.

Returns

Libraries.Interface.Controls.Charts.LineChart: The chart

GetMaximum(text name)

This action returns a phase's most GPU time over the kept frames.

Parameters

  • name text: The phase

Returns

number: Milliseconds, or 0 if no kept frame has it

GetMinimum(text name)

This action returns a phase's least GPU time over the kept frames.

Parameters

  • name text: The phase

Returns

number: Milliseconds, or 0 if no kept frame has it

GetPercentile(text name, number percent)

This action returns the GPU time a phase stays at or under in a share of the kept frames, such as 95 for the 95th percentile.

Parameters

  • name text: The phase
  • percent number: From 0 to 100

Returns

number: Milliseconds, or 0 if no kept frame has it

GetPhaseNames()

This action returns every phase's name in the kept frames, in the order they first appear.

Returns

Libraries.Containers.Array<text>: The names

GetPieChart()

This action returns a pie chart of how an average frame's GPU time is shared among the phases. It is made with the charting library from GetSummaryDataFrame's Average by Phase.

Returns

Libraries.Interface.Controls.Charts.PieChart: The chart

GetShare(text name)

This action returns how much of the GPU's frame time a phase takes over the kept frames: its time added up over all frames, divided by all the frames' time.

Parameters

  • name text: The phase

Returns

number: The share, from 0 to 1

GetSummaryDataFrame()

This action returns a summary of each phase as a DataFrame, one row per phase, largest average first, with the columns Phase, Average, Minimum, Maximum, 95th Percentile and Share Of Frame (times in milliseconds, the share from 0 to 1).

Returns

Libraries.Compute.Statistics.DataFrame: The data frame

SetLimit(integer frameCount)

This action sets how many of the most recent frames are kept. Older ones are let go as new ones come. 0 keeps every frame.

Parameters

  • frameCount integer: The most frames to keep

SetNote(text key, text value)

This action sets a note written with the data, such as the scene or the settings being tried.

Parameters

  • key text: The note's name, such as "scene"
  • value text: The note, such as "QuincyWorld"

SetTimestampScale(number period, integer bits)

This action sets the device's clock, written with the data. The timer sets it.

Parameters

  • period number: Nanoseconds per GPU clock tick
  • bits integer: Valid bits of a timestamp

ToJson()

This action returns everything kept as JSON, laid out to be read by people and AI tools: what it is and its units, the device's clock, the notes, the limits of GPU timing, a summary of each phase (largest average first), and then each frame's phases.

Returns

Libraries.Data.Formats.JavaScriptObjectNotation: The JSON

Write(Libraries.System.File file)

This action writes ToJson to a file, pretty-printed.

Parameters

Inherited Actions

3 actions from Libraries.Language.Object