main 5041353

timing.go RawHistoryFolder

1// Package bootstrap provides initialization utilities for the browser.
2package bootstrap
3
4import (
5	"context"
6	"sync"
7	"time"
8
9	"github.com/bnema/dumber/internal/logging"
10)
11
12// StartupTimer tracks timing for cold start phases.
13// Thread-safe for use with parallel initialization.
14type StartupTimer struct {
15	start  time.Time
16	phases map[string]time.Duration
17	order  []string // Track insertion order for logging
18	last   time.Time
19	mu     sync.Mutex
20}
21
22// NewStartupTimer creates a new timer starting from now.
23func NewStartupTimer() *StartupTimer {
24	now := time.Now()
25	return &StartupTimer{
26		start:  now,
27		phases: make(map[string]time.Duration),
28		order:  make([]string, 0),
29		last:   now,
30	}
31}
32
33// Mark records the duration since the last mark (or start) for the given phase.
34func (t *StartupTimer) Mark(phase string) {
35	t.mu.Lock()
36	defer t.mu.Unlock()
37
38	now := time.Now()
39	t.phases[phase] = now.Sub(t.last)
40	t.order = append(t.order, phase)
41	t.last = now
42}
43
44// MarkDuration records a specific duration for a phase.
45// Useful for operations timed independently (e.g., parallel goroutines).
46func (t *StartupTimer) MarkDuration(phase string, d time.Duration) {
47	t.mu.Lock()
48	defer t.mu.Unlock()
49
50	t.phases[phase] = d
51	t.order = append(t.order, phase)
52}
53
54// Total returns the total elapsed time since timer creation.
55// Thread-safe: uses mutex for memory visibility guarantees.
56func (t *StartupTimer) Total() time.Duration {
57	t.mu.Lock()
58	defer t.mu.Unlock()
59	return time.Since(t.start)
60}
61
62// Log outputs all timing information to the context logger.
63func (t *StartupTimer) Log(ctx context.Context) {
64	t.mu.Lock()
65	defer t.mu.Unlock()
66
67	log := logging.FromContext(ctx)
68	total := time.Since(t.start)
69
70	event := log.Info().Dur("total", total)
71	for _, phase := range t.order {
72		if dur, ok := t.phases[phase]; ok {
73			event = event.Dur(phase, dur)
74		}
75	}
76	event.Msg("startup timing")
77}
78
79// LogDebug outputs timing as debug level (for less verbose production logs).
80func (t *StartupTimer) LogDebug(ctx context.Context) {
81	t.mu.Lock()
82	defer t.mu.Unlock()
83
84	log := logging.FromContext(ctx)
85	total := time.Since(t.start)
86
87	event := log.Debug().Dur("total", total)
88	for _, phase := range t.order {
89		if dur, ok := t.phases[phase]; ok {
90			event = event.Dur(phase, dur)
91		}
92	}
93	event.Msg("startup timing")
94}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close