Version: v0.0.0-...-1978dde Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2022 License: MIT, Unlicense Imports: 9 Imported by: 2



Go Reference

Profiling tools for gio



Package profiling provides tools for recording frame timings for later analysis.

The simplest usage is to construct a profilier at the start of your event loop function and to defer stopping it until the window is closed. Something like:

func loop(w *app.Window) error {
    // log to a CSV file with a randomly-chosen name. The file's path will be
    // logged to stderr.
    recorder, err := NewRecorder(nil)
    if err != nil {
        // handle
    defer recorder.Stop()

    var ops op.Ops

    for event := range window.Events() {
        switch event := event.(type) {
            case system.DestroyEvent:
                // returning will execute the deferred call to Stop(), which
                // flushes the CSV file.
                return event.Err
            case system.FrameEvent:
                gtx := layout.NewContext(&ops, event)

                // record the last frame's timing info and prepare the next one

                // lay out your UI here

The actual disk I/O is performed by a different goroutine and will not block the UI unless it gets more than 60 frames behind.



This section is empty.


This section is empty.


This section is empty.


type CSVTimingRecorder

type CSVTimingRecorder struct {
	// contains filtered or unexported fields

CSVTimingRecorder captures frame timing information into a CSV file

func NewRecorder

func NewRecorder(filename *string) (*CSVTimingRecorder, error)

NewRecorder creates a CSVTimingRecorder that will record to a CSV file with the provided name. If the name is nil, a temporary file will be used.

func (*CSVTimingRecorder) Profile

func (c *CSVTimingRecorder) Profile(gtx layout.Context)

Profile records profiling data from the last frame and prepares the capture of the next frame. Calling this method every frame is sufficient to profile all frames. It will simply return if c is nil.

func (*CSVTimingRecorder) Stop

func (c *CSVTimingRecorder) Stop() error

Stop shuts down the recording process and flushes all data to the CSV file.

func (*CSVTimingRecorder) Write

func (c *CSVTimingRecorder) Write(when time.Time, e profile.Event) error

Write is a lower-level way to capture a single profile event. It should be used instead of the Profile method if more granular profiling control is desired. It will simply return if c is nil.

type Timings

type Timings struct {
	// When is the timestamp of the frame that this struct describes
	When          time.Time
	Total         time.Duration
	FrameDuration time.Duration
	GPUTime       time.Duration
	ZT            time.Duration
	ST            time.Duration
	CovT          time.Duration

Timings holds frame timing information

func (Timings) CSVRow

func (t Timings) CSVRow() []string

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL