pprofutil

package
v0.0.0-...-9d39026 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Unlicense Imports: 3 Imported by: 0

Documentation

Overview

Package pprofutil contains utilities for pprof HTTP handlers.

Example
package main

import (
	"context"
	"fmt"
	"net/http"
	"time"

	"github.com/Potterli20/golibs-fork/pprofutil"
)

func main() {
	mux := http.NewServeMux()
	pprofutil.RoutePprof(mux)

	srv := &http.Server{
		Addr:    "127.0.0.1:0",
		Handler: mux,
	}

	errCh := make(chan error, 1)
	go func() {
		errCh <- srv.ListenAndServe()
	}()

	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
	defer cancel()

	err := srv.Shutdown(ctx)
	fmt.Printf("shutdown error: %v\n", err)
	fmt.Printf("server error: %v\n", <-errCh)

}
Output:

shutdown error: <nil>
server error: http: Server closed

Index

Examples

Constants

View Source
const BasePath = "/debug/pprof/"

BasePath is the default base path used by RoutePprof.

TODO(a.garipov): Consider adding the ability to configure the base path.

Variables

This section is empty.

Functions

func RoutePprof

func RoutePprof(r Router)

RoutePprof adds all pprof handlers to r under the paths within BasePath.

Types

type Router

type Router interface {
	Handle(pattern string, h http.Handler)
}

Router is the interface for HTTP routers, such as *http.ServeMux.

type RouterFunc

type RouterFunc func(pattern string, h http.Handler)

RouterFunc is a functional implementation of the Router interface.

func (RouterFunc) Handle

func (f RouterFunc) Handle(pattern string, h http.Handler)

Handle implements the Router interface for RouterFunc.

Jump to

Keyboard shortcuts

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