Profiling

command
v0.0.0-...-95f5d90 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 6 Imported by: 0

README

Go Profiling

Step #1 .- Get Package

go get github.com/pkg/profile

Step #2 Use Package in your code

package main

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

func main() {
	// CPU profiling by default
	defer profile.Start().Stop()

    //...
}

Step #3 Build and Run your program

go build

go run yourmain.go

After run program, obtain path "cpu.pprof" file

Step #4 Install Graphviz if you don't have it installed yet

https://www.graphviz.org/download/

Update %PATH% and re-open terminal or VSCode or whatever

Step #5 Go Tool Prof and generate pdf file

go tool pprof --pdf /path/yourbinary /path/to/your/cpu.pprof > file.pdf

Step #6 Happy Profiling :D

alt text

Resources

https://blog.golang.org/profiling-go-programs

https://github.com/pkg/profile

https://www.graphviz.org/

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