window

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 17 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 window watches the page of Djinn's native window from outside it, on Linux. When the web process that draws the page ends (after an Intel GPU hang, out of memory, or killed; W353, W366), it is logged with WebKit's state (the page's load events, the web processes' CPU and memory) and the kernel's GPU hangs, told outside the window, and rescued step by step, once each: the page loads again, then the window opens again with a new view. The new view draws in software rendering only after a GPU hang, until Djinn restarts: rendering stays on the GPU at every start (decision Q89).

A page can also load and then wait, its web process alive and idle, never calling the server (W373, W172): a page that makes no call within Silence of its load finished is silent. It is logged with a probe of the page and the web processes' threads, then loaded again once per djinn up, and told nowhere else: no notification, no line on djinn up's output (decisions Q108, Q111), a false alarm costing only a reload.

Index

Constants

View Source
const Lookback = 10 * time.Minute

Lookback is how long before djinn up started the kernel's log is read: the hang that kills a web process may come just before a start (17/10: 30 s before an install restarted Djinn).

View Source
const MaxHangs = 12

MaxHangs is how many hangs a Watch keeps, the latest: a driver that hangs in a loop fills the kernel's log.

View Source
const ProbeScript = `` /* 576-byte string literal not displayed */

ProbeScript is what the probe of a silent page evaluates in it: how far the document went, whether the loader still shows and the interface mounted, and whether boot.js attached the entry module (the page's load finishes before it does, vite.config.ts), with the document's scripts. The resource timing would name the loads still pending, but it lists nothing loaded from wails:// (W181's native run): no field for it.

View Source
const ProbeWait = 2 * time.Second

ProbeWait is how long the probe of a silent page has to answer: no answer tells a JS thread that does not run.

View Source
const Sample = 500 * time.Millisecond

Sample is how long the web processes' CPU is measured, when a page's web process ends.

View Source
const Silence = 3 * time.Second

Silence is how long a page has, from its load finished, to call the server (decision Q111): a good start calls about 0.2 s after (W172), a stuck one not at all in 85 s.

Variables

View Source
var Journal = func(ctx context.Context, since time.Time) ([]byte, error) {
	if runtime.GOOS != "linux" {
		return nil, nil
	}
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	return exec.CommandContext(ctx, "journalctl", "-k", "-q", "--no-pager", "-o", "short-iso",
		"--since", "@"+strconv.FormatInt(since.Unix(), 10)).Output()
}

Journal is the kernel's log of this boot since a time, as journalctl -o short-iso prints it; nothing outside Linux. Tests replace it.

View Source
var ProcRoot = "/proc"

ProcRoot is where the processes are read: /proc. Tests replace it.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Ended is the reason the page's web process ended ("crashed", "memory", "terminated").
	Ended string
	// Hangs are the GPU hangs and resets of the kernel's log since Lookback before djinn up started.
	Hangs []Hang
	// Did is what the Watch did.
	Did Rescue
	// Software tells that the new view draws in software rendering, after a GPU hang, until Djinn restarts.
	Software bool
	// Err is why the page could not load again, or the window open again.
	Err error
}

Event is what a Watch tells outside the window.

type Hang

type Hang struct {
	// Time is when the kernel logged it; zero when the line names none.
	Time time.Time
	// Line is the line, without its time and host.
	Line string
}

Hang is a line of the kernel's log that tells a GPU hang or reset.

func Hangs

func Hangs(log []byte) []Hang

Hangs is the GPU hangs and resets of a kernel log, the last MaxHangs.

func KernelHangs

func KernelHangs(ctx context.Context, since time.Time) ([]Hang, error)

KernelHangs is the GPU hangs and resets of the kernel's log since a time, the last MaxHangs.

type Process

