cmemprof

package
v1.41.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cmemprof profiles C memory allocations (malloc, calloc, realloc, etc.)

Importing this package in a program will replace malloc, calloc, and realloc with wrappers which will sample allocations and record them to a profile.

To use this package:

f, _ := os.Create("cmem.pprof")
var profiler cmemprof.Profile
profiler.Start(500)
// ... do allocations
profile, err := profiler.Stop()

Building this package on Linux requires a non-standard linker flag to wrap the alloaction functions. For Go versions < 1.15, cgo won't allow the flag so it has to be explicitly allowed by setting the following environment variable when building a program that uses this package:

export CGO_LDFLAGS_ALLOW="-Wl,--wrap=.*"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Profile

type Profile struct {

	// SamplingRate is the value, in bytes, such that an average of one
	// sample will be recorded for every SamplingRate bytes allocated.  An
	// allocation of N bytes will be recorded with probability min(1, N /
	// SamplingRate).
	SamplingRate int
	// contains filtered or unexported fields
}

Profile provides access to a C memory allocation profiler based on instrumenting malloc, calloc, and realloc.

func (*Profile) Start

func (c *Profile) Start(rate int)

Start begins profiling C memory allocations.

func (*Profile) Stop

func (c *Profile) Stop() (*profile.Profile, error)

Stop cancels memory profiling and waits for the profile to be written to the io.Writer passed to Start. Returns any error from writing the profile.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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