| 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 graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ |
| 16 | |
| 17 | import ( |
| 18 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 19 | "flagscip-go gomod github.com/golang/go/src go1.24.0 flag/" |
| 20 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 21 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 22 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 23 | "reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/" |
| 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 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 27 | |
| 28 | "github.com/google/pprof/internal/proftestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/proftest`/" |
| 29 | ) |
| 30 | |
| 31 | var updateFlagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/updateFlag. = flagscip-go gomod github.com/golang/go/src go1.24.0 flag/.Boolscip-go gomod github.com/golang/go/src go1.24.0 flag/Bool().("update", false, "Update the golden files") |
| 32 | |
| 33 | func TestComposeWithStandardGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestComposeWithStandardGraph().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 34 | g := baseGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseGraph().() |
| 35 | a, c := baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() |
| 36 | |
| 37 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 38 | ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(&buf, g, a, c) |
| 39 | |
| 40 | compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t, buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), "compose1.dot") |
| 41 | } |
| 42 | |
| 43 | func TestComposeWithNodeAttributesAndZeroFlatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestComposeWithNodeAttributesAndZeroFlat().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 44 | g := baseGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseGraph().() |
| 45 | a, c := baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() |
| 46 | |
| 47 | // Set NodeAttributes for Node 1. |
| 48 | a.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotAttributes#Nodes.[g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[0]] = &DotNodeAttributesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotNodeAttributes#{ |
| 49 | Shapescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotNodeAttributes#Shape.: "folder", |
| 50 | Boldscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotNodeAttributes#Bold.: true, |
| 51 | Peripheriesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotNodeAttributes#Peripheries.: 2, |
| 52 | URLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotNodeAttributes#URL.: "www.google.com", |
| 53 | Formatterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotNodeAttributes#Formatter.: func(ni *NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#) string { |
| 54 | return stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.24.0 strings/ToUpper().(ni.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.) |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | // Set Flat value to zero on Node 2. |
| 59 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[1].Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat. = 0 |
| 60 | |
| 61 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 62 | ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(&buf, g, a, c) |
| 63 | |
| 64 | compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t, buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), "compose2.dot") |
| 65 | } |
| 66 | |
| 67 | func TestComposeWithTagsAndResidualEdgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestComposeWithTagsAndResidualEdge().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 68 | g := baseGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseGraph().() |
| 69 | a, c := baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() |
| 70 | |
| 71 | // Add tags to Node 1. |
| 72 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[0].LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags.["a"] = &Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 73 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name.: "tag1", |
| 74 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.: 10, |
| 75 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.: 10, |
| 76 | } |
| 77 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[0].NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags.[""] = TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#{ |
| 78 | "b": &Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 79 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name.: "tag2", |
| 80 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.: 20, |
| 81 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.: 20, |
| 82 | Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Unit.: "ms", |
| 83 | }, |
| 84 | } |
| 85 | |
| 86 | // Set edge to be Residual. |
| 87 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[0].Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.[g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[1]].Residualscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Residual. = true |
| 88 | |
| 89 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 90 | ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(&buf, g, a, c) |
| 91 | |
| 92 | compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t, buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), "compose3.dot") |
| 93 | } |
| 94 | |
| 95 | func TestComposeWithNestedTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestComposeWithNestedTags().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 96 | g := baseGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseGraph().() |
| 97 | a, c := baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() |
| 98 | |
| 99 | // Add tags to Node 1. |
| 100 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[0].LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags.["tag1"] = &Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 101 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name.: "tag1", |
| 102 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.: 10, |
| 103 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.: 10, |
| 104 | } |
| 105 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[0].NumericTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#NumericTags.["tag1"] = TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#{ |
| 106 | "tag2": &Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 107 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name.: "tag2", |
| 108 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.: 20, |
| 109 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.: 20, |
| 110 | Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Unit.: "ms", |
| 111 | }, |
| 112 | } |
| 113 | |
| 114 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 115 | ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(&buf, g, a, c) |
| 116 | |
| 117 | compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t, buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), "compose5.dot") |
| 118 | } |
| 119 | |
| 120 | func TestComposeWithEmptyGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestComposeWithEmptyGraph().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 121 | g := &Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#{} |
| 122 | a, c := baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() |
| 123 | |
| 124 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 125 | ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(&buf, g, a, c) |
| 126 | |
| 127 | compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t, buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), "compose4.dot") |
| 128 | } |
| 129 | |
| 130 | func TestComposeWithStandardGraphAndURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestComposeWithStandardGraphAndURL().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 131 | g := baseGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseGraph().() |
| 132 | a, c := baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() |
| 133 | c.LegendURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#LegendURL. = "http://example.com" |
| 134 | |
| 135 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 136 | ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(&buf, g, a, c) |
| 137 | |
| 138 | compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t, buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), "compose6.dot") |
| 139 | } |
| 140 | |
| 141 | func TestComposeWithNamesThatNeedEscapingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestComposeWithNamesThatNeedEscaping().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 142 | g := baseGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseGraph().() |
| 143 | a, c := baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() |
| 144 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[0].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#{Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: `var"src"`} |
| 145 | g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes.[1].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#{Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: `var"#dest#"`} |
| 146 | |
| 147 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 148 | ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(&buf, g, a, c) |
| 149 | |
| 150 | compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t, buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), "compose7.dot") |
| 151 | } |
| 152 | |
| 153 | func TestComposeWithCommentsWithNewlinesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestComposeWithCommentsWithNewlines().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 154 | g := baseGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseGraph().() |
| 155 | a, c := baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() |
| 156 | // comments that could be added with the -add_comment command line tool |
| 157 | // the first label is used as the dot "node name"; the others are escaped as labels |
| 158 | c.Labelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#Labels. = []string{"comment line 1\ncomment line 2 \"unterminated double quote", `second comment "double quote"`} |
| 159 | |
| 160 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 161 | ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(&buf, g, a, c) |
| 162 | |
| 163 | compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t, buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), "compose9.dot") |
| 164 | } |
| 165 | |
| 166 | func baseGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseGraph().() *Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph# { |
| 167 | src := &Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#{ |
| 168 | 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#{Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: "src"}, |
| 169 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.: 10, |
| 170 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.: 25, |
| 171 | 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#), |
| 172 | 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#), |
| 173 | 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#), |
| 174 | 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#), |
| 175 | } |
| 176 | dest := &Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#{ |
| 177 | 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#{Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: "dest"}, |
| 178 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.: 15, |
| 179 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.: 25, |
| 180 | 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#), |
| 181 | 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#), |
| 182 | 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#), |
| 183 | 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#), |
| 184 | } |
| 185 | edge := &Edgescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#{ |
| 186 | Srcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Src.: src, |
| 187 | Destscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Dest.: dest, |
| 188 | Weightscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Edge#Weight.: 10, |
| 189 | } |
| 190 | src.Outscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Out.[dest] = edge |
| 191 | src.Inscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#In.[src] = edge |
| 192 | return &Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#{ |
| 193 | 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#{ |
| 194 | src, |
| 195 | dest, |
| 196 | }, |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | func baseAttrsAndConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/baseAttrsAndConfig().() (*DotAttributesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotAttributes#, *DotConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#) { |
| 201 | a := &DotAttributesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotAttributes#{ |
| 202 | Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotAttributes#Nodes.: make(map[*Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#]*DotNodeAttributesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotNodeAttributes#), |
| 203 | } |
| 204 | c := &DotConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#{ |
| 205 | Titlescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#Title.: "testtitle", |
| 206 | Labelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#Labels.: []string{"label1", "label2", `label3: "foo"`}, |
| 207 | Totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#Total.: 100, |
| 208 | FormatValuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#FormatValue.: func(v int64) string { |
| 209 | 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) |
| 210 | }, |
| 211 | } |
| 212 | return a, c |
| 213 | } |
| 214 | |
| 215 | func compareGraphsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/compareGraphs().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, got []byte, wantFile string) { |
| 216 | wantFile = filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Join().("testdata", wantFile) |
| 217 | want, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.24.0 os/ReadFile().(wantFile) |
| 218 | if err != nil { |
| 219 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("error reading test file %s: %v", wantFile, err) |
| 220 | } |
| 221 | |
| 222 | if string(got) != string(want) { |
| 223 | d, err := proftestscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/proftest`/.Diffscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/proftest`/Diff().(got, want) |
| 224 | if err != nil { |
| 225 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("error finding diff: %v", err) |
| 226 | } |
| 227 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("Compose incorrectly wrote %s", string(d)) |
| 228 | if *updateFlagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/updateFlag. { |
| 229 | err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.24.0 os/WriteFile().(wantFile, got, 0644) |
| 230 | if err != nil { |
| 231 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("failed to update the golden file %q: %v", wantFile, err) |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | func TestNodeletCountCappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestNodeletCountCapping().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 238 | labelTags := make(TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#) |
| 239 | for i := 0; i < 10; i++ { |
| 240 | 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().("tag-%d", i) |
| 241 | labelTags[name] = &Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 242 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name.: name, |
| 243 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.: 10, |
| 244 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.: 10, |
| 245 | } |
| 246 | } |
| 247 | numTags := make(TagMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TagMap#) |
| 248 | for i := 0; i < 10; i++ { |
| 249 | 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().("num-tag-%d", i) |
| 250 | numTags[name] = &Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 251 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Name.: name, |
| 252 | Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Unit.: "mb", |
| 253 | Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Value.: 16, |
| 254 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Flat.: 10, |
| 255 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#Cum.: 10, |
| 256 | } |
| 257 | } |
| 258 | node1 := &Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#{ |
| 259 | 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#{Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: "node1-with-tags"}, |
| 260 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.: 10, |
| 261 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.: 10, |
| 262 | 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#{"": numTags}, |
| 263 | LabelTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#LabelTags.: labelTags, |
| 264 | } |
| 265 | node2 := &Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#{ |
| 266 | 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#{Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: "node2"}, |
| 267 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.: 15, |
| 268 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.: 15, |
| 269 | } |
| 270 | node3 := &Nodescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#{ |
| 271 | 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#{Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: "node3"}, |
| 272 | Flatscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Flat.: 15, |
| 273 | Cumscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Cum.: 15, |
| 274 | } |
| 275 | g := &Graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#{ |
| 276 | 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#{ |
| 277 | node1, |
| 278 | node2, |
| 279 | node3, |
| 280 | }, |
| 281 | } |
| 282 | for n := 1; n <= 3; n++ { |
| 283 | input := maxNodeletsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/maxNodelets. + n |
| 284 | if got, want := len(g.SelectTopNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#SelectTopNodes().(input, true)), n; got != want { |
| 285 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("SelectTopNodes(%d): got %d nodes, want %d", input, got, want) |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | func TestMultilinePrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestMultilinePrintableName().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 291 | ni := &NodeInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#{ |
| 292 | Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.: "test1.test2::test3", |
| 293 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#File.: "src/file.cc", |
| 294 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Address.: 123, |
| 295 | Linenoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Lineno.: 999, |
| 296 | } |
| 297 | |
| 298 | want := 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\ntest1\ntest2\ntest3\nfile.cc:999\n`, 123) |
| 299 | if got := multilinePrintableNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/multilinePrintableName().(ni); got != want { |
| 300 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("multilinePrintableName(%#v) == %q, want %q", ni, got, want) |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | func TestTagCollapsescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestTagCollapse().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 305 | |
| 306 | makeTag := func(name, unit string, value, flat, cum int64) *Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag# { |
| 307 | return &Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{name, unit, value, flat, 0, cum, 0} |
| 308 | } |
| 309 | |
| 310 | tagSource := []*Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 311 | makeTag("12mb", "mb", 12, 100, 100), |
| 312 | makeTag("1kb", "kb", 1, 1, 1), |
| 313 | makeTag("1mb", "mb", 1, 1000, 1000), |
| 314 | makeTag("2048mb", "mb", 2048, 1000, 1000), |
| 315 | makeTag("1b", "b", 1, 100, 100), |
| 316 | makeTag("2b", "b", 2, 100, 100), |
| 317 | makeTag("7b", "b", 7, 100, 100), |
| 318 | } |
| 319 | |
| 320 | tagWant := [][]*Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#{ |
| 321 | { |
| 322 | makeTag("1B..2GB", "", 0, 2401, 2401), |
| 323 | }, |
| 324 | { |
| 325 | makeTag("2GB", "", 0, 1000, 1000), |
| 326 | makeTag("1B..12MB", "", 0, 1401, 1401), |
| 327 | }, |
| 328 | { |
| 329 | makeTag("2GB", "", 0, 1000, 1000), |
| 330 | makeTag("12MB", "", 0, 100, 100), |
| 331 | makeTag("1B..1MB", "", 0, 1301, 1301), |
| 332 | }, |
| 333 | { |
| 334 | makeTag("2GB", "", 0, 1000, 1000), |
| 335 | makeTag("1MB", "", 0, 1000, 1000), |
| 336 | makeTag("2B..1kB", "", 0, 201, 201), |
| 337 | makeTag("1B", "", 0, 100, 100), |
| 338 | makeTag("12MB", "", 0, 100, 100), |
| 339 | }, |
| 340 | } |
| 341 | |
| 342 | for _, tc := range tagWant { |
| 343 | var got, want []*Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag# |
| 344 | b := builderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/builder#{nil, &DotAttributesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotAttributes#{}, &DotConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#{}} |
| 345 | got = b.collapsedTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/builder#collapsedTags().(tagSource, len(tc), true) |
| 346 | want = SortTagsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/SortTags().(tc, true) |
| 347 | |
| 348 | if !reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.24.0 reflect/DeepEqual().(got, want) { |
| 349 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("collapse to %d, got:\n%v\nwant:\n%v", len(tc), tagStringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tagString().(got), tagStringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tagString().(want)) |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | func TestEscapeForDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/TestEscapeForDot().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 355 | for _, tc := range []struct { |
| 356 | desc string |
| 357 | input []string |
| 358 | want []string |
| 359 | }{ |
| 360 | { |
| 361 | desc: "with multiple doubles quotes", |
| 362 | input: []string{`label: "foo" and "bar"`}, |
| 363 | want: []string{`label: \"foo\" and \"bar\"`}, |
| 364 | }, |
| 365 | { |
| 366 | desc: "with graphviz center line character", |
| 367 | input: []string{"label: foo \n bar"}, |
| 368 | want: []string{`label: foo \l bar`}, |
| 369 | }, |
| 370 | { |
| 371 | desc: "with two backslashes", |
| 372 | input: []string{`label: \\`}, |
| 373 | want: []string{`label: \\\\`}, |
| 374 | }, |
| 375 | { |
| 376 | desc: "with two double quotes together", |
| 377 | input: []string{`label: ""`}, |
| 378 | want: []string{`label: \"\"`}, |
| 379 | }, |
| 380 | { |
| 381 | desc: "with multiple labels", |
| 382 | input: []string{`label1: "foo"`, `label2: "bar"`}, |
| 383 | want: []string{`label1: \"foo\"`, `label2: \"bar\"`}, |
| 384 | }, |
| 385 | } { |
| 386 | t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 387 | if got := escapeAllForDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/escapeAllForDot().(tc.input); !reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.24.0 reflect/DeepEqual().(got, tc.want) { |
| 388 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("escapeAllForDot(%s) = %s, want %s", tc.input, got, tc.want) |
| 389 | } |
| 390 | }) |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | func tagStringscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/tagString().(t []*Tagscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Tag#) string { |
| 395 | var ret []string |
| 396 | for _, s := range t { |
| 397 | ret = append(ret, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintlnscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintln().(s)) |
| 398 | } |
| 399 | 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().(ret, ":") |
| 400 | } |