Juju and pprof

WIP: Notes on how to use pprof directly with juju.

There are many built in Agent Introspection tools already. Some use pprof underneath others do not. I recommend checking those out first.

Covered here will be how to use pprof live with juju and reading the results.

Simple case: you have a juju controller and want

In one window

$ juju ssh -m controller
$ juju_agent --listen localhost:9090

In a second window

$ juju ssh -m controller
$ go tool pprof /var/lib/juju/tools/machine-0/jujud localhost:6060
Fetching profile over HTTP from http://localhost:6060/debug/pprof/profile
Saved profile in /home/ubuntu/pprof/pprof.jujud.samples.cpu.001.pb.gz
File: jujud
Type: cpu
Time: May 12, 2022 at 8:05pm (UTC)
Duration: 30s, Total samples = 1.14s ( 3.80%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top

Note, you can also setup to run remotely by specifying the controllers IP address above, instead of localhost. This is handy when your source code lives somewhere else.