-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcache.go
187 lines (167 loc) · 6.49 KB
/
cache.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package main
import (
"sync"
perf_collector "github.com/hodgesds/perf-utils"
)
type Cache struct {
podPidPathes map[string]map[string]map[string]string
podContainerPids map[string]map[string][]string
sync.RWMutex
}
func NewCache() *Cache {
return &Cache{
podPidPathes: make(map[string]map[string]map[string]string, 0),
podContainerPids: make(map[string]map[string][]string, 0),
}
}
func (c *Cache) AddNewPodInfo(podInfo string, containerPids map[string][]string, containerPidPathes map[string]map[string]string) {
c.Lock()
defer c.Unlock()
c.podPidPathes[podInfo] = containerPidPathes
c.podContainerPids[podInfo] = containerPids
}
// Not used
// func (c *Cache) GetPodPidPathFromPodInfo(podInfo string) map[string]string {
// c.RLock()
// defer c.RUnlock()
// return c.podPidPathes[podInfo]
// }
func (c *Cache) DeletePodInfo(podInfo string) (map[string]map[string]string, map[string][]string) {
c.Lock()
defer c.Unlock()
deletePathesItem := make(map[string]map[string]string)
deletePidsItem := make(map[string][]string)
for container, pathes := range c.podPidPathes[podInfo] {
deletePathesItem[container] = pathes
}
for container, pids := range c.podContainerPids[podInfo] {
deletePidsItem[container] = pids
}
delete(c.podPidPathes, podInfo)
return deletePathesItem, deletePidsItem
}
func (c *Cache) GetAllPodPathInfo() map[string]map[string]map[string]string {
c.RLock()
defer c.RUnlock()
podPathInfoMap := make(map[string]map[string]map[string]string, 0)
for podInfo, containerPids := range c.podPidPathes {
podPathInfoMap[podInfo] = containerPids
}
return podPathInfoMap
}
func (c *Cache) GetAllPodPidInfo() map[string]map[string][]string {
c.RLock()
defer c.RUnlock()
podPidInfoMap := make(map[string]map[string][]string, 0)
for podInfo, containerPids := range c.podContainerPids {
podPidInfoMap[podInfo] = containerPids
}
return podPidInfoMap
}
func (c *Cache) GetPodPidInfoFromPodInfo(podInfo string) map[string][]string {
c.RLock()
defer c.RUnlock()
return c.podContainerPids[podInfo]
}
type PerfCollector struct {
podHwPerfCollector map[string]map[string]*perf_collector.HardwareProfiler
podSwPerfCollector map[string]map[string]*perf_collector.SoftwareProfiler
podCachePerfCollector map[string]map[string]*perf_collector.CacheProfiler
sync.RWMutex
}
func NewPerfCollector() *PerfCollector {
return &PerfCollector{
podHwPerfCollector: make(map[string]map[string]*perf_collector.HardwareProfiler, 0),
podSwPerfCollector: make(map[string]map[string]*perf_collector.SoftwareProfiler, 0),
podCachePerfCollector: make(map[string]map[string]*perf_collector.CacheProfiler, 0),
}
}
func (p *PerfCollector) AddNewPerfCollector(containerInfo string, pid string, hwprofiler *perf_collector.HardwareProfiler, swprofiler *perf_collector.SoftwareProfiler, cacheprofiler *perf_collector.CacheProfiler) {
p.Lock()
defer p.Unlock()
var exist bool
_, exist = p.podHwPerfCollector[containerInfo]
if !exist {
p.podHwPerfCollector[containerInfo] = map[string]*perf_collector.HardwareProfiler{}
}
_, exist = p.podHwPerfCollector[containerInfo][pid]
if !exist {
p.podHwPerfCollector[containerInfo][pid] = hwprofiler
}
_, exist = p.podSwPerfCollector[containerInfo]
if !exist {
p.podSwPerfCollector[containerInfo] = map[string]*perf_collector.SoftwareProfiler{}
}
_, exist = p.podSwPerfCollector[containerInfo][pid]
if !exist {
p.podSwPerfCollector[containerInfo][pid] = swprofiler
}
_, exist = p.podCachePerfCollector[containerInfo]
if !exist {
p.podCachePerfCollector[containerInfo] = map[string]*perf_collector.CacheProfiler{}
}
_, exist = p.podCachePerfCollector[containerInfo][pid]
if !exist{
p.podCachePerfCollector[containerInfo][pid] = cacheprofiler
}
}
// func (p *PerfCollector) GetHwPerfCollectorFromContainerInfo(containerInfo string) *perf_collector.HardwareProfiler {
// p.RLock()
// defer p.RUnlock()
// return p.podHwPerfCollector[containerInfo]
// }
// func (p *PerfCollector) GetSwPerfCollectorFromContainerInfo(containerInfo string) *perf_collector.SoftwareProfiler {
// p.RLock()
// defer p.RUnlock()
// return p.podSwPerfCollector[containerInfo]
// }
func (p *PerfCollector) DeletePerfCollector(containerInfo string) (map[string]map[string]*perf_collector.HardwareProfiler, map[string]map[string]*perf_collector.SoftwareProfiler, map[string]map[string]*perf_collector.CacheProfiler) {
p.Lock()
defer p.Unlock()
deleteHwItem := make(map[string]map[string]*perf_collector.HardwareProfiler)
deleteSwItem := make(map[string]map[string]*perf_collector.SoftwareProfiler)
deleteCacheItem := make(map[string]map[string]*perf_collector.CacheProfiler)
deleteHwItem[containerInfo] = p.podHwPerfCollector[containerInfo]
deleteSwItem[containerInfo] = p.podSwPerfCollector[containerInfo]
deleteCacheItem[containerInfo] = p.podCachePerfCollector[containerInfo]
delete(p.podHwPerfCollector, containerInfo)
delete(p.podSwPerfCollector, containerInfo)
delete(p.podCachePerfCollector, containerInfo)
return deleteHwItem, deleteSwItem, deleteCacheItem
}
func (p *PerfCollector) GetAllHwPerfCollector() map[string]map[string]*perf_collector.HardwareProfiler {
p.RLock()
defer p.RUnlock()
hwPerfCollectorMap := make(map[string]map[string]*perf_collector.HardwareProfiler, 0)
for cotnainerInfo, hwprofilerMap := range p.podHwPerfCollector {
hwPerfCollectorMap[cotnainerInfo] = map[string]*perf_collector.HardwareProfiler{}
for pid, hwprofiler := range hwprofilerMap {
hwPerfCollectorMap[cotnainerInfo][pid] = hwprofiler
}
}
return hwPerfCollectorMap
}
func (p *PerfCollector) GetAllSwPerfCollector() map[string]map[string]*perf_collector.SoftwareProfiler {
p.RLock()
defer p.RUnlock()
swPerfCollectorMap := make(map[string]map[string]*perf_collector.SoftwareProfiler, 0)
for containerInfo, swprofilerMap := range p.podSwPerfCollector {
swPerfCollectorMap[containerInfo] = map[string]*perf_collector.SoftwareProfiler{}
for pid, swprofiler := range swprofilerMap {
swPerfCollectorMap[containerInfo][pid] = swprofiler
}
}
return swPerfCollectorMap
}
func (p *PerfCollector) GetAllCachePerfCollector() map[string]map[string]*perf_collector.CacheProfiler {
p.RLock()
defer p.RUnlock()
cachePerfCollectorMap := make(map[string]map[string]*perf_collector.CacheProfiler, 0)
for containerInfo, cacheprofilerMap := range p.podCachePerfCollector {
cachePerfCollectorMap[containerInfo] = map[string]*perf_collector.CacheProfiler{}
for pid, cacheprofiler := range cacheprofilerMap {
cachePerfCollectorMap[containerInfo][pid] = cacheprofiler
}
}
return cachePerfCollectorMap
}