For questions about how to use pprof for profiling, refer to https://studygolang.com/articles/7069, which is only a few additions to this article.
1. Explanation of the Http://xxx:6060/debug/pprof/heap?debug=1 page
Heap profile:219:286339776 [29791:2945785336] @ heap/1048576
Where 219--the number of surviving heap objects seen in the current snapshot
286339776--the number of bytes of surviving heap objects seen in the current snapshot
29791--the number of allocated heap objects (including those that have been freed) seen in the current snapshot
29791--bytes of allocated heap objects (including already freed) seen in the current snapshot
1048576--memprofilerate * 2
For each specific object, the data format is
8:62062592 [12:93093888] @ 0x8fd38f 0x8fe4fa 0x8fa5f0 0x90714e 0x909b36 0x46bc31
where 8--objects that are still alive on the current callstack Number
62062592--The number of bytes that are currently alive on CallStack
12--total allocated (including freed) objects on current callstack
93093888--total over current callstack The number of bytes occupied by (including the freed) object
@ The contents of the current callstack stack frame, and callstack consistent with the following parsing
These are all output in the Pprof.go file, see Code
Fmt. fprintf (W, "Heap Profile:%d:%d [%d:%d] @ heap/%d\n", total. Inuseobjects (), total. Inusebytes (), total. Allocobjects, total. Allocbytes,2*runtime. Memprofilerate) for I: = Range p {r: = &p[i]fmt. fprintf (W, "%d:%d [%d:%d] @", r.inuseobjects (), R.inusebytes (), r.allocobjects, r.allocbytes) for _, PC: = Range R.stack () {FMT. fprintf (W, "% #x", PC)}fmt. fprintf (w, "\ n") Printstackrecord (W, R.stack (), false)}//Print memstats information too.//Pprof would ignore, but useful f or Peoples: = new (runtime. Memstats) runtime. Readmemstats (s) fmt. fprintf (W, "\n# runtime. Memstats\n ") fmt. fprintf (W, "# Alloc =%d\n", S.alloc) fmt. fprintf (W, "# Totalalloc =%d\n", S.totalalloc) fmt. fprintf (W, "# Sys =%d\n", S.sys) fmt. fprintf (W, "# lookups =%d\n", s.lookups) fmt. fprintf (W, "# Mallocs =%d\n", S.mallocs) fmt. fprintf (W, "# frees =%d\n", s.frees) fmt. fprintf (W, "# HeapAlloc =%d\n", S.heapalloc) fmt. fprintf (W, "# Heapsys =%d\n", S.heapsys) fmt. fprintf (W, "# Heapidle =%d\n", S.heapidle) fmt. fprintf (W, "# Heapinuse =%d\n ", S.heapinuse) fmt. fprintf (W, "# heapreleased =%d\n", s.heapreleased) fmt. fprintf (W, "# heapobjects =%d\n", s.heapobjects) fmt. fprintf (W, "# Stack =%d/%d\n", S.stackinuse, S.stacksys) fmt. fprintf (W, "# Mspan =%d/%d\n", S.mspaninuse, S.mspansys) fmt. fprintf (W, "# Mcache =%d/%d\n", S.mcacheinuse, S.mcachesys) fmt. fprintf (W, "# Buckhashsys =%d\n", S.buckhashsys) fmt. fprintf (W, "# Gcsys =%d\n", S.gcsys) fmt. fprintf (W, "# Othersys =%d\n", S.othersys) fmt. fprintf (W, "# NEXTGC =%d\n", S.NEXTGC) fmt. fprintf (W, "# LASTGC =%d\n", S.LASTGC) fmt. fprintf (W, "# Pausens =%d\n", S.pausens) fmt. fprintf (W, "# pauseend =%d\n", s.pauseend) fmt. fprintf (W, "# NUMGC =%d\n", S.NUMGC) fmt. fprintf (W, "# NUMFORCEDGC =%d\n", S.NUMFORCEDGC) fmt. fprintf (W, "# gccpufraction =%v\n", s.gccpufraction) fmt. fprintf (W, "# DEBUGGC =%v\n", S.DEBUGGC)
If you feel that the number of active objects printed in the heap profile is too different from the number of heapobjects, you can set memprofilerate to a smaller value (by default, 512*1024), set to 1, and the full heap object assignment can be seen in the snapshot.
Some questions about the Go language memoryprofile