Go to file
Kailash Nadh 20c167c6c3
Merge pull request #1 from kalbhor/master
Minor readme update to include working usage example
2023-01-16 15:52:00 +05:30
LICENSE First commit. 2022-06-16 19:53:41 +05:30
README.md chore: minor usage update 2023-01-16 11:59:43 +05:30
go.mod Add go.mod. 2022-06-16 19:54:28 +05:30
profiler.go Fix incorrect started? flag. 2022-06-23 15:42:20 +05:30

README.md

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
}