graph

Imports

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"

Constants & Variables

AddressOrder const #

Sorting options for node sort.

const AddressOrder

CumNameOrder const #

Sorting options for node sort.

const CumNameOrder

EntropyOrder const #

Sorting options for node sort.

const EntropyOrder

FileOrder const #

Sorting options for node sort.

const FileOrder

FlatCumNameOrder const #

Sorting options for node sort.

const FlatCumNameOrder

FlatNameOrder const #

Sorting options for node sort.

const FlatNameOrder NodeOrder = iota

NameOrder const #

Sorting options for node sort.

const NameOrder

cppAnonymousPrefixRegExp var #

var cppAnonymousPrefixRegExp = *ast.CallExpr

cppRegExp var #

Strips 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.CallExpr

goRegExp var #

Removes package name and method arguments for Go function names. See tests for examples.

var goRegExp = *ast.CallExpr

goVerRegExp var #

Removes potential module versions in a package path.

var goVerRegExp = *ast.CallExpr

javaRegExp var #

Removes package name and method arguments for Java method names. See tests for examples.

var javaRegExp = *ast.CallExpr

maxNodelets const #

const maxNodelets = 4

Type Aliases

EdgeMap type #

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

type EdgeMap map[*Node]*Edge

NodeMap type #

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

type NodeMap map[NodeInfo]*Node

NodeOrder type #

NodeOrder sets the ordering for a Sort operation

type NodeOrder int

NodePtrSet type #

NodePtrSet 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]bool

NodeSet type #

NodeSet is a collection of node info structs.

type NodeSet map[NodeInfo]bool

Nodes type #

Nodes is an ordered collection of graph nodes.

type Nodes []*Node

TagMap type #

TagMap is a collection of tags, classified by their name.

type TagMap map[string]*Tag

edgeList type #

type edgeList []*Edge

Structs

DotAttributes struct #

DotAttributes contains details about the graph itself, giving insight into how its elements should be rendered.

type DotAttributes struct {
Nodes map[*Node]*DotNodeAttributes
}

DotConfig struct #

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 struct #

DotNodeAttributes contains Node specific visualization options.

type DotNodeAttributes struct {
Shape string
Bold bool
Peripheries int
URL string
Formatter func(*NodeInfo) string
}

Edge struct #

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 struct #

Graph summarizes a performance profile into a format that is suitable for visualization.

type Graph struct {
Nodes Nodes
}

Node struct #

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 struct #

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 struct #

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 struct #

Tag represent sample annotations

type Tag struct {
Name string
Unit string
Value int64
Flat int64
FlatDiv int64
Cum int64
CumDiv int64
}

builder struct #

builder wraps an io.Writer and understands how to compose DOT formatted elements.

type builder struct {
io.Writer
attributes *DotAttributes
config *DotConfig
}

nodePair struct #

type nodePair struct {
src *Node
dest *Node
}

nodeSorter struct #

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
}

tags struct #

type tags struct {
t []*Tag
flat bool
}

Functions

AddToEdge method #

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 method #

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 function #

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 function #

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 method #

CumValue returns the inclusive value for this tag, computing the mean if a divisor is available.

func (t *Tag) CumValue() int64

CumValue method #

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

func (n *Node) CumValue() int64

DiscardLowFrequencyNodePtrs method #

DiscardLowFrequencyNodePtrs returns a NodePtrSet of nodes at or over a specific cum value cutoff.

func (g *Graph) DiscardLowFrequencyNodePtrs(nodeCutoff int64) NodePtrSet

DiscardLowFrequencyNodes method #

DiscardLowFrequencyNodes returns a set of the nodes at or over a specific cum value cutoff.

func (g *Graph) DiscardLowFrequencyNodes(nodeCutoff int64) NodeSet

FindOrInsertNode method #

FindOrInsertNode 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) *Node

FlatValue method #

FlatValue returns the exclusive value for this tag, computing the mean if a divisor is available.

func (t *Tag) FlatValue() int64

FlatValue method #

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

func (n *Node) FlatValue() int64

Len method #

func (el edgeList) Len() int

Len method #

func (s nodeSorter) Len() int

Len method #

func (t tags) Len() int

Less method #

func (el edgeList) Less(i int, j int) bool

Less method #

func (t tags) Less(i int, j int) bool

Less method #

func (s nodeSorter) Less(i int, j int) bool

NameComponents method #

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

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

New function #

New summarizes performance data from a profile into a graph.

func New(prof *profile.Profile, o *Options) *Graph

PrintableName method #

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

func (i *NodeInfo) PrintableName() string

RemoveRedundantEdges method #

RemoveRedundantEdges 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 method #

SelectTopNodePtrs returns a set of the top maxNodes *Node in a graph.

func (g *Graph) SelectTopNodePtrs(maxNodes int, visualMode bool) NodePtrSet

SelectTopNodes method #

SelectTopNodes returns a set of the top maxNodes nodes in a graph.

func (g *Graph) SelectTopNodes(maxNodes int, visualMode bool) NodeSet

ShortenFunctionName function #

