profile

package
v0.0.0-...-7c6133f Latest Latest
Warning

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

Go to latest
Published: May 30, 2016 License: BSD-2-Clause, MIT Imports: 7 Imported by: 0

README

profile

Simple profiling support package for Go

installation

go get github.com/davecheney/profile

usage

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

import "github.com/davecheney/profile"

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

options

What to profile is controlled by the *profile.Config value passed to profile.Start. A nil Config is the same as choosing all the defaults. By default no profiles are enabled.

import "github.com/davecheney/profile"

func main() {
    cfg := profile.Config{
        MemProfile:     true,
        ProfilePath:    ".",  // store profiles in current directory
        NoShutdownHook: true, // do not hook SIGINT
    }

    // p.Stop() must be called before the program exits to
    // ensure profiling information is written to disk.
    p := profile.Start(&cfg)
    ...
}

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

For more complex options, consult the documentation on the profile.Config type. Enabling more than one profile at once may cause your results to be less reliable as profiling itself is not without overhead.

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	CPUProfile = &Config{
		CPUProfile: true,
	}

	MemProfile = &Config{
		MemProfile: true,
	}

	BlockProfile = &Config{
		BlockProfile: true,
	}
)

Functions

func Start

func Start(cfg *Config) interface {
	Stop()
}

Start starts a new profiling session configured using *Config. The caller should call the Stop method on the value returned to cleanly stop profiling. Passing a nil *Config is the same as passing a *Config with defaults chosen.

Example
package main

import (
	"github.com/relab/goxos/Godeps/_workspace/src/github.com/davecheney/profile"
)

func main() {
	// start a simple CPU profile and register
	// a defer to Stop (flush) the profiling data.
	defer profile.Start(profile.CPUProfile).Stop()
}
Output:

Types

type Config

type Config struct {
	// Quiet suppresses informational messages during profiling.
	Quiet bool

	// CPUProfile controls if cpu profiling will be enabled.
	// It defaults to false.
	CPUProfile bool

	// MemProfile controls if memory profiling will be enabled.
	// It defaults to false.
	MemProfile bool

	// BlockProfile controls if block (contention) profiling will
	// be enabled.
	// It defaults to false.
	BlockProfile bool

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

	// 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.
	NoShutdownHook bool
}

Config controls the operation of the profile package.

Jump to

Keyboard shortcuts

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