debug

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 16 Imported by: 6

Documentation

Overview

Package debug contains debug helpers for M3 components.

Index

Constants

View Source
const (
	// DebugURL is the url for the debug dump endpoint.
	DebugURL = "/debug/dump"
	// DebugMethod is the HTTP method.
	DebugMethod = http.MethodGet
)
View Source
const (
	// ContinuousCPUProfileName is the name of continuous CPU profile.
	ContinuousCPUProfileName = "cpu"
)

Variables

This section is empty.

Functions

func RegisterPProfHandlers added in v1.3.0

func RegisterPProfHandlers(mux *http.ServeMux)

RegisterPProfHandlers registers pprof endpoints on the ServeMux provided. Use this instead of just importing net/http/pprof if you'd like to register endpoints on a ServeMux other than http.DefaultServeMux.

Types

type ContinuousFileProfile added in v0.15.5

type ContinuousFileProfile struct {
	// contains filtered or unexported fields
}

ContinuousFileProfile is a profile that runs continously to a file using a template for a file name.

func NewContinuousFileProfile added in v0.15.5

func NewContinuousFileProfile(
	opts ContinuousFileProfileOptions,
) (*ContinuousFileProfile, error)

NewContinuousFileProfile returns a new continuous file profile.

func (*ContinuousFileProfile) Start added in v0.15.5

func (c *ContinuousFileProfile) Start() error

Start will start the continuous file profile.

func (*ContinuousFileProfile) Stop added in v0.15.5

func (c *ContinuousFileProfile) Stop() error

Stop will stop the continuous file profile.

type ContinuousFileProfileOptions added in v0.15.5

type ContinuousFileProfileOptions struct {
	FilePathTemplate  string
	ProfileName       string
	ProfileDuration   time.Duration
	ProfileDebug      int
	Conditional       func() bool
	Interval          time.Duration
	InstrumentOptions instrument.Options
}

ContinuousFileProfileOptions is a set of continuous file profile options.

type ContinuousFileProfilePathParams added in v0.15.5

type ContinuousFileProfilePathParams struct {
	ProfileName string
	UnixTime    int64
}

ContinuousFileProfilePathParams is the params used to construct a file path.

type ProfileSource

type ProfileSource struct {
	// contains filtered or unexported fields
}

ProfileSource defines a custom source of a runtime/pprof Profile. This can either be part of a predefined or custom profile.

func NewProfileSource

func NewProfileSource(name string, debug int) (*ProfileSource, error)

NewProfileSource returns a ProfileSource with a name and debug level, where the verbosity of the final stack information increases with value. Will return an error if name is an empty string.

func (*ProfileSource) Profile

func (p *ProfileSource) Profile() *pprof.Profile

Profile returns a *pprof.Profile according the the name of the ProfileSource. This will first try find an existing profile, creating one if it can't be found.

func (*ProfileSource) Write

func (p *ProfileSource) Write(w io.Writer, _ *http.Request) error

Write writes a pprof-formatted snapshot of the profile to w. If a write to w returns an error, Write returns that error. Otherwise, Write returns nil.

type Source

type Source interface {
	// Write writes it's debug information into the provided writer.
	Write(w io.Writer, r *http.Request) error
}

Source is the interface that must be implemented to provide a new debug source. Each debug source's Write method will be called to write out a debug file for that source into the overall debug zip file.

func NewCPUProfileSource

func NewCPUProfileSource(h time.Duration) Source

NewCPUProfileSource returns a Source for CPU Profiling, measured over the passed duration.

func NewHeapDumpSource

func NewHeapDumpSource() Source

NewHeapDumpSource returns a Source for heapdump.

func NewHostInfoSource

func NewHostInfoSource() Source

NewHostInfoSource returns a Source for host information

type ZipWriter

type ZipWriter interface {
	// WriteZip writes a ZIP file in the provided writer.
	// The archive contains the dumps of all sources in separate files.
	WriteZip(io.Writer, *http.Request) error
	// RegisterSource adds a new source to the produced archive.
	RegisterSource(fileName string, source Source) error
	// HTTPHandler sends out the ZIP file as raw bytes.
	HTTPHandler() http.Handler
	// RegisterHandler wires the HTTPHandlerFunc with the given router.
	RegisterHandler(handlerPath string, router *http.ServeMux) error
}

ZipWriter aggregates sources and writes them in a zip file.

func NewZipWriter

func NewZipWriter(iopts instrument.Options) ZipWriter

NewZipWriter returns an instance of an ZipWriter. The passed prefix indicates the folder where to save the zip files.

func NewZipWriterWithDefaultSources

func NewZipWriterWithDefaultSources(
	cpuProfileDuration time.Duration,
	iopts instrument.Options,
) (ZipWriter, error)

NewZipWriterWithDefaultSources returns a zipWriter with the following debug sources already registered: CPU, heap, host, goroutines.

Directories

Path Synopsis
Package extdebug contains helpers for more detailed debug information
Package extdebug contains helpers for more detailed debug information
Package debugtest contains test helper methods
Package debugtest contains test helper methods

Jump to

Keyboard shortcuts

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