pprof_reader

package
v0.0.0-...-4a623d3 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 6 Imported by: 0

README

PProf Reader

Library to read profiles written in go's pprof format.

PProf is sampled data encoded into protobufs, which is then gzipped. internal/profile is copied directly from golang's src/runtime/pprof/internal/profile directory.

This library reads a pprof profile and converts it to an edge based graph similar to Blackfire.

Usage:

fr, err := os.Open(filename)
if err != nil {
	return nil, err
}
defer fr.Close()

profile, err := pprof_reader.ReadFromPProf(fr)
if err != nil {
	return nil, err
}

err = pprof_reader.WriteBFFormat(profile, os.Stdout)
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpProfiles

func DumpProfiles(cpuBuffers, memBuffers []*bytes.Buffer, dstDir string) (err error)

DumpProfiles dumps the raw golang pprof files to the specified directory. It uses the naming scheme exename-type-index.pprof, starting at the next index after the last one found in the specified directory.

Types

type Function

type Function struct {
	Name string

	// Memory usage is aggregated into one overall cost per function (stored as
	// MemoryCost here), so we must keep track of the number of times a function
	// is referenced in a profile, and then "distribute" the cost based on the
	// number of times it is referenced across the sample call stacks of a
	// profile. This value is calculated and cached in DistributedMemoryCost
	MemoryCost            uint64
	DistributedMemoryCost uint64
	ReferenceCount        int
}

func (*Function) AddReferences

func (f *Function) AddReferences(count int)

func (*Function) String

func (f *Function) String() string

type Profile

type Profile struct {
	CpuSampleRateHz int
	USecPerSample   uint64
	Samples         []*Sample
	// Note: Matching by ID didn't work since there seems to be some duplication
	// in the pprof data. We match by name instead since it's guaranteed unique.
	Functions map[string]*Function
}

Profle contains a set of entry points, which collectively contain all sampled data

func NewProfile

func NewProfile() *Profile

func ReadFromPProf

func ReadFromPProf(cpuBuffers, memBuffers []*bytes.Buffer) (*Profile, error)

Read a pprof format profile and convert to our internal format.

func (*Profile) CloneWithSamples

func (p *Profile) CloneWithSamples(samples []*Sample) *Profile

func (*Profile) HasData

func (p *Profile) HasData() bool

type Sample

type Sample struct {
	Count    int
	CPUTime  uint64
	MemUsage uint64
	Stack    []*Function
}

func (*Sample) CloneWithStack

func (s *Sample) CloneWithStack(stack []*Function) *Sample

Directories

Path Synopsis
internal
profile
Package profile provides a representation of profile.proto and methods to encode/decode profiles in this format.
Package profile provides a representation of profile.proto and methods to encode/decode profiles in this format.

Jump to

Keyboard shortcuts

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