Download this file
| 1 | package activator |
| 2 | |
| 3 | import ( |
| 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. |
| 12 | type wakeSteps struct { |
| 13 | last time.Time |
| 14 | steps []wakeStep |
| 15 | } |
| 16 | |
| 17 | type wakeStep struct { |
| 18 | name string |
| 19 | took time.Duration |
| 20 | } |
| 21 | |
| 22 | // begin starts the clock. A mark before it records nothing. |
| 23 | func (s *wakeSteps) begin(now time.Time) { s.last = now } |
| 24 | |
| 25 | // mark closes the step called name at now and starts the next. |
| 26 | func (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 | |
| 34 | func (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 | |