pprofs

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 12 Imported by: 0

README

pprofs

Auto capture profiles.

Build Status codecov Go Report Card GitHub go.mod Go version GitHub tag (latest by date)

Quick start

package main

import "github.com/gochore/pprofs"

func main() {
	if err := pprofs.EnableCapture(); err != nil {
		panic(err)
	}
	// ...
}

It will auto capture profiles and store files in temp dir.

You can specify the dir and the ttl of files by environment variables:

export PPROF_DIR="~/somewhere"
export PPROF_TTL="1h"

Or use options:

func main() {
	if err := pprofs.EnableCapture(
		pprofs.WithStorage(pprofs.NewFileStorage("prefix", "~/somewhere", time.Hour)),
	); err != nil {
		panic(err)
	}
	// ...
}

See more examples.

Reference

Documentation

Index

Constants

View Source
const (
	EnvPprofPrefix = "PPROF_PREFIX"
	EnvPprofDir    = "PPROF_DIR"
	EnvPprofTtl    = "PPROF_TTL"
)

Variables

View Source
var (
	ErrAlreadyEnabled = errors.New("already enabled")
	ErrInvalidOption  = errors.New("invalid option")
)

Functions

func BlockProfile

func BlockProfile() blockProfile

BlockProfile captures the block profile.

func CpuProfile

func CpuProfile() cpuProfile

CpuProfile captures the CPU profile.

func EnableCapture

func EnableCapture(options ...Option) error

EnableCapture will capture the given profiles periodically.

func GoroutineProfile

func GoroutineProfile() goroutineProfile

GoroutineProfile captures the goroutine profile.

func HeapProfile

func HeapProfile() heapProfile

HeapProfile captures the heap profile.

func MutexProfile

func MutexProfile() mutexProfile

MutexProfile captures the mutex profile.

func ThreadcreateProfile

func ThreadcreateProfile() threadcreateProfile

ThreadcreateProfile captures the threadcreate profile.

Types

type FileStorage

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

FileStorage stores the profile results to file with automatic cleaning.

func NewFileStorage

func NewFileStorage(prefix, dir string, ttl time.Duration) *FileStorage

NewFileStorage return a FileStorage, prefix indicates the prefix of the files, dir indicates where to save the files, ttl indicates the time-to-live of the files.

func NewFileStorageFromEnv

func NewFileStorageFromEnv() *FileStorage

NewFileStorageFromEnv return a FileStorage, it read arguments from environment variables.

func (*FileStorage) WriteCloser

func (s *FileStorage) WriteCloser(name string, t time.Time) (io.WriteCloser, error)

WriteCloser implements Storage.

type IntervalTrigger

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

IntervalTrigger will trigger periodically with constant interval.

func NewIntervalTrigger

func NewIntervalTrigger(interval time.Duration) *IntervalTrigger

NewIntervalTrigger returns a IntervalTrigger.

func (*IntervalTrigger) Wait

func (t *IntervalTrigger) Wait() error

Wait implements Trigger.

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger is an abstraction of log output.

type Option

type Option func(c *capturer)

func WithLogger

func WithLogger(logger Logger) Option

WithLogger specifies the logger.

func WithProfiles

func WithProfiles(profiles ...profile) Option

WithProfiles specifies the pprof profiles.

func WithStorage

func WithStorage(storage Storage) Option

WithStorage specifies the storage.

func WithTrigger

func WithTrigger(trigger Trigger) Option

WithTrigger specifies the trigger.

type RandomIntervalTrigger

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

RandomIntervalTrigger will trigger periodically with random interval.

func NewRandomIntervalTrigger

func NewRandomIntervalTrigger(min, max time.Duration) *RandomIntervalTrigger

NewRandomIntervalTrigger returns a IntervalTrigger.

func (*RandomIntervalTrigger) Wait

func (t *RandomIntervalTrigger) Wait() error

Wait implements Trigger.

type Storage

type Storage interface {
	// WriteCloser should return an io.WriteCloser according to the profile name and current time.
	WriteCloser(name string, t time.Time) (io.WriteCloser, error)
}

Storage is an abstraction of storage output.

type Trigger

type Trigger interface {
	// Wait should block until need trigger capturing profile,
	// returning error means skipping.
	Wait() error
}

Trigger is an abstraction of a trigger.

Directories

Path Synopsis
_example

Jump to

Keyboard shortcuts

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