-
Notifications
You must be signed in to change notification settings - Fork 2k
/
structs.go
126 lines (106 loc) · 2.99 KB
/
structs.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package structs
// MemoryStats holds memory usage related stats
type MemoryStats struct {
RSS uint64
Cache uint64
Swap uint64
MaxUsage uint64
KernelUsage uint64
KernelMaxUsage uint64
// A list of fields whose values were actually sampled
Measured []string
}
func (ms *MemoryStats) Add(other *MemoryStats) {
ms.RSS += other.RSS
ms.Cache += other.Cache
ms.Swap += other.Swap
ms.MaxUsage += other.MaxUsage
ms.KernelUsage += other.KernelUsage
ms.KernelMaxUsage += other.KernelMaxUsage
ms.Measured = joinStringSet(ms.Measured, other.Measured)
}
// CpuStats holds cpu usage related stats
type CpuStats struct {
SystemMode float64
UserMode float64
TotalTicks float64
ThrottledPeriods uint64
ThrottledTime uint64
Percent float64
// A list of fields whose values were actually sampled
Measured []string
}
func (cs *CpuStats) Add(other *CpuStats) {
cs.SystemMode += other.SystemMode
cs.UserMode += other.UserMode
cs.TotalTicks += other.TotalTicks
cs.ThrottledPeriods += other.ThrottledPeriods
cs.ThrottledTime += other.ThrottledTime
cs.Percent += other.Percent
cs.Measured = joinStringSet(cs.Measured, other.Measured)
}
// ResourceUsage holds information related to cpu and memory stats
type ResourceUsage struct {
MemoryStats *MemoryStats
CpuStats *CpuStats
}
func (ru *ResourceUsage) Add(other *ResourceUsage) {
ru.MemoryStats.Add(other.MemoryStats)
ru.CpuStats.Add(other.CpuStats)
}
// TaskResourceUsage holds aggregated resource usage of all processes in a Task
// and the resource usage of the individual pids
type TaskResourceUsage struct {
ResourceUsage *ResourceUsage
Timestamp int64
Pids map[string]*ResourceUsage
}
// AllocResourceUsage holds the aggregated task resource usage of the
// allocation.
type AllocResourceUsage struct {
// ResourceUsage is the summation of the task resources
ResourceUsage *ResourceUsage
// Tasks contains the resource usage of each task
Tasks map[string]*TaskResourceUsage
// The max timestamp of all the Tasks
Timestamp int64
}
// joinStringSet takes two slices of strings and joins them
func joinStringSet(s1, s2 []string) []string {
lookup := make(map[string]struct{}, len(s1))
j := make([]string, 0, len(s1))
for _, s := range s1 {
j = append(j, s)
lookup[s] = struct{}{}
}
for _, s := range s2 {
if _, ok := lookup[s]; !ok {
j = append(j, s)
}
}
return j
}
// FSIsolation is an enumeration to describe what kind of filesystem isolation
// a driver supports.
type FSIsolation int
const (
// FSIsolationNone means no isolation. The host filesystem is used.
FSIsolationNone FSIsolation = 0
// FSIsolationChroot means the driver will use a chroot on the host
// filesystem.
FSIsolationChroot FSIsolation = 1
// FSIsolationImage means the driver uses an image.
FSIsolationImage FSIsolation = 2
)
func (f FSIsolation) String() string {
switch f {
case 0:
return "none"
case 1:
return "chroot"
case 2:
return "image"
default:
return "INVALID"
}
}