README

autopprof

GoDoc

Pprof made easy at development time.

Guide

Add autopprof.Capture to your main function.

import "github.com/rakyll/autopprof"

autopprof.Capture(autopprof.CPUProfile{
    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.

Expand ▾ Collapse ▴

Documentation

Overview

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

    This package is experimental and APIs may change.

    Example
    Output:
    
    

    Index

    Examples

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    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.

      Types

      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)

                    Source Files

                    Directories

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