type Process struct {
	PID int
	// Name is the kernel's, cut at 15 characters: WebKitWebProces, WebKitNetworkPr.
	Name string
	// State is the kernel's letter: R running, S sleeping, D waiting on a disk, Z a zombie.
	State string
	// RSS is the memory it holds, in bytes.
	RSS uint64
	// CPU is the CPU time it took since it started.
	CPU time.Duration
	// Threads is what its threads wait on, from /proc/<pid>/task: its main thread's state and wchan, then each state
	// and wchan with its count, the most first: "main S do_epoll_wait, threads 24 (18 S futex_wait_queue, 6 S
	// do_epoll_wait)". Empty when it cannot be read.
	Threads string
}

Process is a process of WebKit, as the log of a dead or silent page names it.

func WebKitProcesses

func WebKitProcesses(parent int) []Process

WebKitProcesses is the processes of WebKit parent started: its web and network processes.

func (Process) Describe

func (p Process) Describe(before []Process, sample time.Duration) string

Describe names p for the log: its PID, name, state, memory, CPU time, and its CPU over sample when before holds it: "pid 4242 WebKitWebProces S rss 155 MB cpu 1.2 s, 0 % over 500ms", then what its threads wait on.

type Rescue

type Rescue int

Rescue is what a Watch did about a dead page.

const (
	// Nothing: the page loaded again and the window opened again already, or neither can be done.
	Nothing Rescue = iota
	// Reloaded: the page loads again, in the same view.
	Reloaded
	// Recreated: the window opens again, with a new view and a new web process.
	Recreated
)

type Watch

type Watch struct {
	// After is how long a page has, from its load finished, to call the server: Silence when zero.
	After time.Duration
	// Probe evaluates script in the current page and gives its answer as JSON. Nil: a silent page is logged without.
	Probe func(ctx context.Context, script string) (string, error)
	// ProbeWait is how long the probe has to answer: ProbeWait when zero.
	ProbeWait time.Duration
	// AfterFunc runs f after d unless the returned function stops it first: time.AfterFunc when nil. Tests replace it.
	AfterFunc func(d time.Duration, f func()) (stop func() bool)
	// Started is when djinn up started: the kernel's log is read from Lookback before it, the load events are timed
	// from it.
	Started time.Time
	// Hangs reads the GPU hangs and resets of the kernel's log since a time: KernelHangs when nil. Tests replace it.
	Hangs func(ctx context.Context, since time.Time) ([]Hang, error)
	// Processes reads the web processes of the window: djinn up's children whose name starts with WebKit, when nil.
	// Tests replace it.
	Processes func() []Process
	// Sample is how long the web processes' CPU is measured: Sample when zero, none when negative.
	Sample time.Duration
	// Reload loads the page again in its view. Nil: no reload.
	Reload func() error
	// Recreate opens the window again with a new view, in software rendering when software, in place of the dead one.
	// Nil: no new view.
	Recreate func(software bool) error
	// Tell says what happened outside the window: a line where djinn up runs, a desktop notification. Nil says nothing.
	Tell func(Event)
	// contains filtered or unexported fields
}

Watch follows the windows of one djinn up: Opened as each opens, Loaded at each of its page's load events, Called as its page calls the server, Ended as its web process ends. It reloads a dead page once and recreates a window once, and reloads a silent page once, per djinn up, never in a loop.

func (*Watch) Called added in v0.5.0

func (w *Watch) Called()

Called tells that the current page called the server: it runs. The first call of each document is logged.

func (*Watch) Ended

func (w *Watch) Ended(reason string)

Ended tells that the web process of the current page ended, for reason, at its start or any time after: the page is dead.

func (*Watch) Handler added in v0.5.0

func (w *Watch) Handler(h http.Handler) http.Handler

Handler marks each call of the window's page to h: a Connect method, not a file of the page, which the web process loads before any script runs.

func (*Watch) Loaded

func (w *Watch) Loaded(event string)

Loaded logs a load event of the current window's page ("started", "committed", "finished", "failed: …"), and keeps it for the log of a dead or silent page. A document committed is a new one, not heard yet; once its load finished, it has After to call the server.

func (*Watch) Opened

func (w *Watch) Opened()

Opened tells that a window opened, its page the current one from now on.

Jump to

Keyboard shortcuts

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