carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package activator
2
3import (
4 "strings"
5 "time"
6)
7
8// wakeSteps times one wake step by step for the operator's journal. The
9// member's wake event carries the total and the spawn (wakeEventMessage);
10// this says where the rest went, which is what a slow wake's diagnosis
11// needs and what no single figure can show.
12type wakeSteps struct {
13 last time.Time
14 steps []wakeStep
15}
16
17type wakeStep struct {
18 name string
19 took time.Duration
20}
21
22// begin starts the clock. A mark before it records nothing.
23func (s *wakeSteps) begin(now time.Time) { s.last = now }
24
25// mark closes the step called name at now and starts the next.
26func (s *wakeSteps) mark(now time.Time, name string) {
27 if s.last.IsZero() {
28 return
29 }
30 s.steps = append(s.steps, wakeStep{name, now.Sub(s.last)})
31 s.last = now
32}
33
34func (s *wakeSteps) String() string {
35 parts := make([]string, len(s.steps))
36 for i, st := range s.steps {
37 parts[i] = st.name + " " + st.took.Round(time.Millisecond).String()
38 }
39 return strings.Join(parts, ", ")
40}
41