API 參考取自原始碼中的 Go 文件註解,以英文撰寫。
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) *RecorderNew 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() SummarySummary 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.