xprof

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: BSD-3-Clause Imports: 8 Imported by: 4

Documentation

Overview

Package xprof.

Extends the original source code https://pkg.go.dev/github.com/pkg/profile

Index

Examples

Constants

View Source
const DefaultMemProfileRate = 4096

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

View Source
const Usage = "enable profiling mode, one of [cpu, mem, mutex, block]"

Usage text for flag package.

Variables

This section is empty.

Functions

func Block

func Block(p *Prof)

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

func CPU

func CPU(p *Prof)

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

Example
// CPU profiling is the default profiling mode, but you can specify it
// explicitly for completeness.
defer Start("", CPU).Stop()

func Go

func Go(p *Prof)

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

func Mem

func Mem(p *Prof)

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

Example
// use memory profiling, rather than the default cpu profiling.
defer Start("", Mem).Stop()

func MemAllocs

func MemAllocs(p *Prof)

MemAllocs changes which type of memory to profile allocations.

Example
// use allocs memory profiling.
defer Start("", MemAllocs).Stop()

func MemHeap

func MemHeap(p *Prof)

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

Example
// use heap memory profiling.
defer Start("", MemHeap).Stop()

func MemRate

func MemRate(rate int) func(*Prof)

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

Example
// use memory profiling with custom rate.
defer Start("", MemRate(2048)).Stop()

func Mutex

func Mutex(p *Prof)

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

func NoShutdownHook

func NoShutdownHook(p *Prof)

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
// disable the automatic shutdown hook.
defer Start("", NoShutdownHook).Stop()

func Quiet

func Quiet(p *Prof)

Quiet suppresses informational messages during profiling.

func Start

func Start(path string, options ...func(*Prof)) interface {
	Stop()
}

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

Example
// start a simple CPU profile and register
// a defer to Stop (flush) the profiling data.
defer Start("").Stop()
Example (WithFlags)
// use the flags package to selectively enable profiling.
mode := flag.String("mode", "", "enable profiling mode, one of [cpu, mem, mutex, block]")
flag.Parse()
switch *mode {
case "cpu":
	defer Start("", CPU).Stop()
case "mem":
	defer Start("", Mem).Stop()
case "mutex":
	defer Start("", Mutex).Stop()
case "block":
	defer Start("", Block).Stop()
default:
	// do nothing
}

func Thread

func Thread(p *Prof)

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

func Trace

func Trace(p *Prof)

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

Example
// use execution tracing, rather than the default cpu profiling.
defer Start("", Trace).Stop()

Types

type Prof added in v0.7.1

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

func (*Prof) Stop added in v0.7.1

func (p *Prof) Stop()

Jump to

Keyboard shortcuts

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