Golang – profiling libraries and GoSNMP for SNMP

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
Tags:


Share This


 


2 Responses to Golang – profiling libraries and GoSNMP for SNMP

  1. Thx. for this tip , saved me heaps of time of trial&error

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>