Golang – profiling libraries and GoSNMP for SNMP
|03-Jun-2013||Posted by Sonia Hamilton under Golang|
There is already a great article on Profiling Go Programs. However that article only discusses how to profile a standalone binary – what about a library?
For example, I’ve been working on the GoSNMP SNMP library, here’s how I profiled it (it wasn’t obvious):
# produce cpu profiling information from the tests - this part was well documented % go test -cpuprofile cpu.out # compile the test binary to pkg.test but do not run it (from `go help test`) # this part wasn't obvious % go test -c # now run pprof using `go teste -c` output # using gosnmp.test - this part wasn't obvious % go tool pprof gosnmp.test cpu.out
Doing a memory profile was similar:
% go test -memprofile mem.out % go test -c % go tool pprof gosnmp.test mem.out