forked from rainycape/gondola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
56 lines (48 loc) · 1.21 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package profile
import (
"time"
)
const (
// HeaderName is the header used for transmitting profiling
// information while profiling a remote application.
HeaderName = "X-Gondola-Profile"
// Salt is the salt used for signing the app secret for requesting
// profiling information.
Salt = "gnd.la/app/profile.salt"
)
// Note represents a note added to an event.
type Note struct {
Title string
Text string
}
// Event represents a finished event when its timing information
// and any notes it might have attached.
type Event struct {
Started time.Time `json:"s"`
Ended time.Time `json:"e"`
Notes []*Note `json:"n"`
}
// Ellapsed returns the time the event took.
func (e *Event) Elapsed() time.Duration {
return e.Ended.Sub(e.Started)
}
// Timing represents a set of events of the same
// kind.
type Timing struct {
Name string `json:"n"`
Events []*Event `json:"e"`
}
// Count returns the number of events contained in this
// timing.
func (t *Timing) Count() int {
return len(t.Events)
}
// Total returns the total elapsed time for all the events
// in this Timing.
func (t *Timing) Total() time.Duration {
total := time.Duration(0)
for _, v := range t.Events {
total += v.Elapsed()
}
return total
}