Imports #
"fmt"
"io"
"math"
"path/filepath"
"strings"
"github.com/google/pprof/internal/measurement"
"fmt"
"math"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"github.com/google/pprof/profile"
"fmt"
"io"
"math"
"path/filepath"
"strings"
"github.com/google/pprof/internal/measurement"
"fmt"
"math"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"github.com/google/pprof/profile"
Sorting options for node sort.
const AddressOrderSorting options for node sort.
const CumNameOrderSorting options for node sort.
const EntropyOrderSorting options for node sort.
const FileOrderSorting options for node sort.
const FlatCumNameOrderSorting options for node sort.
const FlatNameOrder NodeOrder = iotaSorting options for node sort.
const NameOrdervar cppAnonymousPrefixRegExp = *ast.CallExprStrips C++ namespace prefix from a C++ function / method name. NOTE: Make sure to keep the template parameters in the name. Normally, template parameters are stripped from the C++ names but when -symbolize=demangle=templates flag is used, they will not be. See tests for examples.
var cppRegExp = *ast.CallExprRemoves package name and method arguments for Go function names. See tests for examples.
var goRegExp = *ast.CallExprRemoves potential module versions in a package path.
var goVerRegExp = *ast.CallExprRemoves package name and method arguments for Java method names. See tests for examples.
var javaRegExp = *ast.CallExprconst maxNodelets = 4EdgeMap is used to represent the incoming/outgoing edges from a node.
type EdgeMap map[*Node]*EdgeNodeMap maps from a node info struct to a node. It is used to merge report entries with the same info.
type NodeMap map[NodeInfo]*NodeNodeOrder sets the ordering for a Sort operation
type NodeOrder intNodePtrSet is a collection of nodes. Trimming a graph or tree requires a set of objects which uniquely identify the nodes to keep. In a graph, NodeInfo works as a unique identifier; however, in a tree multiple nodes may share identical NodeInfos. A *Node does uniquely identify a node so we can use that instead. Though a *Node also uniquely identifies a node in a graph, currently, during trimming, graphs are rebuilt from scratch using only the NodeSet, so there would not be the required context of the initial graph to allow for the use of *Node.
type NodePtrSet map[*Node]boolNodeSet is a collection of node info structs.
type NodeSet map[NodeInfo]boolNodes is an ordered collection of graph nodes.
type Nodes []*NodeTagMap is a collection of tags, classified by their name.
type TagMap map[string]*Tagtype edgeList []*EdgeDotAttributes contains details about the graph itself, giving insight into how its elements should be rendered.
type DotAttributes struct {
Nodes map[*Node]*DotNodeAttributes
}DotConfig contains attributes about how a graph should be constructed and how it should look.
type DotConfig struct {
Title string
LegendURL string
Labels []string
FormatValue func(int64) string
Total int64
}DotNodeAttributes contains Node specific visualization options.
type DotNodeAttributes struct {
Shape string
Bold bool
Peripheries int
URL string
Formatter func(*NodeInfo) string
}Edge contains any attributes to be represented about edges in a graph.
type Edge struct {
Src *Node
Dest *Node
Weight int64
WeightDiv int64
Residual bool
Inline bool
}Graph summarizes a performance profile into a format that is suitable for visualization.
type Graph struct {
Nodes Nodes
}Node is an entry on a profiling report. It represents a unique program location.
type Node struct {
Info NodeInfo
Function *Node
Flat int64
FlatDiv int64
Cum int64
CumDiv int64
In EdgeMap
Out EdgeMap
LabelTags TagMap
NumericTags map[string]TagMap
}NodeInfo contains the attributes for a node.
type NodeInfo struct {
Name string
OrigName string
Address uint64
File string
StartLine int
Lineno int
Columnno int
Objfile string
}Options encodes the options for constructing a graph
type Options struct {
SampleValue func(s []int64) int64
SampleMeanDivisor func(s []int64) int64
FormatTag func(int64, string) string
ObjNames bool
OrigFnNames bool
CallTree bool
DropNegative bool
KeptNodes NodeSet
}Tag represent sample annotations
type Tag struct {
Name string
Unit string
Value int64
Flat int64
FlatDiv int64
Cum int64
CumDiv int64
}builder wraps an io.Writer and understands how to compose DOT formatted elements.
type builder struct {
io.Writer
attributes *DotAttributes
config *DotConfig
}type nodePair struct {
src *Node
dest *Node
}nodeSorter is a mechanism used to allow a report to be sorted in different ways.
type nodeSorter struct {
rs Nodes
less func(l *Node, r *Node) bool
}type tags struct {
t []*Tag
flat bool
}AddToEdge increases the weight of an edge between two nodes. If there isn't such an edge one is created.
func (n *Node) AddToEdge(to *Node, v int64, residual bool, inline bool)AddToEdgeDiv increases the weight of an edge between two nodes. If there isn't such an edge one is created.
func (n *Node) AddToEdgeDiv(to *Node, dv int64, v int64, residual bool, inline bool)ComposeDot creates and writes a in the DOT format to the writer, using the configurations given.
func ComposeDot(w io.Writer, g *Graph, a *DotAttributes, c *DotConfig)CreateNodes creates graph nodes for all locations in a profile. It returns set of all nodes, plus a mapping of each location to the set of corresponding nodes (one per location.Line).
func CreateNodes(prof *profile.Profile, o *Options) (Nodes, map[uint64]Nodes)CumValue returns the inclusive value for this tag, computing the mean if a divisor is available.
func (t *Tag) CumValue() int64CumValue returns the inclusive value for this node, computing the mean if a divisor is available.
func (n *Node) CumValue() int64DiscardLowFrequencyNodePtrs returns a NodePtrSet of nodes at or over a specific cum value cutoff.
func (g *Graph) DiscardLowFrequencyNodePtrs(nodeCutoff int64) NodePtrSetDiscardLowFrequencyNodes returns a set of the nodes at or over a specific cum value cutoff.
func (g *Graph) DiscardLowFrequencyNodes(nodeCutoff int64) NodeSetFindOrInsertNode takes the info for a node and either returns a matching node from 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.
func (nm NodeMap) FindOrInsertNode(info NodeInfo, kept NodeSet) *NodeFlatValue returns the exclusive value for this tag, computing the mean if a divisor is available.
func (t *Tag) FlatValue() int64FlatValue returns the exclusive value for this node, computing the mean if a divisor is available.
func (n *Node) FlatValue() int64func (el edgeList) Len() intfunc (s nodeSorter) Len() intfunc (t tags) Len() intfunc (el edgeList) Less(i int, j int) boolfunc (t tags) Less(i int, j int) boolfunc (s nodeSorter) Less(i int, j int) boolNameComponents returns the components of the printable name to be used for a node.
func (i *NodeInfo) NameComponents() []stringNew summarizes performance data from a profile into a graph.
func New(prof *profile.Profile, o *Options) *GraphPrintableName calls the Node's Formatter function with a single space separator.
func (i *NodeInfo) PrintableName() stringRemoveRedundantEdges removes residual edges if the destination can be reached through another path. This is done to simplify the graph while preserving connectivity.
func (g *Graph) RemoveRedundantEdges()SelectTopNodePtrs returns a set of the top maxNodes *Node in a graph.
func (g *Graph) SelectTopNodePtrs(maxNodes int, visualMode bool) NodePtrSetSelectTopNodes returns a set of the top maxNodes nodes in a graph.
func (g *Graph) SelectTopNodes(maxNodes int, visualMode bool) NodeSetShortenFunctionName returns a shortened version of a function's name.
func ShortenFunctionName(f string) stringSort returns a slice of the edges in the map, in a consistent order. The sort order is first based on the edge weight (higher-to-lower) and then by the node names to avoid flakiness.
func (e EdgeMap) Sort() []*EdgeSort reorders a slice of nodes based on the specified ordering criteria. The result is sorted in decreasing order for (absolute) numeric quantities, alphabetically for text, and increasing for addresses.
func (ns Nodes) Sort(o NodeOrder) errorSortNodes sorts the nodes in a graph based on a specific heuristic.
func (g *Graph) SortNodes(cum bool, visualMode bool)SortTags sorts a slice of tags based on their weight.
func SortTags(t []*Tag, flat bool) []*TagString returns a text representation of a graph, for debugging purposes.
func (g *Graph) String() stringSum adds the flat and cum values of a set of nodes.
func (ns Nodes) Sum() (flat int64, cum int64)Sum returns the total weight for a set of nodes.
func (e EdgeMap) Sum() int64func (el edgeList) Swap(i int, j int)func (t tags) Swap(i int, j int)func (s nodeSorter) Swap(i int, j int)TrimLowFrequencyEdges removes edges that have less than the specified weight. Returns the number of edges removed
func (g *Graph) TrimLowFrequencyEdges(edgeCutoff int64) intTrimLowFrequencyTags removes tags that have less than the specified weight.
func (g *Graph) TrimLowFrequencyTags(tagCutoff int64)TrimTree trims a Graph in forest form, keeping only the nodes in kept. This will not work correctly if even a single node has multiple parents.
func (g *Graph) TrimTree(kept NodePtrSet)WeightValue returns the weight value for this edge, normalizing if a divisor is available.
func (e *Edge) WeightValue() int64func abs64(i int64) int64addEdge generates a graph edge in DOT format.
func (b *builder) addEdge(edge *Edge, from int, to int, hasNodelets bool)addLegend generates a legend in DOT format.
func (b *builder) addLegend()addNode generates a graph node in DOT format.
func (b *builder) addNode(node *Node, nodeID int, maxFlat float64)addNodelets generates the DOT boxes for the node tags if they exist.
func (b *builder) addNodelets(node *Node, nodeID int) boolfunc (n *Node) addSample(dw int64, w int64, labels string, numLabel map[string][]int64, numUnit map[string][]string, format func(int64, string) string, flat bool)collapsedTags trims and sorts a slice of tags.
func (b *builder) collapsedTags(ts []*Tag, count int, flatTags bool) []*TagcompareNodes compares two nodes to provide a deterministic ordering between them. Two nodes cannot have the same Node.Info value.
func compareNodes(l *Node, r *Node) boolcountTags counts the tags with flat count. This underestimates the number of tags being displayed, but in practice is close enough.
func countTags(n *Node) intfunc defaultLabelFormat(v int64, key string) stringdotColor returns a color for the given score (between -1.0 and 1.0), with -1.0 colored green, 0.0 colored grey, and 1.0 colored red. If isBackground is true, then a light (low-saturation) color is returned (suitable for use as a background color); otherwise, a darker color is returned (suitable for use as a foreground color).
func dotColor(score float64, isBackground bool) stringedgeEntropyScore computes the entropy value for a set of edges coming in or out of a node. Entropy (as defined in information theory) refers to the amount of information encoded by the set of edges. A set of edges that have a more interesting distribution of samples gets a higher score.
func edgeEntropyScore(n *Node, edges EdgeMap, self int64) float64entropyScore computes a score for a node representing how important it is to include this node on a graph visualization. It is used to sort the nodes and select which ones to display if we have more nodes than desired in the graph. This number is computed by looking at the flat and cum weights of the node and the incoming/outgoing edges. The fundamental idea is to penalize nodes that have a simple fallthrough from their incoming to the outgoing edge.
func entropyScore(n *Node) int64escapeAllForDot applies escapeForDot to all strings in the given slice.
func escapeAllForDot(in []string) []stringescapeForDot escapes double quotes and backslashes, and replaces Graphviz's "center" character (\n) with a left-justified character. See https://graphviz.org/docs/attr-types/escString/ for more info.
func escapeForDot(str string) stringfunc (m TagMap) findOrAddTag(label string, unit string, value int64) *Tagfunc (nm NodeMap) findOrInsertLine(l *profile.Location, li profile.Line, o *Options) *Nodefinish closes the opening curly bracket in the constructed DOT buffer.
func (b *builder) finish()getNodesAboveCumCutoff returns all the nodes which have a Cum value greater than or equal to cutoff.
func getNodesAboveCumCutoff(nodes Nodes, nodeCutoff int64) NodesisNegative returns true if the node is considered as "negative" for the purposes of drop_negative.
func isNegative(n *Node) boolisRedundantEdge determines if there is a path that allows e.Src to reach e.Dest after removing e.
func isRedundantEdge(e *Edge) boolfunc joinLabels(s *profile.Sample) stringfunc makeNodeSet(nodes Nodes, nodeCutoff int64) NodeSetfunc min64(a int64, b int64) int64func multilinePrintableName(info *NodeInfo) stringnewGraph computes a graph from a profile. It returns the graph, and a map from the profile location indices to the corresponding graph nodes.
func newGraph(prof *profile.Profile, o *Options) (*Graph, map[uint64]Nodes)func newTree(prof *profile.Profile, o *Options) (g *Graph)func nodeInfo(l *profile.Location, line profile.Line, objfile string, o *Options) *NodeInfofunc (nm NodeMap) nodes() Nodesfunc (b *builder) numericNodelets(nts []*Tag, maxNumNodelets int, flatTags bool, source string) stringfunc selectNodesForGraph(nodes Nodes, dropNegative bool) *GraphselectTopNodes returns a slice of the top maxNodes nodes in a graph.
func (g *Graph) selectTopNodes(maxNodes int, visualMode bool) Nodesstart generates a title and initial node in DOT format.
func (b *builder) start()func tagDistance(t *Tag, u *Tag) float64func (b *builder) tagGroupLabel(g []*Tag) (label string, flat int64, cum int64)func trimLowFreqTags(tags TagMap, minValue int64) TagMapGenerated with Arrow