This is a creation in Article, where the information may have evolved or changed.
First, import the package
Import _ "Net/http/pprof"
Second, start monitoring routine
Go func () {
http. Listenandserve ("0.0.0.0:18080", nil)
}()
Third, access to Web services
Example: Analyzing CPU Usage
Go Tool pprof Http://localhost:18080/debug/pprof/profile
(pprof) top10total:2525 samples 298 11.8% 11.8% 345 13.7% runtime.mapacces S1_fast64 268 10.6% 22.4% 2124 84.1% Main. Findloops 251 9.9% 32.4% 451 17.9% scanblock 178 7.0% 39.4% 351 13.9% Hash_insert 131 5.2% 44.6% 158 6.3% Sweepspan 119 4.7% 49.3% the 13.9% main. DFS 53.1% 98 3.9% flushptrbuf 3.8% 3.8% 56.9% 95 3. 8% 60.6% 101 4.0% runtime.settype_flush the 3.5% 64.1% 988 39.1% runtime.mallocgc
IV, refer to
//pprof command
https://blog.golang.org/profiling-go-programs
//several monitoring metrics on the web
https://golang.org/pkg/net/http/pprof/