pprof

package module
v0.0.0-...-f00801f Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 3 Imported by: 0

README

pprof

github.com/ahrtr/pprof is a package to help a http server to enable runtime profiling data easily. It leverages golang build-in package "net/http/pprof".

How to use this repo

It's super easy. You only need to call pprof.RegisterPprof(h) to wrap your original http.handler. For example, assuming your http.Server definition is something like below,

s := &http.Server{
	Addr:    ":8080",
	Handler: yourHandler,
}

then you can make the following change to enable the runtime profiling data,

import (
	"github.com/ahrtr/pprof"
)

s := &http.Server{
	Addr:    ":8080",
	Handler: pprof.RegisterPprof(yourHandler),
}

Once your http server is running, then you can query the runtime profiling data. The following is a couple of examples.

heap profile:

go tool pprof http://localhost:8080/debug/pprof/heap

30-second CPU profile:

go tool pprof http://localhost:8080/debug/pprof/profile?seconds=30

goroutine profile:

curl http://localhost:8080/debug/pprof/goroutine?debug=1

Please refer to examples/httpsrv.go to get a complete example.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterPprof

func RegisterPprof(handler http.Handler) *http.ServeMux

RegisterPprof registers pprof handlers and return a new http.ServeMux, which wraps the original http.Handler.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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