GitHubНачать

Справочник API собран из Go doc-комментариев в исходном коде и написан на английском языке.

package sessionstats

import "github.com/nsgo-dev/game/pkg/sessionstats"

Обзор

Package sessionstats is experimental: its API and documented formats may change in a minor release. See the API stability policy. records release-safe frame pacing and runtime memory metrics.

Указатель

Типы

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder keeps a bounded frame-time sample window and release-safe runtime metrics.

func New(interval time.Duration) *Recorder

New returns a recorder for a target frame interval (16 ms when zero or negative), against which it counts frames that take twice as long.

func (r *Recorder) Observe(dt time.Duration)

Observe records one foreground frame. It ignores non-positive durations and samples while paused.

func (r *Recorder) SetPaused(paused bool)

SetPaused excludes samples while the application is backgrounded.

func (r *Recorder) Summary() Summary

Summary returns the session so far: the p50, p95 and p99 frame times of the last 4096 frames, the longest frame, the count of frames at least twice the interval, and the peak heap, runtime memory, GC cycles and longest GC pause observed.

type Summary struct {
	Version     int           `json:"version" yaml:"version"`
	Frames      uint64        `json:"frames" yaml:"frames"`
	P50         time.Duration `json:"p50" yaml:"p50"`
	P95         time.Duration `json:"p95" yaml:"p95"`
	P99         time.Duration `json:"p99" yaml:"p99"`
	Longest     time.Duration `json:"longest" yaml:"longest"`
	Jank2x      uint64        `json:"jank2x" yaml:"jank2x"`
	HeapPeak    uint64        `json:"heapPeak" yaml:"heapPeak"`
	TotalMemory uint64        `json:"totalMemory" yaml:"totalMemory"`
	GCCycles    uint64        `json:"gcCycles" yaml:"gcCycles"`
	MaxPause    time.Duration `json:"maxPause" yaml:"maxPause"`
}

Summary is a deterministic snapshot of one recording session.

func (s Summary) MarshalJSON() ([]byte, error)

MarshalJSON keeps field order stable for analytics payloads and snapshots.