easypprof

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: MIT Imports: 9 Imported by: 0

README

easypprof

build-img pkg-img reportcard-img coverage-img version-img

Easy pprof library for Go.

Note

Check go-profiler-notes for more information about profiling in Go.

Features

  • Simple API.
  • Easy to integrate.
  • Configurable.
  • Supports fgprof.
  • Improved version of pkg/profile.

Install

Go version 1.17+

go get github.com/go-perf/easypprof

Example

func main() {
	cfg := easypprof.Config{
		Mode:       easypprof.CpuMode,
		OutputDir:  path.Join(".", "test_pprof"),
		FilePrefix: "my-app",
	}
	defer easypprof.Start(cfg).Stop()

	// your code
}

See examples for more: examples_test.go.

Documentation

See these docs.

License

MIT License.

Documentation

Index

Constants

View Source
const (
	CpuMode          = "cpu"
	TraceMode        = "trace"
	HeapMode         = "heap"
	AllocsMode       = "allocs"
	MutexMode        = "mutex"
	BlockMode        = "block"
	ThreadCreateMode = "threadcreate"
	GoroutineMode    = "goroutine"
	FgprofMode       = "fgprof"
)

Profile modes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Disable the profiler. Easy to set as a command-line flag.
	// Default is false.
	Disable bool

	// Mode is one of cpu, goroutine, threadcreate, heap, allocs, block, mutex.
	// Default is empty string and is treated as cpu.
	Mode string

	// OutputDir where profile must be saved.
	// Default is empty string and is treated as ".".
	OutputDir string

	// FilePrefix for the output file.
	// If prefix is specified an additional '_' will be added to the prefix.
	FilePrefix string

	// UseTextFormat of the resulting pprof file.
	// Default is false.
	UseTextFormat bool

	// FgprofFormat is a format of the output file.
	// Default is fgprof.FormatPprof.
	FgprofFormat string

	// MutexProfileFraction represents the fraction of mutex contention events.
	// Default is 10.
	MutexProfileFraction int

	// BlockProfileRate represents the fraction of goroutine blocking events.
	// Default is 10_000.
	BlockProfileRate int
}

Config of the profiler.

type Profiler

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

Profiler for the Go programs.

func Start added in v0.2.0

func Start(cfg Config) *Profiler

Start profiling based on a config.

func (*Profiler) Stop added in v0.2.0

func (p *Profiler) Stop() error

Stop the profiler and save the result.

Jump to

Keyboard shortcuts

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