How to get correct CPU profile on Mac?

Just wonder is CPU profile ever working on Mac?

I always get following same thing by go tool pprof --web xxx.pprof:

Same with memprofile.

Any help would be grateful!

It works fine for me on Mac. You seem to be missing out the binary under test on your command line.

Thanks! What do you mean binary under test?

The program you want to profile … It’s one of the arguments to go tool pprof (and yes, it should give you a warning if not present).

OH! thank you, I got it now, working!

BTW, I get tons of invalid spdelta __tsan_go_start 0xa90d20 0xa90d60 0x0 -1, is it normal?

This might be a corrupt or confused Go installation. How did you install Go ? Did you set GOROOT by accident ? What does which go show ? Does that match the version of Go you expect to be installed ?

What is the complete command line you are using to generate this profile ?

It’s also worth noting that profiling is broken on OSX versions prior to El Capitan, source

How did you install Go

I used compiled tarball from All releases - The Go Programming Language

Did you set GOROOT by accident ?

What was set long time ago, should I remove it?

What does which go show

It shows /usr/local/src/go/bin/go and my GOROOT is /usr/local/src/go.

Does that match the version of Go you expect to be installed

Yes.

What is the complete command line you are using to generate this profile ?

curl http://localhost:3000/debug/pprof/profile > my.profile
go tool pprof path/to/my/binary my.profile
(pprof) web

It’s also worth noting that profiling is broken on OSX versions prior to El Capitan, source

I noticed this article but not sure what you mean exactly, and I’m using El Capitan

Absolutely

It shows /usr/local/src/go/bin/go and my GOROOT is /usr/local/src/go.

This is incorrect, you should unset GOROOT and place the downloaded tarball in /usr/local/go as documented.

go tool pprof path/to/my/binary my.profile

Please try

 go tool pprof path/to/binary http://localhost:3000/debug/pprof/profile

Thanks! I’ve done the things you’ve asked.

But still gets tons of invalid spdelta __tsan_go_start 0xa90d20 0xa90d60 0x0 -1.

Is it possible because I’m using os/exec calling other commands?

You may need to remove $GOPATH/pkg and rebuild your application from scratch.

But still gets tons of invalid spdelta __tsan_go_start 0xa90d20 0xa90d60 0x0 -1.

Where are these coming from, can you include more context ?

Thanks again! Still getting same error message, but the graph looks more sense to me now :grin:

I’ve searched the issue tracker and cannot find any references to this issue for the current release of Go. Although I have some suspicions that the installation of Go on your machine is not correct, I encourage you to raise an issue for this problem. You will need to include a way for people to reproduce the problem before they can investigate.

tsan probably comes from the race checker (ThreadSanitizer). Don’t profile code compiled with -race!

2 Likes

Boom! Well spotted Tamas!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.