Trying to use the /pprof/block endpoint

1,770 views
Skip to first unread message

Traun Leyden

unread,
Feb 23, 2015, 5:57:51 PM2/23/15
to golan...@googlegroups.com

I've added a handler in my webserver that passes on the request to the net/http/pprof package as follows:

    httpprof.Handler("block").ServeHTTP(res,req)

but if I call that endpoint via:

    go tool pprof bin/my_binary http://localhost/_debug/pprof/block

I get this error:

    Fetching profile from http://localhost:4985/_debug/pprof/block
    parsing profile: unrecognized profile format

If I try using curl instead of the go tool pprof command, I see this returned:

    --- contention:
    cycles/second=2395538828

Am I doing something wrong or is this known not to work on Go 1.4?  In the Go blog post about profiling go programs it says "The goroutine blocking profile will be explained in a future post. Stay tuned." but it looks like that post is still in the works.
 

Yves Junqueira

unread,
Feb 23, 2015, 7:32:47 PM2/23/15
to Traun Leyden, golang-nuts

The profile output is empty because the blocking profile is disabled by default. You have to set a profiling rate using the runtime package.

http://golang.org/pkg/runtime/#SetBlockProfileRate

Typically you would set it to something like 1%, then leave it on for enough time to collect interesting samples for your application, then disable it again. After that the blocking profile fetched via HTTP will have data.

The exact rate and period of collection you should use is application dependent - it's a balance between instrumentation precision and execution overhead. Experimentation is the best way to find what works best for you (ie: collect more blocking samples as fast as possible but without hurting your system performance too much).

The more interest part is how to interpret the data, and tell when a blocking time is benign (e.g: waiting for IO) or not (e.g: excessive locking).

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Traun Leyden

unread,
Feb 23, 2015, 7:40:59 PM2/23/15
to golan...@googlegroups.com, traun....@gmail.com

Thank you!  I think that was the missing link.  I will give that a shot.

ps

unread,
Feb 23, 2015, 9:30:18 PM2/23/15
to golan...@googlegroups.com, traun....@gmail.com
You may not need it now, but it appears the 'profile' package handles that for you (with a default rate setting):

https://github.com/davecheney/profile
Reply all
Reply to author
Forward
0 new messages