Golang Profiling - top10 shows only one row with 100%

I am trying to profile my go library to find out what is the reason that in C ++ is going much slower than the same.

I have a simple test

func BenchmarkFile(t *testing.B) { tmpFile, err := ioutil.TempFile("", TMP_FILE_PREFIX) fw, err := NewFile(tmpFile.Name()) text := []byte("testing") for i := 0; i < bN; i++ { _, err = fw.Write(text) } fw.Close() } 

NewFile returns my custom Writer, which encodes the data in our binary representation, even compresses it and writes it to the file system.

Running go test -bench . -memprofile mem.out -cpuprofile cpu.out go test -bench . -memprofile mem.out -cpuprofile cpu.out I get

 PASS BenchmarkFile-16 2000000000 0.20 ns/op ok .../writer/iowriter 9.074s 

How to analyze it

 # go tool pprof cpu.out Entering interactive mode (type "help" for commands) (pprof) top10 930ms of 930ms total ( 100%) flat flat% sum% cum cum% 930ms 100% 100% 930ms 100% (pprof) 

I even try to write an example.go application that my writer uses and add pprof.StartCPUProfile(f) as shown in http://blog.golang.org/profiling-go-programs , but with the same result.

What am I doing wrong, and how can I determine what is the bottleneck of my library? Thank you in advance

+5
source share
2 answers

Ok i miss to add binary to go to pprof tool, si it should be

 # go tool pprof write cpu.out Entering interactive mode (type "help" for commands) (pprof) top10 7.02s of 7.38s total (95.12%) Dropped 14 nodes (cum <= 0.04s) Showing top 10 nodes out of 32 (cum >= 0.19s) flat flat% sum% cum cum% 6.55s 88.75% 88.75% 6.76s 91.60% syscall.Syscall ... 

and when using benchmarks, a binary file is created there, and using it gives the same result.

+7
source

To expand sevolnd's answer:

pprof needs a binary file that actually generated the cpu.out file as the first argument.

So, you need to run the command as go tool pprof <go binary of your program> <generaged profiling output file>

eg. go tool pprof go_binary cpu.pprof

0
source

Source: https://habr.com/ru/post/1244669/


All Articles