github.com/GuanceCloud/cliutils@v1.1.21/pprofparser/domain/events/type.go (about) 1 package events 2 3 import ( 4 "github.com/GuanceCloud/cliutils/pprofparser/domain/languages" 5 "github.com/GuanceCloud/cliutils/pprofparser/domain/quantity" 6 ) 7 8 const ( 9 DefaultMetaFileName = "event" 10 DefaultMetaFileNameWithExt = "event.json" 11 DefaultProfileFilename = "prof" 12 DefaultProfileFilenameWithExt = "prof.pprof" 13 ) 14 15 const ( 16 CpuSamples Type = "cpu-samples" 17 CpuTime Type = "cpu-time" 18 WallTime Type = "wall-time" 19 HeapLiveSize Type = "heap-space" 20 HeapLiveObjects Type = "heap-live-objects" 21 Mutex Type = "mutex" 22 Block Type = "block" 23 Goroutines Type = "goroutines" 24 AllocatedMemory Type = "alloc-space" 25 Allocations Type = "alloc-samples" 26 ThrownExceptions Type = "exception-samples" 27 LockWaitTime Type = "lock-acquire-wait" 28 LockedTime Type = "lock-release-hold" 29 LockAcquires Type = "lock-acquire" 30 LockReleases Type = "lock-release" 31 Other Type = "other" 32 Unknown Type = "unknown" 33 ) 34 35 const ( 36 ShowNoWay ShowPlace = 0 37 ShowInTrace ShowPlace = 1 38 ShowInProfile ShowPlace = 2 39 ) 40 41 var TypeProfileFilename = map[languages.Lang]map[Type]string{ 42 languages.Python: {}, 43 44 languages.GoLang: {}, 45 } 46 47 var Metas = map[Type]TypeMetadata{ 48 CpuSamples: { 49 Sort: sortMap{languages.Python: 0, languages.GoLang: 0, languages.NodeJS: 0}, 50 Name: "CPU Samples", 51 Description: descriptionMap{languages.Any: "This is the number of samples each method spent running on the CPU."}, 52 QuantityKind: quantity.Count, 53 ShowPlaces: ShowNoWay, 54 }, 55 56 CpuTime: { 57 Sort: sortMap{languages.Python: 10, languages.GoLang: 10, languages.DotNet: 10}, //map[languages.Lang]int{languages.Python: 10, languages.GoLang: 10}, 58 Name: "CPU Time", 59 Description: descriptionMap{languages.Any: "This is the time each method spent running on the CPU."}, 60 QuantityKind: quantity.Duration, 61 ShowPlaces: ShowInTrace | ShowInProfile, 62 }, 63 64 WallTime: { 65 Sort: sortMap{languages.Python: 20, languages.DotNet: 80}, //map[languages.Lang]int{languages.Python: 20, languages.GoLang: 20}, 66 Name: "Wall Time", 67 Description: descriptionMap{languages.Any: "This is the elapsed time spent in each method. Elapsed time includes time when code is running on CPU, waiting for I/O, and anything else that happens while the function is running."}, 68 QuantityKind: quantity.Duration, 69 ShowPlaces: ShowInProfile, 70 }, 71 72 HeapLiveSize: { 73 Sort: sortMap{languages.Python: 30, languages.NodeJS: 30, languages.DotNet: 70}, //map[languages.Lang]int{languages.Python: 30, languages.GoLang: 30}, 74 Name: "Heap Live Size", 75 Description: descriptionMap{languages.Any: "This is the amount of heap memory allocated that remains in use.", 76 languages.GoLang: `This is the amount of heap memory allocated by each function that remains in use. (Go calls this "inuse_space").`, 77 }, 78 QuantityKind: quantity.Memory, 79 ShowPlaces: ShowInProfile, 80 }, 81 82 HeapLiveObjects: { 83 Sort: sortMap{languages.Python: 31, languages.NodeJS: 31, languages.DotNet: 60}, //map[languages.Lang]int{languages.Python: 31, languages.GoLang: 31}, 84 Name: "Heap Live Objects", 85 Description: descriptionMap{languages.Any: `This is the number of objects allocated by each function that remain in use. `, 86 languages.GoLang: `This is the number of objects allocated by each function that remain in use. (Go calls this "inuse_objects").`, 87 }, 88 QuantityKind: quantity.Count, 89 ShowPlaces: ShowInProfile, 90 }, 91 92 Mutex: { 93 Sort: sortMap{languages.Python: 32}, //map[languages.Lang]int{languages.Python: 32, languages.GoLang: 32}, 94 Name: "Mutex", 95 Description: descriptionMap{languages.GoLang: `This is the time each function spent waiting on mutexes during the profiling period.`}, 96 QuantityKind: quantity.Duration, 97 ShowPlaces: ShowInProfile, 98 }, 99 100 Block: { 101 Sort: sortMap{languages.Python: 33}, //map[languages.Lang]int{languages.Python: 33, languages.GoLang: 33}, 102 Name: "Block", 103 Description: descriptionMap{languages.Any: `This is the time each function spent blocked since the start of the process.`}, 104 QuantityKind: quantity.Duration, 105 ShowPlaces: ShowInProfile, 106 }, 107 108 Goroutines: { 109 Sort: sortMap{languages.Python: 34}, //map[languages.Lang]int{languages.Python: 34, languages.GoLang: 34}, 110 Name: "Goroutines", 111 Description: descriptionMap{languages.Any: `This is the number of goroutines.`}, 112 QuantityKind: quantity.Count, 113 ShowPlaces: ShowInProfile, 114 }, 115 116 AllocatedMemory: { 117 Sort: sortMap{languages.Python: 40, languages.DotNet: 40}, //map[languages.Lang]int{languages.Python: 40, languages.GoLang: 40}, 118 Name: "Allocated Memory", 119 Description: descriptionMap{languages.Any: "This is the amount of heap memory allocated by each method, including allocations which were subsequently freed.", 120 languages.GoLang: `This is the amount of heap memory allocated by each function during the profiling period, including allocations which were subsequently freed. (Go calls this "alloc_space").`, 121 }, 122 QuantityKind: quantity.Memory, 123 ShowPlaces: ShowInProfile, 124 }, 125 126 Allocations: { 127 Sort: sortMap{languages.Python: 50, languages.DotNet: 30}, //map[languages.Lang]int{languages.Python: 50, languages.GoLang: 50}, 128 Name: "Allocations", 129 Description: descriptionMap{languages.Any: "This is the number of heap allocations made by each method, including allocations which were subsequently freed.", 130 languages.GoLang: "This is the number of objects allocated by each function during the profiling period, including allocations which were subsequently freed. (Go calls this \"alloc_objects\").", 131 }, 132 QuantityKind: quantity.Count, 133 ShowPlaces: ShowInProfile, 134 }, 135 136 ThrownExceptions: { 137 Sort: sortMap{languages.Python: 60, languages.DotNet: 20}, //map[languages.Lang]int{languages.Python: 60, languages.GoLang: 60}, 138 Name: "Thrown Exceptions", 139 Description: descriptionMap{languages.Any: "This is the number of exceptions thrown by each method."}, 140 QuantityKind: quantity.Count, 141 ShowPlaces: ShowInProfile, 142 }, 143 144 LockWaitTime: { 145 Sort: sortMap{languages.Python: 70, languages.DotNet: 110}, //map[languages.Lang]int{languages.Python: 70, languages.GoLang: 70}, 146 Name: "Lock Wait Time", 147 Description: descriptionMap{languages.Any: "This is the time each function spent waiting for a lock."}, 148 QuantityKind: quantity.Duration, 149 ShowPlaces: ShowInTrace | ShowInProfile, 150 }, 151 152 LockedTime: { 153 Sort: sortMap{languages.Python: 80}, //map[languages.Lang]int{languages.Python: 80, languages.GoLang: 80}, 154 Name: "Locked Time", 155 Description: descriptionMap{languages.Any: "This is the time each function spent holding a lock."}, 156 QuantityKind: quantity.Duration, 157 ShowPlaces: ShowInTrace | ShowInProfile, 158 }, 159 160 LockAcquires: { 161 Sort: sortMap{languages.Python: 90, languages.DotNet: 100}, //map[languages.Lang]int{languages.Python: 90, languages.GoLang: 90}, 162 Name: "Lock Acquires", 163 Description: descriptionMap{languages.Any: "This is the number of lock acquisitions made by each method."}, 164 QuantityKind: quantity.Count, 165 ShowPlaces: ShowInProfile, 166 }, 167 168 LockReleases: { 169 Sort: sortMap{languages.Python: 100}, //map[languages.Lang]int{languages.Python: 100, languages.GoLang: 100}, 170 Name: "Lock Releases", 171 Description: descriptionMap{languages.Any: "This is the number of times each function released a lock."}, 172 QuantityKind: quantity.Count, 173 ShowPlaces: ShowInProfile, 174 }, 175 Other: { 176 Sort: sortMap{languages.Python: 110}, //map[languages.Lang]int{languages.Python: 110, languages.GoLang: 110}, 177 Name: "Other", 178 Description: descriptionMap{languages.Any: "Methods that used the most uncategorized time."}, 179 QuantityKind: quantity.Duration, 180 ShowPlaces: ShowInTrace, 181 }, 182 } 183 184 type Type string 185 186 func ParseType(typ string) Type { 187 et := Type(typ) 188 if _, ok := Metas[et]; ok { 189 return et 190 } 191 return Unknown 192 } 193 194 func (et Type) String() string { 195 return string(et) 196 } 197 198 func (et Type) Equals(target Type) bool { 199 return et.String() == target.String() 200 } 201 202 func (et Type) GetSort(lang languages.Lang) int { 203 if meta, ok := Metas[et]; ok { 204 if sort, ok := meta.Sort[lang]; ok { 205 return sort 206 } 207 if sort, ok := meta.Sort[languages.Any]; ok { 208 return sort 209 } 210 } 211 return 1 << 30 212 } 213 214 func (et Type) GetName() string { 215 if meta, ok := Metas[et]; ok { 216 return meta.Name 217 } 218 return "unknown" 219 } 220 221 func (et Type) GetDescription(lang languages.Lang) string { 222 if meta, ok := Metas[et]; ok { 223 if desc, ok := meta.Description[lang]; ok { 224 return desc 225 } 226 if desc, ok := meta.Description[languages.Any]; ok { 227 return desc 228 } 229 } 230 return "unknown metric type" 231 } 232 233 func (et Type) GetQuantityKind() *quantity.Kind { 234 if meta, ok := Metas[et]; ok { 235 return meta.QuantityKind 236 } 237 return quantity.UnknownKind 238 } 239 240 func (et Type) GetShowPlaces() ShowPlace { 241 if meta, ok := Metas[et]; ok { 242 return meta.ShowPlaces 243 } 244 return ShowNoWay 245 } 246 247 type TypeMetadata struct { 248 Sort sortMap 249 Name string 250 Description descriptionMap 251 QuantityKind *quantity.Kind 252 ShowPlaces ShowPlace 253 } 254 255 type ShowPlace int 256 257 // sortMap used to generate sort map for convenience 258 type sortMap map[languages.Lang]int 259 260 func newSortMap() sortMap { 261 return make(sortMap) 262 } 263 264 func (sm sortMap) put(lang languages.Lang, sort int) sortMap { 265 sm[lang] = sort 266 return sm 267 } 268 269 type descriptionMap map[languages.Lang]string 270 271 func newDescriptionMap() descriptionMap { 272 return make(descriptionMap) 273 } 274 275 func (dm descriptionMap) put(lang languages.Lang, desc string) descriptionMap { 276 dm[lang] = desc 277 return dm 278 }