Share the joy















One of the things I missed when starting to use golang was departing from profiling tools like visualvm and yourkit for the JVM. Golang has a few options and one of them I’ll be documenting here is profiling your running application and outputting a callgrind file that you can use to understand your running golang app.

or via SVG!

To enable this kind of profiling, follow the instructions for adding pprof to your application: http://golang.org/pkg/net/http/pprof/

Once your app is back up and running with pprof and you’re putting some stress on it then it’s time to check out a profile.

Installing kcachegrind on ubuntu:

sudo apt-get install kcachegrind

launch it:

kcachegrind

start debugging an application

jim@localhost: ~ ➺ go tool pprof http://127.0.0.1:8001/debug/pprof/profile Read http://127.0.0.1:8001/debug/pprof/symbol Gathering CPU profile from http://127.0.0.1:8001/debug/pprof/profile?seconds=30 for 30 seconds to /var/folders/mg/x8pzmrlj6msgkkvvcbpybd580000gn/T/TjhdgALH3Z Be patient... Wrote profile to /var/folders/mg/x8pzmrlj6msgkkvvcbpybd580000gn/T/TjhdgALH3Z Welcome to pprof! For help, type 'help'. (pprof) callgrind my-cool-grindfile

now just click OPEN on kcachegrind and you should be able to visualize your running application from it’s snapshot.

If you want to view the SVG version then just type in “web” from the pprof interactive shell instead of “callgrind my-cool-grindfile”

Notes:

If you get the error:

Failed to POST to http://127.0.0.1:8001/debug/pprof/symbol

edit the following file:

jim@ubuntu:~$ vim /usr/local/go/pkg/tool/linux_amd64/pprof

and change:

if ($@) {

to:

if (1) {