ShortenFunctionName returns a shortened version of a function's name.

func ShortenFunctionName(f string) string

Sort method #

Sort 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() []*Edge

Sort method #

Sort 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) error

SortNodes method #

SortNodes sorts the nodes in a graph based on a specific heuristic.

func (g *Graph) SortNodes(cum bool, visualMode bool)

SortTags function #

SortTags sorts a slice of tags based on their weight.

func SortTags(t []*Tag, flat bool) []*Tag

String method #

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

func (g *Graph) String() string

Sum method #

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

func (ns Nodes) Sum() (flat int64, cum int64)

Sum method #

Sum returns the total weight for a set of nodes.

func (e EdgeMap) Sum() int64

Swap method #

func (el edgeList) Swap(i int, j int)

Swap method #

func (t tags) Swap(i int, j int)

Swap method #

func (s nodeSorter) Swap(i int, j int)

TrimLowFrequencyEdges method #

TrimLowFrequencyEdges removes edges that have less than the specified weight. Returns the number of edges removed

func (g *Graph) TrimLowFrequencyEdges(edgeCutoff int64) int

TrimLowFrequencyTags method #

TrimLowFrequencyTags removes tags that have less than the specified weight.

func (g *Graph) TrimLowFrequencyTags(tagCutoff int64)

TrimTree method #

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 method #

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

func (e *Edge) WeightValue() int64

abs64 function #

func abs64(i int64) int64

addEdge method #

addEdge generates a graph edge in DOT format.

func (b *builder) addEdge(edge *Edge, from int, to int, hasNodelets bool)

addLegend method #

addLegend generates a legend in DOT format.

func (b *builder) addLegend()

addNode method #

addNode generates a graph node in DOT format.

func (b *builder) addNode(node *Node, nodeID int, maxFlat float64)

addNodelets method #

addNodelets generates the DOT boxes for the node tags if they exist.

func (b *builder) addNodelets(node *Node, nodeID int) bool

addSample method #

func (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 method #

collapsedTags trims and sorts a slice of tags.

func (b *builder) collapsedTags(ts []*Tag, count int, flatTags bool) []*Tag

compareNodes function #

compareNodes 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) bool

countTags function #

countTags counts the tags with flat count. This underestimates the number of tags being displayed, but in practice is close enough.

func countTags(n *Node) int

defaultLabelFormat function #

func defaultLabelFormat(v int64, key string) string

dotColor function #

dotColor 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) string

edgeEntropyScore function #

edgeEntropyScore 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) float64

entropyScore function #

entropyScore 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) int64

escapeAllForDot function #

escapeAllForDot applies escapeForDot to all strings in the given slice.

func escapeAllForDot(in []string) []string

escapeForDot function #

escapeForDot 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) string

findOrAddTag method #

func (m TagMap) findOrAddTag(label string, unit string, value int64) *Tag

findOrInsertLine method #

func (nm NodeMap) findOrInsertLine(l *profile.Location, li profile.Line, o *Options) *Node

finish method #

finish closes the opening curly bracket in the constructed DOT buffer.

func (b *builder) finish()

getNodesAboveCumCutoff function #

getNodesAboveCumCutoff returns all the nodes which have a Cum value greater than or equal to cutoff.

func getNodesAboveCumCutoff(nodes Nodes, nodeCutoff int64) Nodes

isNegative function #

isNegative returns true if the node is considered as "negative" for the purposes of drop_negative.

func isNegative(n *Node) bool

isRedundantEdge function #

isRedundantEdge determines if there is a path that allows e.Src to reach e.Dest after removing e.

func isRedundantEdge(e *Edge) bool

joinLabels function #

func joinLabels(s *profile.Sample) string

makeNodeSet function #

func makeNodeSet(nodes Nodes, nodeCutoff int64) NodeSet

min64 function #

func min64(a int64, b int64) int64

multilinePrintableName function #

func multilinePrintableName(info *NodeInfo) string

newGraph function #

newGraph 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)

newTree function #

func newTree(prof *profile.Profile, o *Options) (g *Graph)

nodeInfo function #

func nodeInfo(l *profile.Location, line profile.Line, objfile string, o *Options) *NodeInfo

nodes method #

func (nm NodeMap) nodes() Nodes

numericNodelets method #

func (b *builder) numericNodelets(nts []*Tag, maxNumNodelets int, flatTags bool, source string) string

selectNodesForGraph function #

func selectNodesForGraph(nodes Nodes, dropNegative bool) *Graph

selectTopNodes method #

selectTopNodes returns a slice of the top maxNodes nodes in a graph.

func (g *Graph) selectTopNodes(maxNodes int, visualMode bool) Nodes

start method #

start generates a title and initial node in DOT format.

func (b *builder) start()

tagDistance function #

func tagDistance(t *Tag, u *Tag) float64

tagGroupLabel method #

func (b *builder) tagGroupLabel(g []*Tag) (label string, flat int64, cum int64)

trimLowFreqTags function #

func trimLowFreqTags(tags TagMap, minValue int64) TagMap

Generated with Arrow