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 ¶
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.
const FirstPaintKey = "startup.first_paint_ms"
FirstPaintKey is the key every first-paint record carries, followed by the milliseconds from process start.
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 ¶
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.