| 1 | // Copyright 2014 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Package graph collects a set of samples into a directed graph. |
| 16 | package graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ |
| 17 | |
| 18 | import ( |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 20 | "mathscip-go gomod github.com/golang/go/src go1.24.0 math/" |
| 21 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 22 | "regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/" |
| 23 | "sortscip-go gomod github.com/golang/go/src go1.24.0 sort/" |
| 24 | "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/" |
| 25 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 26 | |
| 27 | "github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/" |
| 28 | ) |
| 29 | |
| 30 | var ( |
| 31 | // Removes package name and method arguments for Java method names. |
| 32 | // See tests for examples. |
| 33 | javaRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/javaRegExp. = regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().(`^(?:[a-z]\w*\.)*([A-Z][\w\$]*\.(?:<init>|[a-z][\w\$]*(?:\$\d+)?))(?:(?:\()|$)`) |
| 34 | // Removes package name and method arguments for Go function names. |
| 35 | // See tests for examples. |
| 36 | goRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/goRegExp. = regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().(`^(?:[\w\-\.]+\/)+([^.]+\..+)`) |
| 37 | // Removes potential module versions in a package path. |
| 38 | goVerRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/goVerRegExp. = regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().(`^(.*?)/v(?:[2-9]|[1-9][0-9]+)([./].*)$`) |
| 39 | // Strips C++ namespace prefix from a C++ function / method name. |
| 40 | // NOTE: Make sure to keep the template parameters in the name. Normally, |
| 41 | // template parameters are stripped from the C++ names but when |
| 42 | // -symbolize=demangle=templates flag is used, they will not be. |
| 43 | // See tests for examples. |
| 44 | cppRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/cppRegExp. = regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().(`^(?:[_a-zA-Z]\w*::)+(_*[A-Z]\w*::~?[_a-zA-Z]\w*(?:<.*>)?)`) |
| 45 | cppAnonymousPrefixRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/cppAnonymousPrefixRegExp. = regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().(`^\(anonymous namespace\)::`) |
| 46 | ) |
| 47 | |
| 48 | // Graph summarizes a performance profile into a format that is |
| 49 | // suitable for visualization. |
| 50 | type Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph# struct { |
| 51 | Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# |
| 52 | } |
| 53 | |
| 54 | // Options encodes the options for constructing a graph |
| 55 | type Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options# struct { |
| 56 | SampleValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#SampleValue. func(s []int64) int64 // Function to compute the value of a sample |
| 57 | SampleMeanDivisorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#SampleMeanDivisor. func(s []int64) int64 // Function to compute the divisor for mean graphs, or nil |
| 58 | FormatTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#FormatTag. func(int64, string) string // Function to format a sample tag value into a string |
| 59 | ObjNamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#ObjNames. bool // Always preserve obj filename |
| 60 | OrigFnNamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#OrigFnNames. bool // Preserve original (eg mangled) function names |
| 61 | |
| 62 | CallTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#CallTree. bool // Build a tree instead of a graph |
| 63 | DropNegativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#DropNegative. bool // Drop nodes with overall negative values |
| 64 | |
| 65 | KeptNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#KeptNodes. NodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeSet# // If non-nil, only use nodes in this set |
| 66 | } |
| 67 | |
| 68 | // Nodes is an ordered collection of graph nodes. |
| 69 | type Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# []*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# |
| 70 | |
| 71 | // Node is an entry on a profiling report. It represents a unique |
| 72 | // program location. |
| 73 | type Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# struct { |
| 74 | // Info describes the source location associated to this node. |
| 75 | Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info. NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo# |
| 76 | |
| 77 | // Function represents the function that this node belongs to. On |
| 78 | // graphs with sub-function resolution (eg line number or |
| 79 | // addresses), two nodes in a NodeMap that are part of the same |
| 80 | // function have the same value of Node.Function. If the Node |
| 81 | // represents the whole function, it points back to itself. |
| 82 | Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Function. *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# |
| 83 | |
| 84 | // Values associated to this node. Flat is exclusive to this node, |
| 85 | // Cum includes all descendents. |
| 86 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat., FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#FlatDiv., Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum., CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#CumDiv. int64 |
| 87 | |
| 88 | // In and out Contains the nodes immediately reaching or reached by |
| 89 | // this node. |
| 90 | Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In., Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out. EdgeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap# |
| 91 | |
| 92 | // LabelTags provide additional information about subsets of a sample. |
| 93 | LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags. TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap# |
| 94 | |
| 95 | // NumericTags provide additional values for subsets of a sample. |
| 96 | // Numeric tags are optionally associated to a label tag. The key |
| 97 | // for NumericTags is the name of the LabelTag they are associated |
| 98 | // to, or "" for numeric tags not associated to a label tag. |
| 99 | NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags. map[string]TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap# |
| 100 | } |
| 101 | |
| 102 | // FlatValue returns the exclusive value for this node, computing the |
| 103 | // mean if a divisor is available. |
| 104 | func (n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) FlatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#FlatValue().() int64 { |
| 105 | if n.FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#FlatDiv. == 0 { |
| 106 | return n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. |
| 107 | } |
| 108 | return n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. / n.FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#FlatDiv. |
| 109 | } |
| 110 | |
| 111 | // CumValue returns the inclusive value for this node, computing the |
| 112 | // mean if a divisor is available. |
| 113 | func (n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) CumValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#CumValue().() int64 { |
| 114 | if n.CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#CumDiv. == 0 { |
| 115 | return n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum. |
| 116 | } |
| 117 | return n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum. / n.CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#CumDiv. |
| 118 | } |
| 119 | |
| 120 | // AddToEdge increases the weight of an edge between two nodes. If |
| 121 | // there isn't such an edge one is created. |
| 122 | func (n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) AddToEdgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#AddToEdge().(to *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#, v int64, residual, inline bool) { |
| 123 | n.AddToEdgeDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#AddToEdgeDiv().(to, 0, v, residual, inline) |
| 124 | } |
| 125 | |
| 126 | // AddToEdgeDiv increases the weight of an edge between two nodes. If |
| 127 | // there isn't such an edge one is created. |
| 128 | func (n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) AddToEdgeDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#AddToEdgeDiv().(to *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#, dv, v int64, residual, inline bool) { |
| 129 | if n.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.[to] != to.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.[n] { |
| 130 | panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("asymmetric edges %v %v", *n, *to)) |
| 131 | } |
| 132 | |
| 133 | if e := n.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.[to]; e != nil { |
| 134 | e.WeightDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#WeightDiv. += dv |
| 135 | e.Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight. += v |
| 136 | if residual { |
| 137 | e.Residualscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Residual. = true |
| 138 | } |
| 139 | if !inline { |
| 140 | e.Inlinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Inline. = false |
| 141 | } |
| 142 | return |
| 143 | } |
| 144 | |
| 145 | info := &Edgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#{Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src.: n, Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest.: to, WeightDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#WeightDiv.: dv, Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight.: v, Residualscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Residual.: residual, Inlinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Inline.: inline} |
| 146 | n.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.[to] = info |
| 147 | to.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.[n] = info |
| 148 | } |
| 149 | |
| 150 | // NodeInfo contains the attributes for a node. |
| 151 | type NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo# struct { |
| 152 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name. string |
| 153 | OrigNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#OrigName. string |
| 154 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. uint64 |
| 155 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File. string |
| 156 | StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#StartLine., Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno. int |
| 157 | Columnnoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Columnno. int |
| 158 | Objfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Objfile. string |
| 159 | } |
| 160 | |
| 161 | // PrintableName calls the Node's Formatter function with a single space separator. |
| 162 | func (i *NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#) PrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#PrintableName().() string { |
| 163 | return stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(i.NameComponentsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#NameComponents().(), " ") |
| 164 | } |
| 165 | |
| 166 | // NameComponents returns the components of the printable name to be used for a node. |
| 167 | func (i *NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#) NameComponentsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#NameComponents().() []string { |
| 168 | var name []string |
| 169 | if i.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. != 0 { |
| 170 | name = append(name, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("%016x", i.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address.)) |
| 171 | } |
| 172 | if fun := i.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.; fun != "" { |
| 173 | name = append(name, fun) |
| 174 | } |
| 175 | |
| 176 | switch { |
| 177 | case i.Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno. != 0: |
| 178 | s := fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("%s:%d", i.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File., i.Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno.) |
| 179 | if i.Columnnoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Columnno. != 0 { |
| 180 | s += fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().(":%d", i.Columnnoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Columnno.) |
| 181 | } |
| 182 | // User requested line numbers, provide what we have. |
| 183 | name = append(name, s) |
| 184 | case i.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File. != "": |
| 185 | // User requested file name, provide it. |
| 186 | name = append(name, i.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File.) |
| 187 | case i.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name. != "": |
| 188 | // User requested function name. It was already included. |
| 189 | case i.Objfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Objfile. != "": |
| 190 | // Only binary name is available |
| 191 | name = append(name, "["+filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Base().(i.Objfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Objfile.)+"]") |
| 192 | default: |
| 193 | // Do not leave it empty if there is no information at all. |
| 194 | name = append(name, "<unknown>") |
| 195 | } |
| 196 | return name |
| 197 | } |
| 198 | |
| 199 | // comparePrintableName compares NodeInfo lexicographically the same way as `i.PrintableName() < right.PrintableName()`, but much more performant. |
| 200 | func (i *NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#) comparePrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#comparePrintableName().(right NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#) (equal bool, less bool) { |
| 201 | if right == *i { |
| 202 | return true, false |
| 203 | } |
| 204 | |
| 205 | if i.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. != 0 && right.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. != 0 && i.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. != right.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. { |
| 206 | // comparing ints directly is the same as comparing padded hex from fmt.Sprintf("%016x", Address) |
| 207 | return false, i.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. < right.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. |
| 208 | } |
| 209 | |
| 210 | // fallback |
| 211 | return false, i.PrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#PrintableName().() < right.PrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#PrintableName().() |
| 212 | } |
| 213 | |
| 214 | // NodeMap maps from a node info struct to a node. It is used to merge |
| 215 | // report entries with the same info. |
| 216 | type NodeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap# map[NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#]*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# |
| 217 | |
| 218 | // NodeSet is a collection of node info structs. |
| 219 | type NodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeSet# map[NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#]bool |
| 220 | |
| 221 | // NodePtrSet is a collection of nodes. Trimming a graph or tree requires a set |
| 222 | // of objects which uniquely identify the nodes to keep. In a graph, NodeInfo |
| 223 | // works as a unique identifier; however, in a tree multiple nodes may share |
| 224 | // identical NodeInfos. A *Node does uniquely identify a node so we can use that |
| 225 | // instead. Though a *Node also uniquely identifies a node in a graph, |
| 226 | // currently, during trimming, graphs are rebuilt from scratch using only the |
| 227 | // NodeSet, so there would not be the required context of the initial graph to |
| 228 | // allow for the use of *Node. |
| 229 | type NodePtrSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodePtrSet# map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]bool |
| 230 | |
| 231 | // FindOrInsertNode takes the info for a node and either returns a matching node |
| 232 | // from the node map if one exists, or adds one to the map if one does not. |
| 233 | // If kept is non-nil, nodes are only added if they can be located on it. |
| 234 | func (nm NodeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#) FindOrInsertNodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#FindOrInsertNode().(info NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#, kept NodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeSet#) *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# { |
| 235 | if kept != nil { |
| 236 | if _, ok := kept[info]; !ok { |
| 237 | return nil |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | if n, ok := nm[info]; ok { |
| 242 | return n |
| 243 | } |
| 244 | |
| 245 | n := &Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#{ |
| 246 | Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info.: info, |
| 247 | Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.: make(EdgeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap#), |
| 248 | Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.: make(EdgeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap#), |
| 249 | LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags.: make(TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#), |
| 250 | NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags.: make(map[string]TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#), |
| 251 | } |
| 252 | nm[info] = n |
| 253 | if info.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. == 0 && info.Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno. == 0 { |
| 254 | // This node represents the whole function, so point Function |
| 255 | // back to itself. |
| 256 | n.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Function. = n |
| 257 | return n |
| 258 | } |
| 259 | // Find a node that represents the whole function. |
| 260 | info.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address. = 0 |
| 261 | info.Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno. = 0 |
| 262 | info.Columnnoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Columnno. = 0 |
| 263 | n.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Function. = nm.FindOrInsertNodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#FindOrInsertNode().(info, nil) |
| 264 | return n |
| 265 | } |
| 266 | |
| 267 | // EdgeMap is used to represent the incoming/outgoing edges from a node. |
| 268 | type EdgeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap# map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]*Edgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge# |
| 269 | |
| 270 | // Edge contains any attributes to be represented about edges in a graph. |
| 271 | type Edgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge# struct { |
| 272 | Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src., Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest. *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# |
| 273 | // The summary weight of the edge |
| 274 | Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight., WeightDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#WeightDiv. int64 |
| 275 | |
| 276 | // residual edges connect nodes that were connected through a |
| 277 | // separate node, which has been removed from the report. |
| 278 | Residualscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Residual. bool |
| 279 | // An inline edge represents a call that was inlined into the caller. |
| 280 | Inlinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Inline. bool |
| 281 | } |
| 282 | |
| 283 | // WeightValue returns the weight value for this edge, normalizing if a |
| 284 | // divisor is available. |
| 285 | func (e *Edgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#) WeightValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#WeightValue().() int64 { |
| 286 | if e.WeightDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#WeightDiv. == 0 { |
| 287 | return e.Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight. |
| 288 | } |
| 289 | return e.Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight. / e.WeightDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#WeightDiv. |
| 290 | } |
| 291 | |
| 292 | // Tag represent sample annotations |
| 293 | type Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag# struct { |
| 294 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name. string |
| 295 | Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Unit. string // Describe the value, "" for non-numeric tags |
| 296 | Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Value. int64 |
| 297 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat., FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#FlatDiv. int64 |
| 298 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum., CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#CumDiv. int64 |
| 299 | } |
| 300 | |
| 301 | // FlatValue returns the exclusive value for this tag, computing the |
| 302 | // mean if a divisor is available. |
| 303 | func (t *Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#) FlatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#FlatValue().() int64 { |
| 304 | if t.FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#FlatDiv. == 0 { |
| 305 | return t.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat. |
| 306 | } |
| 307 | return t.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat. / t.FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#FlatDiv. |
| 308 | } |
| 309 | |
| 310 | // CumValue returns the inclusive value for this tag, computing the |
| 311 | // mean if a divisor is available. |
| 312 | func (t *Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#) CumValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#CumValue().() int64 { |
| 313 | if t.CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#CumDiv. == 0 { |
| 314 | return t.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum. |
| 315 | } |
| 316 | return t.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum. / t.CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#CumDiv. |
| 317 | } |
| 318 | |
| 319 | // TagMap is a collection of tags, classified by their name. |
| 320 | type TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap# map[string]*Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag# |
| 321 | |
| 322 | // SortTags sorts a slice of tags based on their weight. |
| 323 | func SortTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/SortTags().(t []*Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#, flat bool) []*Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag# { |
| 324 | ts := tagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#{t, flat} |
| 325 | sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Sortscip-go gomod github.com/golang/go/src go1.24.0 sort/Sort().(ts) |
| 326 | return ts.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t. |
| 327 | } |
| 328 | |
| 329 | // New summarizes performance data from a profile into a graph. |
| 330 | func Newscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/New().(prof *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, o *Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#) *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph# { |
| 331 | if o.CallTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#CallTree. { |
| 332 | return newTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/newTree().(prof, o) |
| 333 | } |
| 334 | g, _ := newGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/newGraph().(prof, o) |
| 335 | return g |
| 336 | } |
| 337 | |
| 338 | // newGraph computes a graph from a profile. It returns the graph, and |
| 339 | // a map from the profile location indices to the corresponding graph |
| 340 | // nodes. |
| 341 | func newGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/newGraph().(prof *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, o *Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#) (*Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#, map[uint64]Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#) { |
| 342 | nodes, locationMap := CreateNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/CreateNodes().(prof, o) |
| 343 | seenNode := make(map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]bool) |
| 344 | seenEdge := make(map[nodePairscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodePair#]bool) |
| 345 | for _, sample := range prof.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. { |
| 346 | var w, dw int64 |
| 347 | w = o.SampleValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#SampleValue.(sample.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.) |
| 348 | if o.SampleMeanDivisorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#SampleMeanDivisor. != nil { |
| 349 | dw = o.SampleMeanDivisorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#SampleMeanDivisor.(sample.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.) |
| 350 | } |
| 351 | if dw == 0 && w == 0 { |
| 352 | continue |
| 353 | } |
| 354 | clear(seenNode) |
| 355 | clear(seenEdge) |
| 356 | var parent *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# |
| 357 | // A residual edge goes over one or more nodes that were not kept. |
| 358 | residual := false |
| 359 | |
| 360 | labels := joinLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/joinLabels().(sample) |
| 361 | // Group the sample frames, based on a global map. |
| 362 | for i := len(sample.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.) - 1; i >= 0; i-- { |
| 363 | l := sample.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[i] |
| 364 | locNodes := locationMap[l.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.] |
| 365 | for ni := len(locNodes) - 1; ni >= 0; ni-- { |
| 366 | n := locNodes[ni] |
| 367 | if n == nil { |
| 368 | residual = true |
| 369 | continue |
| 370 | } |
| 371 | // Add cum weight to all nodes in stack, avoiding double counting. |
| 372 | if _, ok := seenNode[n]; !ok { |
| 373 | seenNode[n] = true |
| 374 | n.addSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#addSample().(dw, w, labels, sample.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel., sample.NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit., o.FormatTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#FormatTag., false) |
| 375 | } |
| 376 | // Update edge weights for all edges in stack, avoiding double counting. |
| 377 | if _, ok := seenEdge[nodePairscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodePair#{n, parent}]; !ok && parent != nil && n != parent { |
| 378 | seenEdge[nodePairscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodePair#{n, parent}] = true |
| 379 | parent.AddToEdgeDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#AddToEdgeDiv().(n, dw, w, residual, ni != len(locNodes)-1) |
| 380 | } |
| 381 | parent = n |
| 382 | residual = false |
| 383 | } |
| 384 | } |
| 385 | if parent != nil && !residual { |
| 386 | // Add flat weight to leaf node. |
| 387 | parent.addSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#addSample().(dw, w, labels, sample.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel., sample.NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit., o.FormatTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#FormatTag., true) |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | return selectNodesForGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/selectNodesForGraph().(nodes, o.DropNegativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#DropNegative.), locationMap |
| 392 | } |
| 393 | |
| 394 | func selectNodesForGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/selectNodesForGraph().(nodes Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, dropNegative bool) *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph# { |
| 395 | // Collect nodes into a graph. |
| 396 | gNodes := make(Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, 0, len(nodes)) |
| 397 | for _, n := range nodes { |
| 398 | if n == nil { |
| 399 | continue |
| 400 | } |
| 401 | if n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum. == 0 && n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. == 0 { |
| 402 | continue |
| 403 | } |
| 404 | if dropNegative && isNegativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/isNegative().(n) { |
| 405 | continue |
| 406 | } |
| 407 | gNodes = append(gNodes, n) |
| 408 | } |
| 409 | return &Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#{gNodes} |
| 410 | } |
| 411 | |
| 412 | type nodePairscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodePair# struct { |
| 413 | srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodePair#src., destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodePair#dest. *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# |
| 414 | } |
| 415 | |
| 416 | func newTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/newTree().(prof *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, o *Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#) (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) { |
| 417 | parentNodeMap := make(map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]NodeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#, len(prof.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample.)) |
| 418 | for _, sample := range prof.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. { |
| 419 | var w, dw int64 |
| 420 | w = o.SampleValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#SampleValue.(sample.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.) |
| 421 | if o.SampleMeanDivisorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#SampleMeanDivisor. != nil { |
| 422 | dw = o.SampleMeanDivisorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#SampleMeanDivisor.(sample.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.) |
| 423 | } |
| 424 | if dw == 0 && w == 0 { |
| 425 | continue |
| 426 | } |
| 427 | var parent *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# |
| 428 | labels := joinLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/joinLabels().(sample) |
| 429 | // Group the sample frames, based on a per-node map. |
| 430 | for i := len(sample.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.) - 1; i >= 0; i-- { |
| 431 | l := sample.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[i] |
| 432 | lines := l.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. |
| 433 | if len(lines) == 0 { |
| 434 | lines = []profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#{{}} // Create empty line to include location info. |
| 435 | } |
| 436 | for lidx := len(lines) - 1; lidx >= 0; lidx-- { |
| 437 | nodeMap := parentNodeMap[parent] |
| 438 | if nodeMap == nil { |
| 439 | nodeMap = make(NodeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#) |
| 440 | parentNodeMap[parent] = nodeMap |
| 441 | } |
| 442 | n := nodeMap.findOrInsertLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#findOrInsertLine().(l, lines[lidx], o) |
| 443 | if n == nil { |
| 444 | continue |
| 445 | } |
| 446 | n.addSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#addSample().(dw, w, labels, sample.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel., sample.NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit., o.FormatTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#FormatTag., false) |
| 447 | if parent != nil { |
| 448 | parent.AddToEdgeDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#AddToEdgeDiv().(n, dw, w, false, lidx != len(lines)-1) |
| 449 | } |
| 450 | parent = n |
| 451 | } |
| 452 | } |
| 453 | if parent != nil { |
| 454 | parent.addSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#addSample().(dw, w, labels, sample.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel., sample.NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit., o.FormatTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#FormatTag., true) |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | nodes := make(Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, 0, len(prof.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location.)) |
| 459 | for _, nm := range parentNodeMap { |
| 460 | nodes = append(nodes, nm.nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#nodes().()...) |
| 461 | } |
| 462 | return selectNodesForGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/selectNodesForGraph().(nodes, o.DropNegativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#DropNegative.) |
| 463 | } |
| 464 | |
| 465 | // ShortenFunctionName returns a shortened version of a function's name. |
| 466 | func ShortenFunctionNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ShortenFunctionName().(f string) string { |
| 467 | f = cppAnonymousPrefixRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/cppAnonymousPrefixRegExp..ReplaceAllStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#ReplaceAllString().(f, "") |
| 468 | f = goVerRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/goVerRegExp..ReplaceAllStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#ReplaceAllString().(f, `${1}${2}`) |
| 469 | for _, re := range []*regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#{goRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/goRegExp., javaRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/javaRegExp., cppRegExpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/cppRegExp.} { |
| 470 | if matches := re.FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(f); len(matches) >= 2 { |
| 471 | return stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(matches[1:], "") |
| 472 | } |
| 473 | } |
| 474 | return f |
| 475 | } |
| 476 | |
| 477 | // TrimTree trims a Graph in forest form, keeping only the nodes in kept. This |
| 478 | // will not work correctly if even a single node has multiple parents. |
| 479 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) TrimTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#TrimTree().(kept NodePtrSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodePtrSet#) { |
| 480 | // Creates a new list of nodes |
| 481 | oldNodes := g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. |
| 482 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. = make(Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, 0, len(kept)) |
| 483 | |
| 484 | for _, cur := range oldNodes { |
| 485 | // A node may not have multiple parents |
| 486 | if len(cur.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.) > 1 { |
| 487 | panic("TrimTree only works on trees") |
| 488 | } |
| 489 | |
| 490 | // If a node should be kept, add it to the new list of nodes |
| 491 | if _, ok := kept[cur]; ok { |
| 492 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. = append(g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes., cur) |
| 493 | continue |
| 494 | } |
| 495 | |
| 496 | // If a node has no parents, then delete all of the in edges of its |
| 497 | // children to make them each roots of their own trees. |
| 498 | if len(cur.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.) == 0 { |
| 499 | for _, outEdge := range cur.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out. { |
| 500 | delete(outEdge.Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest..Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In., cur) |
| 501 | } |
| 502 | continue |
| 503 | } |
| 504 | |
| 505 | // Get the parent. This works since at this point cur.In must contain only |
| 506 | // one element. |
| 507 | if len(cur.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.) != 1 { |
| 508 | panic("Get parent assertion failed. cur.In expected to be of length 1.") |
| 509 | } |
| 510 | var parent *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# |
| 511 | for _, edge := range cur.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In. { |
| 512 | parent = edge.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src. |
| 513 | } |
| 514 | |
| 515 | parentEdgeInline := parent.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.[cur].Inlinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Inline. |
| 516 | |
| 517 | // Remove the edge from the parent to this node |
| 518 | delete(parent.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out., cur) |
| 519 | |
| 520 | // Reconfigure every edge from the current node to now begin at the parent. |
| 521 | for _, outEdge := range cur.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out. { |
| 522 | child := outEdge.Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest. |
| 523 | |
| 524 | delete(child.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In., cur) |
| 525 | child.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.[parent] = outEdge |
| 526 | parent.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.[child] = outEdge |
| 527 | |
| 528 | outEdge.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src. = parent |
| 529 | outEdge.Residualscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Residual. = true |
| 530 | // If the edge from the parent to the current node and the edge from the |
| 531 | // current node to the child are both inline, then this resulting residual |
| 532 | // edge should also be inline |
| 533 | outEdge.Inlinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Inline. = parentEdgeInline && outEdge.Inlinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Inline. |
| 534 | } |
| 535 | } |
| 536 | g.RemoveRedundantEdgesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#RemoveRedundantEdges().() |
| 537 | } |
| 538 | |
| 539 | func joinLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/joinLabels().(s *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) string { |
| 540 | if len(s.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label.) == 0 { |
| 541 | return "" |
| 542 | } |
| 543 | |
| 544 | var labels []string |
| 545 | for key, vals := range s.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label. { |
| 546 | for _, v := range vals { |
| 547 | labels = append(labels, key+":"+v) |
| 548 | } |
| 549 | } |
| 550 | sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Stringsscip-go gomod github.com/golang/go/src go1.24.0 sort/Strings().(labels) |
| 551 | return stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(labels, `\n`) |
| 552 | } |
| 553 | |
| 554 | // isNegative returns true if the node is considered as "negative" for the |
| 555 | // purposes of drop_negative. |
| 556 | func isNegativescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/isNegative().(n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool { |
| 557 | switch { |
| 558 | case n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. < 0: |
| 559 | return true |
| 560 | case n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. == 0 && n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum. < 0: |
| 561 | return true |
| 562 | default: |
| 563 | return false |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | // CreateNodes creates graph nodes for all locations in a profile. It |
| 568 | // returns set of all nodes, plus a mapping of each location to the |
| 569 | // set of corresponding nodes (one per location.Line). |
| 570 | func CreateNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/CreateNodes().(prof *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, o *Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#) (Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, map[uint64]Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#) { |
| 571 | locations := make(map[uint64]Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, len(prof.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location.)) |
| 572 | nm := make(NodeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#, len(prof.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location.)) |
| 573 | for _, l := range prof.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. { |
| 574 | lines := l.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. |
| 575 | if len(lines) == 0 { |
| 576 | lines = []profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#{{}} // Create empty line to include location info. |
| 577 | } |
| 578 | nodes := make(Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, len(lines)) |
| 579 | for ln := range lines { |
| 580 | nodes[ln] = nm.findOrInsertLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#findOrInsertLine().(l, lines[ln], o) |
| 581 | } |
| 582 | locations[l.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.] = nodes |
| 583 | } |
| 584 | return nm.nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#nodes().(), locations |
| 585 | } |
| 586 | |
| 587 | func (nm NodeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#) nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#nodes().() Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# { |
| 588 | nodes := make(Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, 0, len(nm)) |
| 589 | for _, n := range nm { |
| 590 | nodes = append(nodes, n) |
| 591 | } |
| 592 | return nodes |
| 593 | } |
| 594 | |
| 595 | func (nm NodeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#) findOrInsertLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#findOrInsertLine().(l *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, li profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#, o *Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#) *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node# { |
| 596 | var objfile string |
| 597 | if m := l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.; m != nil && m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File. != "" { |
| 598 | objfile = m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File. |
| 599 | } |
| 600 | |
| 601 | ni := nodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeInfo().(l, li, objfile, o) |
| 602 | |
| 603 | return nm.FindOrInsertNodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeMap#FindOrInsertNode().(ni, o.KeptNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#KeptNodes.) |
| 604 | } |
| 605 | |
| 606 | func nodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeInfo().(l *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, line profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#, objfile string, o *Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#) NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo# { |
| 607 | if line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function. == nil { |
| 608 | return NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#{Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address.: l.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address., Objfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Objfile.: objfile} |
| 609 | } |
| 610 | ni := NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#{ |
| 611 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address.: l.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address., |
| 612 | Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno.: int(line.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.), |
| 613 | Columnnoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Columnno.: int(line.Columnscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Column.), |
| 614 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name., |
| 615 | } |
| 616 | if fname := line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.; fname != "" { |
| 617 | ni.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File. = filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Clean().(fname) |
| 618 | } |
| 619 | if o.OrigFnNamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#OrigFnNames. { |
| 620 | ni.OrigNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#OrigName. = line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName. |
| 621 | } |
| 622 | if o.ObjNamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Options#ObjNames. || (ni.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name. == "" && ni.OrigNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#OrigName. == "") { |
| 623 | ni.Objfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Objfile. = objfile |
| 624 | ni.StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#StartLine. = int(line.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function..StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#StartLine.) |
| 625 | } |
| 626 | return ni |
| 627 | } |
| 628 | |
| 629 | type tagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags# struct { |
| 630 | tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t. []*Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag# |
| 631 | flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#flat. bool |
| 632 | } |
| 633 | |
| 634 | func (t tagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#) Lenscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#Len().() int { return len(t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.) } |
| 635 | func (t tagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#) Swapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#Swap().(i, j int) { t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[i], t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[j] = t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[j], t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[i] } |
| 636 | func (t tagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#) Lessscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#Less().(i, j int) bool { |
| 637 | if !t.flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#flat. { |
| 638 | if t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[i].Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum. != t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[j].Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum. { |
| 639 | return abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[i].Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.) > abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[j].Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.) |
| 640 | } |
| 641 | } |
| 642 | if t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[i].Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat. != t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[j].Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat. { |
| 643 | return abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[i].Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.) > abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[j].Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.) |
| 644 | } |
| 645 | return t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[i].Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name. < t.tscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tags#t.[j].Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name. |
| 646 | } |
| 647 | |
| 648 | // Sum adds the flat and cum values of a set of nodes. |
| 649 | func (ns Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#) Sumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sum().() (flat int64, cum int64) { |
| 650 | for _, n := range ns { |
| 651 | flat += n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. |
| 652 | cum += n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum. |
| 653 | } |
| 654 | return |
| 655 | } |
| 656 | |
| 657 | func (n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) addSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#addSample().(dw, w int64, labels string, numLabel map[string][]int64, numUnit map[string][]string, format func(int64, string) string, flat bool) { |
| 658 | // Update sample value |
| 659 | if flat { |
| 660 | n.FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#FlatDiv. += dw |
| 661 | n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. += w |
| 662 | } else { |
| 663 | n.CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#CumDiv. += dw |
| 664 | n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum. += w |
| 665 | } |
| 666 | |
| 667 | // Add string tags |
| 668 | if labels != "" { |
| 669 | t := n.LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags..findOrAddTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#findOrAddTag().(labels, "", 0) |
| 670 | if flat { |
| 671 | t.FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#FlatDiv. += dw |
| 672 | t.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat. += w |
| 673 | } else { |
| 674 | t.CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#CumDiv. += dw |
| 675 | t.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum. += w |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | numericTags := n.NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags.[labels] |
| 680 | if numericTags == nil { |
| 681 | numericTags = TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#{} |
| 682 | n.NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags.[labels] = numericTags |
| 683 | } |
| 684 | // Add numeric tags |
| 685 | if format == nil { |
| 686 | format = defaultLabelFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/defaultLabelFormat(). |
| 687 | } |
| 688 | for k, nvals := range numLabel { |
| 689 | units := numUnit[k] |
| 690 | for i, v := range nvals { |
| 691 | var t *Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag# |
| 692 | if len(units) > 0 { |
| 693 | t = numericTags.findOrAddTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#findOrAddTag().(format(v, units[i]), units[i], v) |
| 694 | } else { |
| 695 | t = numericTags.findOrAddTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#findOrAddTag().(format(v, k), k, v) |
| 696 | } |
| 697 | if flat { |
| 698 | t.FlatDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#FlatDiv. += dw |
| 699 | t.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat. += w |
| 700 | } else { |
| 701 | t.CumDivscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#CumDiv. += dw |
| 702 | t.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum. += w |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | func defaultLabelFormatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/defaultLabelFormat().(v int64, key string) string { |
| 709 | return strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.FormatIntscip-go gomod github.com/golang/go/src go1.24.0 strconv/FormatInt().(v, 10) |
| 710 | } |
| 711 | |
| 712 | func (m TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#) findOrAddTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#findOrAddTag().(label, unit string, value int64) *Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag# { |
| 713 | l := m[label] |
| 714 | if l == nil { |
| 715 | l = &Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 716 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name.: label, |
| 717 | Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Unit.: unit, |
| 718 | Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Value.: value, |
| 719 | } |
| 720 | m[label] = l |
| 721 | } |
| 722 | return l |
| 723 | } |
| 724 | |
| 725 | // String returns a text representation of a graph, for debugging purposes. |
| 726 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) Stringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#String().() string { |
| 727 | var s []string |
| 728 | |
| 729 | nodeIndex := make(map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]int, len(g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.)) |
| 730 | |
| 731 | for i, n := range g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. { |
| 732 | nodeIndex[n] = i + 1 |
| 733 | } |
| 734 | |
| 735 | for i, n := range g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. { |
| 736 | name := n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..PrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#PrintableName().() |
| 737 | var in, out []int |
| 738 | |
| 739 | for _, from := range n.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In. { |
| 740 | in = append(in, nodeIndex[from.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src.]) |
| 741 | } |
| 742 | for _, to := range n.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out. { |
| 743 | out = append(out, nodeIndex[to.Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest.]) |
| 744 | } |
| 745 | s = append(s, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("%d: %s[flat=%d cum=%d] %x -> %v ", i+1, name, n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat., n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum., in, out)) |
| 746 | } |
| 747 | return stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(s, "\n") |
| 748 | } |
| 749 | |
| 750 | // DiscardLowFrequencyNodes returns a set of the nodes at or over a |
| 751 | // specific cum value cutoff. |
| 752 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) DiscardLowFrequencyNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#DiscardLowFrequencyNodes().(nodeCutoff int64) NodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeSet# { |
| 753 | return makeNodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/makeNodeSet().(g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes., nodeCutoff) |
| 754 | } |
| 755 | |
| 756 | // DiscardLowFrequencyNodePtrs returns a NodePtrSet of nodes at or over a |
| 757 | // specific cum value cutoff. |
| 758 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) DiscardLowFrequencyNodePtrsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#DiscardLowFrequencyNodePtrs().(nodeCutoff int64) NodePtrSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodePtrSet# { |
| 759 | cutNodes := getNodesAboveCumCutoffscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/getNodesAboveCumCutoff().(g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes., nodeCutoff) |
| 760 | kept := make(NodePtrSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodePtrSet#, len(cutNodes)) |
| 761 | for _, n := range cutNodes { |
| 762 | kept[n] = true |
| 763 | } |
| 764 | return kept |
| 765 | } |
| 766 | |
| 767 | func makeNodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/makeNodeSet().(nodes Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, nodeCutoff int64) NodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeSet# { |
| 768 | cutNodes := getNodesAboveCumCutoffscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/getNodesAboveCumCutoff().(nodes, nodeCutoff) |
| 769 | kept := make(NodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeSet#, len(cutNodes)) |
| 770 | for _, n := range cutNodes { |
| 771 | kept[n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info.] = true |
| 772 | } |
| 773 | return kept |
| 774 | } |
| 775 | |
| 776 | // getNodesAboveCumCutoff returns all the nodes which have a Cum value greater |
| 777 | // than or equal to cutoff. |
| 778 | func getNodesAboveCumCutoffscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/getNodesAboveCumCutoff().(nodes Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, nodeCutoff int64) Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# { |
| 779 | cutoffNodes := make(Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#, 0, len(nodes)) |
| 780 | for _, n := range nodes { |
| 781 | if abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.) < nodeCutoff { |
| 782 | continue |
| 783 | } |
| 784 | cutoffNodes = append(cutoffNodes, n) |
| 785 | } |
| 786 | return cutoffNodes |
| 787 | } |
| 788 | |
| 789 | // TrimLowFrequencyTags removes tags that have less than |
| 790 | // the specified weight. |
| 791 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) TrimLowFrequencyTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#TrimLowFrequencyTags().(tagCutoff int64) { |
| 792 | // Remove nodes with value <= total*nodeFraction |
| 793 | for _, n := range g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. { |
| 794 | n.LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags. = trimLowFreqTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/trimLowFreqTags().(n.LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags., tagCutoff) |
| 795 | for s, nt := range n.NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags. { |
| 796 | n.NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags.[s] = trimLowFreqTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/trimLowFreqTags().(nt, tagCutoff) |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | func trimLowFreqTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/trimLowFreqTags().(tags TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#, minValue int64) TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap# { |
| 802 | kept := TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#{} |
| 803 | for s, t := range tags { |
| 804 | if abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(t.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.) >= minValue || abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(t.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.) >= minValue { |
| 805 | kept[s] = t |
| 806 | } |
| 807 | } |
| 808 | return kept |
| 809 | } |
| 810 | |
| 811 | // TrimLowFrequencyEdges removes edges that have less than |
| 812 | // the specified weight. Returns the number of edges removed |
| 813 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) TrimLowFrequencyEdgesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#TrimLowFrequencyEdges().(edgeCutoff int64) int { |
| 814 | var droppedEdges int |
| 815 | for _, n := range g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. { |
| 816 | for src, e := range n.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In. { |
| 817 | if abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(e.Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight.) < edgeCutoff { |
| 818 | delete(n.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In., src) |
| 819 | delete(src.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out., n) |
| 820 | droppedEdges++ |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | return droppedEdges |
| 825 | } |
| 826 | |
| 827 | // SortNodes sorts the nodes in a graph based on a specific heuristic. |
| 828 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) SortNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#SortNodes().(cum bool, visualMode bool) { |
| 829 | // Sort nodes based on requested mode |
| 830 | switch { |
| 831 | case visualMode: |
| 832 | // Specialized sort to produce a more visually-interesting graph |
| 833 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes..Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sort().(EntropyOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EntropyOrder.) |
| 834 | case cum: |
| 835 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes..Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sort().(CumNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/CumNameOrder.) |
| 836 | default: |
| 837 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes..Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sort().(FlatNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/FlatNameOrder.) |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | // SelectTopNodePtrs returns a set of the top maxNodes *Node in a graph. |
| 842 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) SelectTopNodePtrsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#SelectTopNodePtrs().(maxNodes int, visualMode bool) NodePtrSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodePtrSet# { |
| 843 | set := make(NodePtrSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodePtrSet#) |
| 844 | for _, node := range g.selectTopNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#selectTopNodes().(maxNodes, visualMode) { |
| 845 | set[node] = true |
| 846 | } |
| 847 | return set |
| 848 | } |
| 849 | |
| 850 | // SelectTopNodes returns a set of the top maxNodes nodes in a graph. |
| 851 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) SelectTopNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#SelectTopNodes().(maxNodes int, visualMode bool) NodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeSet# { |
| 852 | return makeNodeSetscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/makeNodeSet().(g.selectTopNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#selectTopNodes().(maxNodes, visualMode), 0) |
| 853 | } |
| 854 | |
| 855 | // selectTopNodes returns a slice of the top maxNodes nodes in a graph. |
| 856 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) selectTopNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#selectTopNodes().(maxNodes int, visualMode bool) Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# { |
| 857 | if maxNodes > 0 { |
| 858 | if visualMode { |
| 859 | var count int |
| 860 | // If generating a visual graph, count tags as nodes. Update |
| 861 | // maxNodes to account for them. |
| 862 | for i, n := range g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. { |
| 863 | tags := min(countTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/countTags().(n), maxNodeletsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/maxNodelets.) |
| 864 | if count += tags + 1; count >= maxNodes { |
| 865 | maxNodes = i + 1 |
| 866 | break |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | if maxNodes > len(g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.) { |
| 872 | maxNodes = len(g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.) |
| 873 | } |
| 874 | return g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[:maxNodes] |
| 875 | } |
| 876 | |
| 877 | // countTags counts the tags with flat count. This underestimates the |
| 878 | // number of tags being displayed, but in practice is close enough. |
| 879 | func countTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/countTags().(n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) int { |
| 880 | count := 0 |
| 881 | for _, e := range n.LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags. { |
| 882 | if e.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat. != 0 { |
| 883 | count++ |
| 884 | } |
| 885 | } |
| 886 | for _, t := range n.NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags. { |
| 887 | for _, e := range t { |
| 888 | if e.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat. != 0 { |
| 889 | count++ |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | return count |
| 894 | } |
| 895 | |
| 896 | // RemoveRedundantEdges removes residual edges if the destination can |
| 897 | // be reached through another path. This is done to simplify the graph |
| 898 | // while preserving connectivity. |
| 899 | func (g *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#) RemoveRedundantEdgesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#RemoveRedundantEdges().() { |
| 900 | // Walk the nodes and outgoing edges in reverse order to prefer |
| 901 | // removing edges with the lowest weight. |
| 902 | for i := len(g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.); i > 0; i-- { |
| 903 | n := g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[i-1] |
| 904 | in := n.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In..Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap#Sort().() |
| 905 | for j := len(in); j > 0; j-- { |
| 906 | e := in[j-1] |
| 907 | if !e.Residualscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Residual. { |
| 908 | // Do not remove edges heavier than a non-residual edge, to |
| 909 | // avoid potential confusion. |
| 910 | break |
| 911 | } |
| 912 | if isRedundantEdgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/isRedundantEdge().(e) { |
| 913 | delete(e.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src..Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out., e.Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest.) |
| 914 | delete(e.Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest..Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In., e.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src.) |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | // isRedundantEdge determines if there is a path that allows e.Src |
| 921 | // to reach e.Dest after removing e. |
| 922 | func isRedundantEdgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/isRedundantEdge().(e *Edgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#) bool { |
| 923 | src, n := e.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src., e.Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest. |
| 924 | seen := map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]bool{n: true} |
| 925 | queue := Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#{n} |
| 926 | for len(queue) > 0 { |
| 927 | n := queue[0] |
| 928 | queue = queue[1:] |
| 929 | for _, ie := range n.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In. { |
| 930 | if e == ie || seen[ie.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src.] { |
| 931 | continue |
| 932 | } |
| 933 | if ie.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src. == src { |
| 934 | return true |
| 935 | } |
| 936 | seen[ie.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src.] = true |
| 937 | queue = append(queue, ie.Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src.) |
| 938 | } |
| 939 | } |
| 940 | return false |
| 941 | } |
| 942 | |
| 943 | // nodeSorter is a mechanism used to allow a report to be sorted |
| 944 | // in different ways. |
| 945 | type nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter# struct { |
| 946 | rsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#rs. Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes# |
| 947 | lessscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#less. func(l, r *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool |
| 948 | } |
| 949 | |
| 950 | func (s nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#) Lenscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#Len().() int { return len(s.rsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#rs.) } |
| 951 | func (s nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#) Swapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#Swap().(i, j int) { s.rsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#rs.[i], s.rsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#rs.[j] = s.rsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#rs.[j], s.rsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#rs.[i] } |
| 952 | func (s nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#) Lessscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#Less().(i, j int) bool { return s.lessscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#less.(s.rsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#rs.[i], s.rsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#rs.[j]) } |
| 953 | |
| 954 | // Sort reorders a slice of nodes based on the specified ordering |
| 955 | // criteria. The result is sorted in decreasing order for (absolute) |
| 956 | // numeric quantities, alphabetically for text, and increasing for |
| 957 | // addresses. |
| 958 | func (ns Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#) Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Nodes#Sort().(o NodeOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeOrder#) error { |
| 959 | var s nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter# |
| 960 | |
| 961 | switch o { |
| 962 | case FlatNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/FlatNameOrder.: |
| 963 | s = nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#{ns, |
| 964 | func(l, r *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool { |
| 965 | if iv, jv := abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(l.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.), abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(r.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.); iv != jv { |
| 966 | return iv > jv |
| 967 | } |
| 968 | equal, leftLess := l.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..comparePrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#comparePrintableName().(r.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info.) |
| 969 | if !equal { |
| 970 | return leftLess |
| 971 | } |
| 972 | if iv, jv := abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(l.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.), abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(r.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.); iv != jv { |
| 973 | return iv > jv |
| 974 | } |
| 975 | return compareNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareNodes().(l, r) |
| 976 | }, |
| 977 | } |
| 978 | case FlatCumNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/FlatCumNameOrder.: |
| 979 | s = nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#{ns, |
| 980 | func(l, r *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool { |
| 981 | if iv, jv := abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(l.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.), abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(r.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.); iv != jv { |
| 982 | return iv > jv |
| 983 | } |
| 984 | if iv, jv := abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(l.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.), abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(r.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.); iv != jv { |
| 985 | return iv > jv |
| 986 | } |
| 987 | equal, leftLess := l.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..comparePrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#comparePrintableName().(r.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info.) |
| 988 | if !equal { |
| 989 | return leftLess |
| 990 | } |
| 991 | return compareNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareNodes().(l, r) |
| 992 | }, |
| 993 | } |
| 994 | case NameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NameOrder.: |
| 995 | s = nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#{ns, |
| 996 | func(l, r *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool { |
| 997 | if iv, jv := l.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name., r.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.; iv != jv { |
| 998 | return iv < jv |
| 999 | } |
| 1000 | return compareNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareNodes().(l, r) |
| 1001 | }, |
| 1002 | } |
| 1003 | case FileOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/FileOrder.: |
| 1004 | s = nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#{ns, |
| 1005 | func(l, r *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool { |
| 1006 | if iv, jv := l.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File., r.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File.; iv != jv { |
| 1007 | return iv < jv |
| 1008 | } |
| 1009 | if iv, jv := l.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#StartLine., r.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#StartLine.; iv != jv { |
| 1010 | return iv < jv |
| 1011 | } |
| 1012 | return compareNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareNodes().(l, r) |
| 1013 | }, |
| 1014 | } |
| 1015 | case AddressOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/AddressOrder.: |
| 1016 | s = nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#{ns, |
| 1017 | func(l, r *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool { |
| 1018 | if iv, jv := l.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address., r.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address.; iv != jv { |
| 1019 | return iv < jv |
| 1020 | } |
| 1021 | return compareNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareNodes().(l, r) |
| 1022 | }, |
| 1023 | } |
| 1024 | case CumNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/CumNameOrder., EntropyOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EntropyOrder.: |
| 1025 | // Hold scoring for score-based ordering |
| 1026 | var score map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]int64 |
| 1027 | scoreOrder := func(l, r *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool { |
| 1028 | if iv, jv := abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(score[l]), abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(score[r]); iv != jv { |
| 1029 | return iv > jv |
| 1030 | } |
| 1031 | equal, leftLess := l.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..comparePrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#comparePrintableName().(r.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info.) |
| 1032 | if !equal { |
| 1033 | return leftLess |
| 1034 | } |
| 1035 | if iv, jv := abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(l.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.), abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(r.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.); iv != jv { |
| 1036 | return iv > jv |
| 1037 | } |
| 1038 | return compareNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareNodes().(l, r) |
| 1039 | } |
| 1040 | |
| 1041 | switch o { |
| 1042 | case CumNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/CumNameOrder.: |
| 1043 | score = make(map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]int64, len(ns)) |
| 1044 | for _, n := range ns { |
| 1045 | score[n] = n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum. |
| 1046 | } |
| 1047 | s = nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#{ns, scoreOrder} |
| 1048 | case EntropyOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EntropyOrder.: |
| 1049 | score = make(map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]int64, len(ns)) |
| 1050 | for _, n := range ns { |
| 1051 | score[n] = entropyScorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/entropyScore().(n) |
| 1052 | } |
| 1053 | s = nodeSorterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/nodeSorter#{ns, scoreOrder} |
| 1054 | } |
| 1055 | default: |
| 1056 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("report: unrecognized sort ordering: %d", o) |
| 1057 | } |
| 1058 | sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Sortscip-go gomod github.com/golang/go/src go1.24.0 sort/Sort().(s) |
| 1059 | return nil |
| 1060 | } |
| 1061 | |
| 1062 | // compareNodes compares two nodes to provide a deterministic ordering |
| 1063 | // between them. Two nodes cannot have the same Node.Info value. |
| 1064 | func compareNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareNodes().(l, r *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) bool { |
| 1065 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprint().(l.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info.) < fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprint().(r.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info.) |
| 1066 | } |
| 1067 | |
| 1068 | // entropyScore computes a score for a node representing how important |
| 1069 | // it is to include this node on a graph visualization. It is used to |
| 1070 | // sort the nodes and select which ones to display if we have more |
| 1071 | // nodes than desired in the graph. This number is computed by looking |
| 1072 | // at the flat and cum weights of the node and the incoming/outgoing |
| 1073 | // edges. The fundamental idea is to penalize nodes that have a simple |
| 1074 | // fallthrough from their incoming to the outgoing edge. |
| 1075 | func entropyScorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/entropyScore().(n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#) int64 { |
| 1076 | score := float64(0) |
| 1077 | |
| 1078 | if len(n.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.) == 0 { |
| 1079 | score++ // Favor entry nodes |
| 1080 | } else { |
| 1081 | score += edgeEntropyScorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeEntropyScore().(n, n.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In., 0) |
| 1082 | } |
| 1083 | |
| 1084 | if len(n.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.) == 0 { |
| 1085 | score++ // Favor leaf nodes |
| 1086 | } else { |
| 1087 | score += edgeEntropyScorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeEntropyScore().(n, n.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out., n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.) |
| 1088 | } |
| 1089 | |
| 1090 | return int64(score*float64(n.Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.)) + n.Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. |
| 1091 | } |
| 1092 | |
| 1093 | // edgeEntropyScore computes the entropy value for a set of edges |
| 1094 | // coming in or out of a node. Entropy (as defined in information |
| 1095 | // theory) refers to the amount of information encoded by the set of |
| 1096 | // edges. A set of edges that have a more interesting distribution of |
| 1097 | // samples gets a higher score. |
| 1098 | func edgeEntropyScorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeEntropyScore().(n *Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#, edges EdgeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap#, self int64) float64 { |
| 1099 | score := float64(0) |
| 1100 | total := self |
| 1101 | for _, e := range edges { |
| 1102 | if e.Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight. > 0 { |
| 1103 | total += abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(e.Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight.) |
| 1104 | } |
| 1105 | } |
| 1106 | if total != 0 { |
| 1107 | for _, e := range edges { |
| 1108 | frac := float64(abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(e.Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight.)) / float64(total) |
| 1109 | score += -frac * mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Log2scip-go gomod github.com/golang/go/src go1.24.0 math/Log2().(frac) |
| 1110 | } |
| 1111 | if self > 0 { |
| 1112 | frac := float64(abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(self)) / float64(total) |
| 1113 | score += -frac * mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Log2scip-go gomod github.com/golang/go/src go1.24.0 math/Log2().(frac) |
| 1114 | } |
| 1115 | } |
| 1116 | return score |
| 1117 | } |
| 1118 | |
| 1119 | // NodeOrder sets the ordering for a Sort operation |
| 1120 | type NodeOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeOrder# int |
| 1121 | |
| 1122 | // Sorting options for node sort. |
| 1123 | const ( |
| 1124 | FlatNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/FlatNameOrder. NodeOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeOrder# = iota |
| 1125 | FlatCumNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/FlatCumNameOrder. |
| 1126 | CumNameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/CumNameOrder. |
| 1127 | NameOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NameOrder. |
| 1128 | FileOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/FileOrder. |
| 1129 | AddressOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/AddressOrder. |
| 1130 | EntropyOrderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EntropyOrder. |
| 1131 | ) |
| 1132 | |
| 1133 | // Sort returns a slice of the edges in the map, in a consistent |
| 1134 | // order. The sort order is first based on the edge weight |
| 1135 | // (higher-to-lower) and then by the node names to avoid flakiness. |
| 1136 | func (e EdgeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap#) Sortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap#Sort().() []*Edgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge# { |
| 1137 | el := make(edgeListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeList#, 0, len(e)) |
| 1138 | for _, w := range e { |
| 1139 | el = append(el, w) |
| 1140 | } |
| 1141 | |
| 1142 | sortscip-go gomod github.com/golang/go/src go1.24.0 sort/.Sortscip-go gomod github.com/golang/go/src go1.24.0 sort/Sort().(el) |
| 1143 | return el |
| 1144 | } |
| 1145 | |
| 1146 | // Sum returns the total weight for a set of nodes. |
| 1147 | func (e EdgeMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap#) Sumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/EdgeMap#Sum().() int64 { |
| 1148 | var ret int64 |
| 1149 | for _, edge := range e { |
| 1150 | ret += edge.Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight. |
| 1151 | } |
| 1152 | return ret |
| 1153 | } |
| 1154 | |
| 1155 | type edgeListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeList# []*Edgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge# |
| 1156 | |
| 1157 | func (el edgeListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeList#) Lenscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeList#Len().() int { |
| 1158 | return len(el) |
| 1159 | } |
| 1160 | |
| 1161 | func (el edgeListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeList#) Lessscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeList#Less().(i, j int) bool { |
| 1162 | if el[i].Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight. != el[j].Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight. { |
| 1163 | return abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(el[i].Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight.) > abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(el[j].Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight.) |
| 1164 | } |
| 1165 | |
| 1166 | from1 := el[i].Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src..Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..PrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#PrintableName().() |
| 1167 | from2 := el[j].Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src..Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..PrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#PrintableName().() |
| 1168 | if from1 != from2 { |
| 1169 | return from1 < from2 |
| 1170 | } |
| 1171 | |
| 1172 | to1 := el[i].Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest..Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..PrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#PrintableName().() |
| 1173 | to2 := el[j].Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest..Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..PrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#PrintableName().() |
| 1174 | |
| 1175 | return to1 < to2 |
| 1176 | } |
| 1177 | |
| 1178 | func (el edgeListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeList#) Swapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/edgeList#Swap().(i, j int) { |
| 1179 | el[i], el[j] = el[j], el[i] |
| 1180 | } |
| 1181 | |
| 1182 | func abs64scip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/abs64().(i int64) int64 { |
| 1183 | if i < 0 { |
| 1184 | return -i |
| 1185 | } |
| 1186 | return i |
| 1187 | } |