小结:
1、内存消耗分析 list peek 定位到函数
https://mp.weixin.qq.com/s/_LovnIqJYAuDpTm2QmUgrA
go tool pprof http://127.0.0.1:123/debug/pprof/heap
使用list命令直接可以查看到具体是哪一行分配了多少内存
list Output annotated source for functions matching regexp
pdf Outputs a graph in PDF format
peek Output callers/callees of functions matching regexp
(pprof) list new Total: 1.02MB ROUTINE ======================== google.golang.org/grpc/internal/transport.newFramer in /home/shawn/go/pkg/mod/google.golang.org/grpc@v1.29.1/internal/transport/http_util.go 0 528.17kB (flat, cum) 50.74% of Total . . 658: if writeBufferSize < 0 { . . 659: writeBufferSize = 0 . . 660: } . . 661: var r io.Reader = conn . . 662: if readBufferSize > 0 { . 528.17kB 663: r = bufio.NewReaderSize(r, readBufferSize) . . 664: } . . 665: w := newBufWriter(conn, writeBufferSize) . . 666: f := &framer{ . . 667: writer: w, . . 668: fr: http2.NewFramer(w, r), ROUTINE ======================== google.golang.org/grpc/internal/transport.newHTTP2Client in /home/shawn/go/pkg/mod/google.golang.org/grpc@v1.29.1/internal/transport/http2_client.go 0 528.17kB (flat, cum) 50.74% of Total . . 244: localAddr: conn.LocalAddr(), . . 245: authInfo: authInfo, . . 246: readerDone: make(chan struct{}), . . 247: writerDone: make(chan struct{}), . . 248: goAway: make(chan struct{}), . 528.17kB 249: framer: newFramer(conn, writeBufSize, readBufSize, maxHeaderListSize), . . 250: fc: &trInFlow{limit: uint32(icwz)}, . . 251: scheme: scheme, . . 252: activeStreams: make(map[uint32]*Stream), . . 253: isSecure: isSecure, . . 254: perRPCCreds: perRPCCreds, (pprof) (pprof) peek new Showing nodes accounting for 1040.92kB, 100% of 1040.92kB total ----------------------------------------------------------+------------- flat flat% sum% cum cum% calls calls% + context ----------------------------------------------------------+------------- 528.17kB 100% | google.golang.org/grpc/internal/transport.newHTTP2Client 0 0% 0% 528.17kB 50.74% | google.golang.org/grpc/internal/transport.newFramer 528.17kB 100% | bufio.NewReaderSize (inline) ----------------------------------------------------------+------------- 528.17kB 100% | google.golang.org/grpc/internal/transport.NewClientTransport 0 0% 0% 528.17kB 50.74% | google.golang.org/grpc/internal/transport.newHTTP2Client 528.17kB 100% | google.golang.org/grpc/internal/transport.newFramer ----------------------------------------------------------+------------- (pprof)
list Output annotated source for functions matching regexp
pdf Outputs a graph in PDF format
peek Output callers/callees of functions matching regexp