cpuprofile and memprofile in golang testing

8.4k views Asked by At

I tried the command go test -cpuprofile cpu.out on a GO test file and it resulted in a file cpu.out which is full of many 64 bit numbers. It doesn't make any sense to me. What did the command do and what information can get I extract from cpu.out file?

Similarly go test -memprofile mem.out generated a mem.out file which also seems to make no sense to me. Help me out.

I have attached both the files.

cpu.out and mem.out

1

There are 1 answers

0
Martin Gallagher On BEST ANSWER

Use the output profiles in coordination with the go tool e.g.:

go tool pprof testbin.test cpu.out

I'd recommend some func Benchmark*(b *testing.B) implementations for functionality you're interesting in profiling.

Once in the tool try top10:

Welcome to pprof!  For help, type 'help'.
(pprof) top10

More information: https://blog.golang.org/profiling-go-programs