forked from profefe/profefe
/
profile_type.go
70 lines (64 loc) · 1.1 KB
/
profile_type.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
package profile
import (
"fmt"
"strings"
)
type ProfileType uint8
const (
TypeUnknown ProfileType = iota
TypeCPU
TypeHeap
TypeBlock
TypeMutex
TypeGoroutine
TypeThreadcreate
TypeOther ProfileType = 127
TypeTrace ProfileType = 128
)
func (ptype *ProfileType) FromString(s string) error {
s = strings.TrimSpace(s)
switch s {
case "cpu":
*ptype = TypeCPU
case "heap":
*ptype = TypeHeap
case "block":
*ptype = TypeBlock
case "mutex":
*ptype = TypeMutex
case "goroutine":
*ptype = TypeGoroutine
case "threadcreate":
*ptype = TypeThreadcreate
case "other":
*ptype = TypeOther
case "trace":
*ptype = TypeTrace
default:
*ptype = TypeUnknown
}
return nil
}
func (ptype ProfileType) String() string {
switch ptype {
case TypeUnknown:
return "unknown"
case TypeCPU:
return "cpu"
case TypeHeap:
return "heap"
case TypeBlock:
return "block"
case TypeMutex:
return "mutex"
case TypeGoroutine:
return "goroutine"
case TypeThreadcreate:
return "threadcreate"
case TypeOther:
return "other"
case TypeTrace:
return "trace"
}
return fmt.Sprintf("ProfileType(%d)", ptype)
}