Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cpuprofile and memprofile in golang testing

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

like image 735
Jsmith Avatar asked Dec 30 '16 10:12

Jsmith


1 Answers

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

like image 107
Martin Gallagher Avatar answered Oct 12 '22 11:10

Martin Gallagher