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 Status Coverage Status

Table of Contents generated with DocToc

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:

  • Signal HUP
  • Listen :6666
  • Timeout 10m

Start the pprof endpoint

pkill -HUP <your Go program>

After timeout the endpoint will shutdown.

Collect pprof data

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

Usage with kubernetes services

Start the pprof endpoint

$ k get pods
NAME                    READY   STATUS    RESTARTS   AGE
...

$ k exec -ti <your pod> sh
/ # pkill -HUP <your Go program>
/ #

After timeout the endpoint will shutdown.

Check log

$ k logs <your pod> -f
...
2020/02/10 16:37:09 start pprof endpoint on ":6666"
...

Port-forward

$  k 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

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