go-runtime之pprof子包
elf.go
1 |
// elfBuildID returns the GNU build ID of the named ELF binary, |
返回ELF二进制文件的GNU build ID
label.go
通过 context.Context 上操作kv值,达到设置 label的目的
map.go
1 |
// A profMap is a map from (stack, tag) to mapEntry. |
大概是标签查找
pprof.go
-
定义了Profile
1
2
3
4
5
6
7type Profile struct {
name string
mu sync.Mutex
m map[interface{}][]uintptr
count func() int
write func(io.Writer, int) error
} -
初始化了一些Profile
goroutine,threadcreate,heap,allocs,block,mutex
-
提供 NewProfile(name string) 方法支持自定义生成
-
func (p *Profile) Add(value interface{}, skip int)
将和value相关的执行栈加入到profile.Add在内部实现的map中存储value,所以value必须是可以被用作map的key,而且在没有收到移除(Remove)指令前不会被自动gc掉.
-
writexxx
proto.go
基本是构建pprof文件信息的方法
protobuf.go
编码,buffer
protomem.go
runtime.go
标记当前线程
internal子包
为了给外部调用,里面多封了一层profile包
- encode.go
对Profile的编解码
- filter.go
过滤
- legacy_profile.go
- profile.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// Profile is an in-memory representation of profile.proto.
type Profile struct {
SampleType []*ValueType
DefaultSampleType string
Sample []*Sample
Mapping []*Mapping
Location []*Location
Function []*Function
Comments []string
DropFrames string
KeepFrames string
TimeNanos int64
DurationNanos int64
PeriodType *ValueType
Period int64
commentX []int64
dropFramesX int64
keepFramesX int64
stringTable []string
defaultSampleTypeX int64
}
profile.proto文件的内存信息