package module
v0.1.0 Latest Latest

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

Go to latest
Published: Nov 26, 2018 License: Apache-2.0 Imports: 10 Imported by: 9




Pprof made easy at development time.


Add autopprof.Capture to your main function.

import ""

    Duration: 15 * time.Second,

Run your program and send SIGQUIT to the process (or CTRL+\ on Mac).

Profile capturing will start. Pprof UI will be started once capture is completed.

See godoc for other profile types.

Why autopprof?

autopprof is a easy-to-setup pprof profile data collection library for development time. It highly depends on the standard library packages such as runtime/pprof and the existing tools such as go tool pprof.

Collecting and visualizing profiling data from Go programs is a multi-step process. First, you need to collect and write the collected data to a file. Then you should use the go tool pprof tool to analyze and visualize.

autopprof makes it easier to collect and start the pprof UI with a one-line configuration. It collects profiles once the process is triggered with a SIGQUIT and starts the pprof UI with the collected data. Since it does signal handling and starting the browser, it is only recommended at development-time.

For production cases, please see the runtime/pprof and net/http/pprof packages.



Package autopprof provides a development-time library to collect pprof profiles from Go programs.

This package is experimental and APIs may change.

package main

import (


func main() {
	// Add the following to your main, then
	// use CTRL+\ to intercept and capture.
	// Pprof UI will start in 15 seconds once
	// the profile is captured.
		Duration: 15 * time.Second,




This section is empty.


This section is empty.


func Capture

func Capture(p Profile)

Capture captures the given profiles at SIGINT and opens a browser with the collected profiles.

Capture should be used in development-time and shouldn't be in production binaries.


type BlockProfile

type BlockProfile struct {
	// Rate is the fraction of goroutine blocking events that
	// are reported in the blocking profile. The profiler aims to
	// sample an average of one blocking event per rate nanoseconds spent blocked.
	// If zero value is provided, it will include every blocking event
	// in the profile.
	Rate int

BlockProfile captures stack traces that led to blocking on synchronization primitives.

func (BlockProfile) Capture

func (p BlockProfile) Capture() (string, error)

type CPUProfile

type CPUProfile struct {
	Duration time.Duration // 30 seconds by default

CPUProfile captures the CPU profile.

func (CPUProfile) Capture

func (p CPUProfile) Capture() (string, error)

type GoroutineProfile

type GoroutineProfile struct{}

GoroutineProfile captures stack traces of all current goroutines.

func (GoroutineProfile) Capture

func (p GoroutineProfile) Capture() (string, error)

type HeapProfile

type HeapProfile struct{}

HeapProfile captures the heap profile.

func (HeapProfile) Capture

func (p HeapProfile) Capture() (string, error)

type MutexProfile

type MutexProfile struct{}

MutexProfile captures stack traces of holders of contended mutexes.

func (MutexProfile) Capture

func (p MutexProfile) Capture() (string, error)

type Profile

type Profile interface {
	Capture() (profile string, err error)

Profile represents a pprof profile.

type ThreadcreateProfile

type ThreadcreateProfile struct{}

Threadcreate profile captures the stack traces that led to the creation of new OS threads.

func (ThreadcreateProfile) Capture

func (p ThreadcreateProfile) Capture() (string, error)


Path Synopsis
Package main contains a simple hello world example for autopprof.
Package main contains a simple hello world example for autopprof.

Jump to

Keyboard shortcuts

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