profiler

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 11 Imported by: 0

README

profiler

profiler is a tiny wrapper around runtime/pprof for easily profiling Go programs. It allows running one or more profiles (cpu, mem etc.) simultaneously while avoiding boilerplate. The results are dumped to files. This is a rewrite of pkg/profile with the key difference of supporting multiple concurrent profiles.

Install

go get github.com/knadh/profiler

Usage

import "github.com/knadh/profiler"

func main() {
	// Pass one or more modes: Block, Cpu, Goroutine, Mem, Mutex, ThreadCreate, Trace ...
	p := profiler.New(profiler.Conf{}, profiler.Cpu, profiler.Mem ...)
	p.Start()

	// Stuff ...

	p.Stop()
}
Optional config
profiler.Conf{
	// Directory path to dump the profile output to. Default is current directory.
	DirPath string

	// Quiet disables info log output.
	Quiet bool

	// NoShutdownHook controls whether the profiling package should
	// hook SIGINT to automatically Stop().
	NoShutdownHook bool

	// MemProfileRate is the rate for the memory profiler. Default is 4096.
	// To include every allocated block in the profile, set MemProfileRate to 1.
	MemProfileRate int

	// MemProfileType = heap or alloc. Default is heap.
	MemProfileType string
}

Documentation

Overview

Package profiler is a simple abstraction for easily running runtime profiles and storing the results to files.

Index

Constants

View Source
const (
	// Profiler modes.
	Block = iota
	Cpu
	Goroutine
	Mem
	Mutex
	ThreadCreate
	Trace
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf struct {
	// Directory path to dump the profile output to. Default is current directory.
	DirPath string

	// Quiet disables info log output.
	Quiet bool

	// NoShutdownHook controls whether the profiling package should
	// hook SIGINT to automatically Stop().
	NoShutdownHook bool

	// MemProfileRate is the rate for the memory profiler. Default is 4096.
	// To include every allocated block in the profile, set MemProfileRate to 1.
	MemProfileRate int

	// MemProfileType = heap or alloc. Default is heap.
	MemProfileType string
}

Conf contains the profiler config.

type Profiler

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

Profiler represents an active profiling session.

func New

func New(c Conf, modes ...int) *Profiler

New returns a new Profiler. One or more modes can be provided. eg: `prof := New(profiler.Cpu, profiler.Mem ...)` Configuration can be directly applied once `prof` is initiailized. eg: `prof.Path = "./otuput"`

func (*Profiler) Start

func (prof *Profiler) Start()

func (*Profiler) Stop

func (pr *Profiler) Stop()

Stop runs all the profile stop functions.

Jump to

Keyboard shortcuts

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