Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to run go pprof on Docker daemon

#Use pprof debug docker daemon

pprof debug entrypoint

source file: docker\api\server\profiler.go

const debugPathPrefix = "/debug/"

func profilerSetup(mainRouter *mux.Router) {
	var r = mainRouter.PathPrefix(debugPathPrefix).Subrouter()
	r.HandleFunc("/vars", expVars)
	r.HandleFunc("/pprof/", pprof.Index)
	r.HandleFunc("/pprof/cmdline", pprof.Cmdline)
	r.HandleFunc("/pprof/profile", pprof.Profile)
	r.HandleFunc("/pprof/symbol", pprof.Symbol)
	r.HandleFunc("/pprof/trace", pprof.Trace)
	r.HandleFunc("/pprof/block", pprof.Handler("block").ServeHTTP)
	r.HandleFunc("/pprof/heap", pprof.Handler("heap").ServeHTTP)
	r.HandleFunc("/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
	r.HandleFunc("/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)

Start docker daemon in debug mode

add -D to command line

$ /usr/bin/docker daemon -D -H tcp:// -H unix:///var/run/docker.sock

Run socat to make docker sock available via tcp port

note the IP to listen at

$ socat -d -d TCP-LISTEN:8080,fork,bind= UNIX:/var/run/docker.sock
  2016/01/23 12:59:43 socat[3113] N listening on AF=2

Access debug url entrypoint

show global vars

$ curl -s | jq .
    "cmdline": [
    "memstats": {
      "Alloc": 7140904,
      "TotalAlloc": 20379824,
      "Sys": 14559480,
      "Lookups": 3090,
      "Mallocs": 313164,
      "Frees": 199260,
      "HeapAlloc": 7140904,

get command line

$ curl -s
  /usr/bin/docker daemon -D -H tcp:// -H unix:///var/run/docker.sock -api-enable-cors --storage-driver=aufs --insecure-registry --insecure-registry

run pprof on your client:

$ go tool pprof
  Fetching profile from
  Please wait... (30s)
  Saved profile in /home/xjimmy/pprof/pprof.
  Entering interactive mode (type "help" for commands)
  (pprof) web     
  (pprof) web ploop

generate graph

$ cd /home/xjimmy/pprof
$ gunzip pprof.
$ go tool pprof --pdf pprof.dockerd. > callgraph.pdf

get symbol

$ curl -s
  num_symbols: 1


$ culr -s
$ curl -s
$ curl -s
$ curl -s
Copy link

Bablzz commented Sep 30, 2019

Thanks for a good article

Typo in other section

Copy link

curl can hit unix sockets directly now (since 7.40), e.g. curl --unix-socket /var/run/docker.sock http://_/debug/vars (since 7.50 you have to give curl a hostname, but it doesn't matter what it is, so I put _ in)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment