README

profile

Simple profiling support package for Go

Build Status GoDoc

installation

go get github.com/pkg/profile

usage

Enabling profiling in your application is as simple as one line at the top of your main function

import "github.com/pkg/profile"

func main() {
    defer profile.Start().Stop()
    ...
}

options

What to profile is controlled by config value passed to profile.Start. By default CPU profiling is enabled.

import "github.com/pkg/profile"

func main() {
    // p.Stop() must be called before the program exits to
    // ensure profiling information is written to disk.
    p := profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook)
    ...
    // You can enable different kinds of memory profiling, either Heap or Allocs where Heap
    // profiling is the default with profile.MemProfile.
    p := profile.Start(profile.MemProfileAllocs, profile.ProfilePath("."), profile.NoShutdownHook)
}

Several convenience package level values are provided for cpu, memory, and block (contention) profiling.

For more complex options, consult the documentation.

contributing

We welcome pull requests, bug fixes and issue reports.

Before proposing a change, please discuss it first by raising an issue.

Expand ▾ Collapse ▴

Documentation

Overview

    Package profile provides a simple way to manage runtime/pprof profiling of your Go application.

    Index

    Examples

    Constants

    View Source
    const DefaultMemProfileRate = 4096

      DefaultMemProfileRate is the default memory profiling rate. See also http://golang.org/pkg/runtime/#pkg-variables

      Variables

      This section is empty.

      Functions

      func BlockProfile

      func BlockProfile(p *Profile)

        BlockProfile enables block (contention) profiling. It disables any previous profiling settings.

        func CPUProfile

        func CPUProfile(p *Profile)

          CPUProfile enables cpu profiling. It disables any previous profiling settings.

          Example
          Output:
          
          

          func GoroutineProfile

          func GoroutineProfile(p *Profile)

            GoroutineProfile enables goroutine profiling. It disables any previous profiling settings.

            func MemProfile

            func MemProfile(p *Profile)

              MemProfile enables memory profiling. It disables any previous profiling settings.

              Example
              Output:
              
              

              func MemProfileAllocs

              func MemProfileAllocs() func(*Profile)

                MemProfileAllocs changes which type of memory to profile allocations.

                func MemProfileHeap

                func MemProfileHeap() func(*Profile)

                  MemProfileHeap changes which type of memory profiling to profile the heap.

                  func MemProfileRate

                  func MemProfileRate(rate int) func(*Profile)

                    MemProfileRate enables memory profiling at the preferred rate. It disables any previous profiling settings.

                    Example
                    Output:
                    
                    

                    func MutexProfile

                    func MutexProfile(p *Profile)

                      MutexProfile enables mutex profiling. It disables any previous profiling settings.

                      func NoShutdownHook

                      func NoShutdownHook(p *Profile)

                        NoShutdownHook controls whether the profiling package should hook SIGINT to write profiles cleanly. Programs with more sophisticated signal handling should set this to true and ensure the Stop() function returned from Start() is called during shutdown.

                        Example
                        Output:
                        
                        

                        func ProfilePath

                        func ProfilePath(path string) func(*Profile)

                          ProfilePath controls the base path where various profiling files are written. If blank, the base path will be generated by ioutil.TempDir.

                          Example
                          Output:
                          
                          

                          func Quiet

                          func Quiet(p *Profile)

                            Quiet suppresses informational messages during profiling.

                            func Start

                            func Start(options ...func(*Profile)) interface {
                            	Stop()
                            }

                              Start starts a new profiling session. The caller should call the Stop method on the value returned to cleanly stop profiling.

                              Example
                              Output:
                              
                              
                              Example (WithFlags)
                              Output:
                              
                              

                              func ThreadcreationProfile

                              func ThreadcreationProfile(p *Profile)

                                ThreadcreationProfile enables thread creation profiling.. It disables any previous profiling settings.

                                func TraceProfile

                                func TraceProfile(p *Profile)

                                  Trace profile enables execution tracing. It disables any previous profiling settings.

                                  Example
                                  Output:
                                  
                                  

                                  Types

                                  type Profile

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

                                    Profile represents an active profiling session.

                                    func (*Profile) Stop

                                    func (p *Profile) Stop()

                                      Stop stops the profile and flushes any unwritten data.

                                      Source Files