prof

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 15 Imported by: 1

README

prof

Wrap the official net/http/pprof route and add the profile io wait time route.


Example of use

sampling profile by http
	mux := http.NewServeMux()
    prof.Register(mux, WithPrefix("/myServer"), WithIOWaitTime())

	httpServer := &http.Server{
		Addr:    ":8080",
		Handler: mux,
	}
	
    if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
        panic("listen and serve error: " + err.Error())
    }

sampling profile by system notification signal
func WaitSign() {
	p := NewProfile()

	signals := make(chan os.Signal, 1)
	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGTRAP)

	for {
		v := <-signals
		switch v {
		case syscall.SIGTRAP:
			p.StartOrStop()

		case syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP:
			os.Exit(0)
		}
	}
}
# view the program's pid
ps -aux | grep serverName

# notification of sampling profile, default 60s, in less than 60s, if the second execution will actively stop sampling profile
kill -trap pid

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableTrace

func EnableTrace()

EnableTrace enable sampling trace profile

func NewProfile

func NewProfile() *profile

NewProfile create a new profile

func Register

func Register(mux *http.ServeMux, opts ...Option)

Register pprof server mux

func SetDurationSecond

func SetDurationSecond(d uint32)

SetDurationSecond set sampling profile duration

Types

type Option

type Option func(o *options)

Option set defaultPrefix func

func WithIOWaitTime

func WithIOWaitTime() Option

WithIOWaitTime enable IO wait time

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix set route defaultPrefix

Jump to

Keyboard shortcuts

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