timing

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package timing measures how long the app takes to show its first frame.

The measurement runs from the moment the operating system started the process to the moment the frontend reports its first paint. On systems where the process start time cannot be read, it falls back to the moment the Go runtime initialized this package, which is slightly later; every measurement records which source it used.

Index

Constants

View Source
const (
	// SourceOS is the start time the operating system recorded for the process.
	SourceOS = "os"

	// SourceRuntime is the time the Go runtime initialized this package.
	SourceRuntime = "runtime"
)

Sources of the process start time.

View Source
const FirstPaintKey = "startup.first_paint_ms"

FirstPaintKey is the key every first-paint record carries, followed by the milliseconds from process start.

View Source
const LogFileName = "timing.log"

LogFileName is the file under the logs directory that collects timing lines.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Logger receives the timing record. Without it the record is not logged.
	Logger *slog.Logger

	// LogsDir is the directory whose timing.log gets the timing line. Empty skips the
	// file.
	LogsDir string

	// Start is the process start time; zero uses processStart.
	Start time.Time

	// Source names where Start came from; it is ignored when Start is zero.
	Source string

	// Now tells the time. It defaults to time.Now.
	Now func() time.Time
}

Config holds a Recorder's settings. Every field is optional.

type Measurement

type Measurement struct {
	// FirstPaintMS is the milliseconds from process start to the first paint.
	FirstPaintMS int64

	// Source is where the start time came from: SourceOS or SourceRuntime.
	Source string
}

Measurement is one first-paint reading.

func (Measurement) String

func (m Measurement) String() string

String formats the measurement as a timing line, e.g. "startup.first_paint_ms=412 source=os".

type Recorder

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

Recorder records the first paint exactly once.

func NewRecorder

func NewRecorder(cfg Config) *Recorder

NewRecorder returns a Recorder for the current process.

func (*Recorder) FirstPaint

func (r *Recorder) FirstPaint() (Measurement, bool, error)

FirstPaint records the time from process start to now as the first paint. The first call logs it and appends it to the timing log, and returns true; later calls return the first measurement and false without recording again. An error means the timing log could not be written; the measurement is still valid and was still logged.

Jump to

Keyboard shortcuts

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