software-engineering

Definition

Pprof (Go)

Pprof is a tool for visualisation and analysis of profiling data.

pprof reads a collection of profiling samples in profile.proto format and generates reports to visualize and help analyze the data. It can generate both text and graphical reports (through the use of the dot visualization package).

1


HTTP Server

In Go, an HTTP server can be started programmatically to explore pprof profiles, s.a. CPU and memory.

1. Import: By import the net/http/pprof package, an http handler is added.

import _ "net/http/pprof"

2. Listen HTTP: Start an HTTP server with Go’s http package.

import "http"
 
func main() {
	err := http.ListenAndServe(":8080", nil)
	// handle error
}

3. Fetch profile: After an HTTP server is started, profiles can be fetched using go tool pprof. For example, an SVG can be generated from the heap profile.

go tool pprof -svg https://localhost:8080/debug/pprof/heap > out.svg

2

Footnotes

  1. GitHub - google/pprof: pprof is a tool for visualization and analysis of profiling data

  2. Profiling Go programs with pprof