This is a creation in Article, where the information may have evolved or changed.
Method One:
Use: Set godebug=gctrace=1/ godebug=gctrace=2
Run the executable directly: Server.exe
Format: GC # @ #s #%: #+...+# ms Clock, #+...+# MS CPU, #->#-># MB, # MB goal, # P
GC # indicates the first few GC
@ #s indicates how long the program started executing the GC
#% indicates the percentage of time that the program started GC elapsed (percentage of spent in GC since programs start)
The #+...+# represents the CPU blocking time during GC execution and
#->#-># MB indicates that the GC starts the heap size, ends the heap size, and the active heap size
# MB goal indicates target pair size
# P Indicates the number of CPU cores during program run
Example:
GC @1277.835s 0%: 0+1.0+0+1.0+1.0 ms Clock, 0+1.0+0+0/1.0/0+3.0 MS CPU, 0->0->0 MB, 4 MB goal, 4 P
Method Two:
Import _ "Net/http/pprof" Go func () {log. Println (http. Listenandserve ("localhost:6060", Nil)} () Add the above code to the program.-----------------------------------------------------------use the following command to view the performance: Go Tool pprof/HTTP Localhost:6060/debug/pprof/heap viewing CPU usage in 30 seconds: Go tool pprof http://localhost:6060/debug/pprof/ Profile View Goroutime performance: Go tool pprof Http://localhost:6060/debug/pprof/block view 5-second execution trace.wget http://localhost:6060/ Debug/pprof/trace?seconds=5 Open in Browser view: http://localhost:6060/debug/pprof/https://blog.golang.org/2011/06/ profiling-go-programs.html command: Go tool pprof/mnt/go/src/main http://localhost:6060/debug/pprof/ The heap input list can be seen in detail. Input web can be viewed on a Web page in addition we can also run Go tool pprof your-executable-name--dot profile-filename > HEAP.GV, this will get a HEAP.GV file, and we'll open this file in Graphviz to get a more detailed memory consumption graph that includes the call relationship. Of course, if we only need a picture, we can run Dot-tpng HEAP.GV > Heap.png Save this GV file as a PNG, so I can show the results below as I do.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.