Movatterモバイル変換


[0]ホーム

URL:


profile

packagestandard library
go1.25.5Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License:BSD-3-ClauseImports:10Imported by:0

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package profile represents a pprof profile as a directed graph.

This package is a simplified fork of github.com/google/pprof/internal/graph.

Package profile provides a representation ofgithub.com/google/pprof/proto/profile.proto andmethods to encode/decode/merge profiles in this format.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoData =fmt.Errorf("empty input file")

Functions

This section is empty.

Types

typeDemangler

type Demangler func(name []string) (map[string]string,error)

Demangler maps symbol names to a human-readable form. This mayinclude C++ demangling and additional simplification. Names thatare not demangled may be missing from the resulting map.

typeEdgeadded ingo1.23.0

type Edge struct {Src, Dest *Node// The summary weight of the edgeWeight, WeightDivint64// residual edges connect nodes that were connected through a// separate node, which has been removed from the report.Residualbool// An inline edge represents a call that was inlined into the caller.Inlinebool}

Edge contains any attributes to be represented about edges in a graph.

func (*Edge)WeightValueadded ingo1.23.0

func (e *Edge) WeightValue()int64

WeightValue returns the weight value for this edge, normalizing if adivisor is available.

typeEdgeMapadded ingo1.23.0

type EdgeMap []*Edge

EdgeMap is used to represent the incoming/outgoing edges from a node.

func (*EdgeMap)Addadded ingo1.23.0

func (em *EdgeMap) Add(e *Edge)

func (*EdgeMap)Deleteadded ingo1.23.0

func (em *EdgeMap) Delete(e *Edge)

func (EdgeMap)FindToadded ingo1.23.0

func (emEdgeMap) FindTo(n *Node) *Edge

func (EdgeMap)Sortadded ingo1.23.0

func (emEdgeMap) Sort() []*Edge

Sort returns a slice of the edges in the map, in a consistentorder. The sort order is first based on the edge weight(higher-to-lower) and then by the node names to avoid flakiness.

func (EdgeMap)Sumadded ingo1.23.0

func (emEdgeMap) Sum()int64

Sum returns the total weight for a set of nodes.

typeFunction

type Function struct {IDuint64NamestringSystemNamestringFilenamestringStartLineint64// contains filtered or unexported fields}

Function corresponds to Profile.Function

typeGraphadded ingo1.23.0

type Graph struct {NodesNodes}

Graph summarizes a performance profile into a format that issuitable for visualization.

funcNewGraphadded ingo1.23.0

func NewGraph(prof *Profile, o *Options) *Graph

NewGraph computes a graph from a profile.

func (*Graph)Stringadded ingo1.23.0

func (g *Graph) String()string

String returns a text representation of a graph, for debugging purposes.

typeLabel

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

Label corresponds to Profile.Label

typeLine

type Line struct {Function *FunctionLineint64// contains filtered or unexported fields}

Line corresponds to Profile.Line

typeLocation

type Location struct {IDuint64Mapping  *MappingAddressuint64Line     []LineIsFoldedbool// contains filtered or unexported fields}

Location corresponds to Profile.Location

typeMapping

type Mapping struct {IDuint64Startuint64Limituint64Offsetuint64FilestringBuildIDstringHasFunctionsboolHasFilenamesboolHasLineNumbersboolHasInlineFramesbool// contains filtered or unexported fields}

Mapping corresponds to Profile.Mapping

typeNodeadded ingo1.23.0

type Node struct {// Info describes the source location associated to this node.InfoNodeInfo// Function represents the function that this node belongs to. On// graphs with sub-function resolution (eg line number or// addresses), two nodes in a NodeMap that are part of the same// function have the same value of Node.Function. If the Node// represents the whole function, it points back to itself.Function *Node// Values associated to this node. Flat is exclusive to this node,// Cum includes all descendents.Flat, FlatDiv, Cum, CumDivint64// In and out Contains the nodes immediately reaching or reached by// this node.In, OutEdgeMap}

Node is an entry on a profiling report. It represents a uniqueprogram location.

func (*Node)AddToEdgeadded ingo1.23.0

func (n *Node) AddToEdge(to *Node, vint64, residual, inlinebool)

AddToEdge increases the weight of an edge between two nodes. Ifthere isn't such an edge one is created.

func (*Node)AddToEdgeDivadded ingo1.23.0

func (n *Node) AddToEdgeDiv(to *Node, dv, vint64, residual, inlinebool)

AddToEdgeDiv increases the weight of an edge between two nodes. Ifthere isn't such an edge one is created.

func (*Node)CumValueadded ingo1.23.0

func (n *Node) CumValue()int64

CumValue returns the inclusive value for this node, computing themean if a divisor is available.

func (*Node)FlatValueadded ingo1.23.0

func (n *Node) FlatValue()int64

FlatValue returns the exclusive value for this node, computing themean if a divisor is available.

typeNodeInfoadded ingo1.23.0

type NodeInfo struct {NamestringAddressuint64StartLine, Linenoint}

NodeInfo contains the attributes for a node.

func (*NodeInfo)NameComponentsadded ingo1.23.0

func (i *NodeInfo) NameComponents() []string

NameComponents returns the components of the printable name to be used for a node.

func (*NodeInfo)PrintableNameadded ingo1.23.0

func (i *NodeInfo) PrintableName()string

PrintableName calls the Node's Formatter function with a single space separator.

typeNodeMapadded ingo1.23.0

type NodeMap map[NodeInfo]*Node

NodeMap maps from a node info struct to a node. It is used to mergereport entries with the same info.

func (NodeMap)FindOrInsertNodeadded ingo1.23.0

func (nmNodeMap) FindOrInsertNode(infoNodeInfo, keptNodeSet) *Node

FindOrInsertNode takes the info for a node and either returns a matching nodefrom the node map if one exists, or adds one to the map if one does not.If kept is non-nil, nodes are only added if they can be located on it.

typeNodePtrSetadded ingo1.23.0

type NodePtrSet map[*Node]bool

NodePtrSet is a collection of nodes. Trimming a graph or tree requires a setof objects which uniquely identify the nodes to keep. In a graph, NodeInfoworks as a unique identifier; however, in a tree multiple nodes may shareidentical NodeInfos. A *Node does uniquely identify a node so we can use thatinstead. Though a *Node also uniquely identifies a node in a graph,currently, during trimming, graphs are rebuilt from scratch using only theNodeSet, so there would not be the required context of the initial graph toallow for the use of *Node.

typeNodeSetadded ingo1.23.0

type NodeSet map[NodeInfo]bool

NodeSet is a collection of node info structs.

typeNodesadded ingo1.23.0

type Nodes []*Node

Nodes is an ordered collection of graph nodes.

funcCreateNodesadded ingo1.23.0

func CreateNodes(prof *Profile, o *Options) (Nodes, locationMap)

CreateNodes creates graph nodes for all locations in a profile. Itreturns set of all nodes, plus a mapping of each location to theset of corresponding nodes (one per location.Line).

func (Nodes)Sumadded ingo1.23.0

func (nsNodes) Sum() (flatint64, cumint64)

Sum adds the flat and cum values of a set of nodes.

typeOptionsadded ingo1.23.0

type Options struct {SampleValue       func(s []int64)int64// Function to compute the value of a sampleSampleMeanDivisor func(s []int64)int64// Function to compute the divisor for mean graphs, or nilDropNegativebool// Drop nodes with overall negative valuesKeptNodesNodeSet// If non-nil, only use nodes in this set}

Options encodes the options for constructing a graph

typeProfile

type Profile struct {SampleType        []*ValueTypeDefaultSampleTypestringSample            []*SampleMapping           []*MappingLocation          []*LocationFunction          []*FunctionComments          []stringDropFramesstringKeepFramesstringTimeNanosint64DurationNanosint64PeriodType    *ValueTypePeriodint64// contains filtered or unexported fields}

Profile is an in-memory representation of profile.proto.

funcMerge

func Merge(srcs []*Profile) (*Profile,error)

Merge merges all the profiles in profs into a single Profile.Returns a new profile independent of the input profiles. The mergedprofile is compacted to eliminate unused samples, locations,functions and mappings. Profiles must have identical profile sampleand period types or the merge will fail. profile.Period of theresulting profile will be the maximum of all profiles, andprofile.TimeNanos will be the earliest nonzero one.

funcParse

func Parse(rio.Reader) (*Profile,error)

Parse parses a profile and checks for its validity. The input must be anencoded pprof protobuf, which may optionally be gzip-compressed.

func (*Profile)Aggregate

func (p *Profile) Aggregate(inlineFrame, function, filename, linenumber, addressbool)error

Aggregate merges the locations in the profile into equivalenceclasses preserving the request attributes. It also updates thesamples to point to the merged locations.

func (*Profile)CheckValid

func (p *Profile) CheckValid()error

CheckValid tests whether the profile is valid. Checks include, but arenot limited to:

  • len(Profile.Sample[n].value) == len(Profile.value_unit)
  • Sample.id has a corresponding Profile.Location

func (*Profile)Compatible

func (p *Profile) Compatible(pb *Profile)error

Compatible determines if two profiles can be compared/merged.returns nil if the profiles are compatible; otherwise an error withdetails on the incompatibility.

func (*Profile)Copy

func (p *Profile) Copy() *Profile

Copy makes a fully independent copy of a profile.

func (*Profile)Demangle

func (p *Profile) Demangle(dDemangler)error

Demangle attempts to demangle and optionally simplify any functionnames referenced in the profile. It works on a best-effort basis:it will silently preserve the original names in case of any errors.

func (*Profile)Empty

func (p *Profile) Empty()bool

Empty reports whether the profile contains no samples.

func (*Profile)FilterSamplesByTag

func (p *Profile) FilterSamplesByTag(focus, ignoreTagMatch) (fm, imbool)

FilterSamplesByTag removes all samples from the profile, exceptthose that match focus and do not match the ignore regularexpression.

func (*Profile)HasFileLines

func (p *Profile) HasFileLines()bool

HasFileLines determines if all locations in this profile havesymbolized file and line number information.

func (*Profile)HasFunctions

func (p *Profile) HasFunctions()bool

HasFunctions determines if all locations in this profile havesymbolized function information.

func (*Profile)Merge

func (p *Profile) Merge(pb *Profile, rfloat64)error

Merge adds profile p adjusted by ratio r into profile p. Profilesmust be compatible (same Type and SampleType).TODO(rsilvera): consider normalizing the profiles based on thetotal samples collected.

func (*Profile)Normalize

func (p *Profile) Normalize(pb *Profile)error

Normalize normalizes the source profile by multiplying each value in profile by theratio of the sum of the base profile's values of that sample type to the sum of thesource profile's value of that sample type.

func (*Profile)Prune

func (p *Profile) Prune(dropRx, keepRx *regexp.Regexp)

Prune removes all nodes beneath a node matching dropRx, and notmatching keepRx. If the root node of a Sample matches, the samplewill have an empty stack.

func (*Profile)RemoveUninteresting

func (p *Profile) RemoveUninteresting()error

RemoveUninteresting prunes and elides profiles using built-intables of uninteresting function names.

func (*Profile)Scale

func (p *Profile) Scale(ratiofloat64)

Scale multiplies all sample values in a profile by a constant.

func (*Profile)ScaleN

func (p *Profile) ScaleN(ratios []float64)error

ScaleN multiplies each sample values in a sample by a different amount.

func (*Profile)String

func (p *Profile) String()string

Print dumps a text representation of a profile. Intended mainlyfor debugging purposes.

func (*Profile)Write

func (p *Profile) Write(wio.Writer)error

Write writes the profile as a gzip-compressed marshaled protobuf.

typeSample

type Sample struct {Location []*LocationValue    []int64Label    map[string][]stringNumLabel map[string][]int64NumUnit  map[string][]string// contains filtered or unexported fields}

Sample corresponds to Profile.Sample

typeTagMatch

type TagMatch func(key, valstring, nvalint64)bool

TagMatch selects tags for filtering

typeValueType

type ValueType struct {Typestring// cpu, wall, inuse_space, etcUnitstring// seconds, nanoseconds, bytes, etc// contains filtered or unexported fields}

ValueType corresponds to Profile.ValueType

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp