Skip to content

pprof endpoint for Go applications that can be activated by a signal

License

Notifications You must be signed in to change notification settings

postfinance/profiler

Repository files navigation

Go Report Card GoDoc Build Coverage

profiler

Usage

Add the following line to your Go code:

// create and start the profiler handler
profiler.New().Start()

// ... or with custom values
profiler.New(
    profiler.WithSignal(syscall.SIGUSR1),
    profiler.WithAddress(":8080"),
    profiler.WithTimeout(15 * time.Minute),
)

Defaults

Parameter Default
Signal SIGUSR1
Listen :6666
Timeout 30m

Start the pprof endpoint

pkill -SIGUSR1 <your Go program>

After timeout the endpoint will shutdown.

Collect pprof data

go tool pprof -http $(hostname):8080 http://localhost:6666/debug/pprof/profile

... or ...

go tool pprof -http localhost:7007 http://localhost:8080/debug/pprof/profile

Kubernetes

Start the pprof endpoint

kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
...

kubectl exec -ti <your pod> sh
/ # pkill -SIGUSR1 <your Go program>
/ #

After timeout the endpoint will shutdown.

Check log

kubectl logs <your pod> -f | grep 'start debug endpoint'

Port-forward

kubectl port-forward <your pod> 8080:6666
Forwarding from 127.0.0.1:8080 -> 6666
Forwarding from [::1]:8080 -> 6666
Handling connection for 8080

Collect pprof data

go tool pprof -http $(hostname):8888 http://localhost:8080/debug/pprof/profile

... or ...

go tool pprof -http localhost:7007 http://localhost:8080/debug/pprof/profile

About

pprof endpoint for Go applications that can be activated by a signal

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages