go-memory-profiling

command module
v0.0.0-...-44912ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2020 License: MIT Imports: 1 Imported by: 0

README

go-memory-profiling

add profiling into the main() function of your command
package main

import (
   //...
   "github.com/pkg/profile"
)

func main() {
   // Memory profiling
   defer profile.Start(profile.MemProfile).Stop()

   //...
}
build and run your program

This will generate a *.pprof file in a temp folder, and tell you where it’s located (will be needed later)

2017/08/03 14:26:28 profile: cpu profiling enabled, /var/...../cpu.pprof
install graphviz if you don’t have it installed yet

This is used to generate the graph on a pdf. On a Mac, it’s a simple brew install graphviz. Refer to https://www.graphviz.org for other platforms.

run go tool pprof

Pass your binary location, and the location of the cpu.pprof file as returned when running your program.

You can generate the analysis in various formats. The PDF one is pretty amazing:

go tool pprof --pdf ~/go/bin/yourbinary /var/path/to/cpu.pprof > file.pdf

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL