diff options
| author | Alberto Donizetti <alb.donizetti@gmail.com> | 2017-06-20 17:40:21 +0200 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-06-20 18:31:06 +0000 |
| commit | 3d13b5e00c9bc065d83e27d787a64adc683cea02 (patch) | |
| tree | 60f71d89af63a6ee45cc73e79336c271511c5883 /src/cmd/vendor/github.com/google/pprof/internal/graph | |
| parent | dc8b4e65a7a68e102484020efbf80cecd2d515bd (diff) | |
| download | go-3d13b5e00c9bc065d83e27d787a64adc683cea02.tar.xz | |
cmd/vendor/github.com/google/pprof: refresh from upstream
Updating to commit fffc5831a499a958516664a34cb7ba2b9e228793
from github.com/google/pprof
Fixes #19380
Change-Id: I7a0c64101f42b494c4a469c41628374272eccf95
Reviewed-on: https://go-review.googlesource.com/46155
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd/vendor/github.com/google/pprof/internal/graph')
3 files changed, 70 insertions, 22 deletions
diff --git a/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph.go b/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph.go index c99e8992de..514156a184 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph.go @@ -50,7 +50,9 @@ type DotConfig struct { Total int64 // The total weight of the graph, used to compute percentages } -// Compose creates and writes a in the DOT format to the writer, using +const maxNodelets = 4 // Number of nodelets for labels (both numeric and non) + +// ComposeDot creates and writes a in the DOT format to the writer, using // the configurations given. func ComposeDot(w io.Writer, g *Graph, a *DotAttributes, c *DotConfig) { builder := &builder{w, a, c} @@ -204,13 +206,11 @@ func (b *builder) addNode(node *Node, nodeID int, maxFlat float64) { // addNodelets generates the DOT boxes for the node tags if they exist. func (b *builder) addNodelets(node *Node, nodeID int) bool { - const maxNodelets = 4 // Number of nodelets for alphanumeric labels - const maxNumNodelets = 4 // Number of nodelets for numeric labels var nodelets string // Populate two Tag slices, one for LabelTags and one for NumericTags. var ts []*Tag - lnts := make(map[string][]*Tag, 0) + lnts := make(map[string][]*Tag) for _, t := range node.LabelTags { ts = append(ts, t) } @@ -242,12 +242,12 @@ func (b *builder) addNodelets(node *Node, nodeID int) bool { nodelets += fmt.Sprintf(`N%d_%d [label = "%s" fontsize=8 shape=box3d tooltip="%s"]`+"\n", nodeID, i, t.Name, weight) nodelets += fmt.Sprintf(`N%d -> N%d_%d [label=" %s" weight=100 tooltip="%s" labeltooltip="%s"]`+"\n", nodeID, nodeID, i, weight, weight, weight) if nts := lnts[t.Name]; nts != nil { - nodelets += b.numericNodelets(nts, maxNumNodelets, flatTags, fmt.Sprintf(`N%d_%d`, nodeID, i)) + nodelets += b.numericNodelets(nts, maxNodelets, flatTags, fmt.Sprintf(`N%d_%d`, nodeID, i)) } } if nts := lnts[""]; nts != nil { - nodelets += b.numericNodelets(nts, maxNumNodelets, flatTags, fmt.Sprintf(`N%d`, nodeID)) + nodelets += b.numericNodelets(nts, maxNodelets, flatTags, fmt.Sprintf(`N%d`, nodeID)) } fmt.Fprint(b, nodelets) diff --git a/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph_test.go b/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph_test.go index 7f51269769..c9d4bca5de 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph_test.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph_test.go @@ -209,6 +209,59 @@ func compareGraphs(t *testing.T, got, want []byte) { } } +func TestNodeletCountCapping(t *testing.T) { + labelTags := make(TagMap) + for i := 0; i < 10; i++ { + name := fmt.Sprintf("tag-%d", i) + labelTags[name] = &Tag{ + Name: name, + Flat: 10, + Cum: 10, + } + } + numTags := make(TagMap) + for i := 0; i < 10; i++ { + name := fmt.Sprintf("num-tag-%d", i) + numTags[name] = &Tag{ + Name: name, + Unit: "mb", + Value: 16, + Flat: 10, + Cum: 10, + } + } + node1 := &Node{ + Info: NodeInfo{Name: "node1-with-tags"}, + Flat: 10, + Cum: 10, + NumericTags: map[string]TagMap{"": numTags}, + LabelTags: labelTags, + } + node2 := &Node{ + Info: NodeInfo{Name: "node2"}, + Flat: 15, + Cum: 15, + } + node3 := &Node{ + Info: NodeInfo{Name: "node3"}, + Flat: 15, + Cum: 15, + } + g := &Graph{ + Nodes: Nodes{ + node1, + node2, + node3, + }, + } + for n := 1; n <= 3; n++ { + input := maxNodelets + n + if got, want := len(g.SelectTopNodes(input, true)), n; got != want { + t.Errorf("SelectTopNodes(%d): got %d nodes, want %d", input, got, want) + } + } +} + func TestMultilinePrintableName(t *testing.T) { ni := &NodeInfo{ Name: "test1.test2::test3", @@ -240,19 +293,19 @@ func TestTagCollapse(t *testing.T) { } tagWant := [][]*Tag{ - []*Tag{ + { makeTag("1B..2GB", "", 0, 2401, 2401), }, - []*Tag{ + { makeTag("2GB", "", 0, 1000, 1000), makeTag("1B..12MB", "", 0, 1401, 1401), }, - []*Tag{ + { makeTag("2GB", "", 0, 1000, 1000), makeTag("12MB", "", 0, 100, 100), makeTag("1B..1MB", "", 0, 1301, 1301), }, - []*Tag{ + { makeTag("2GB", "", 0, 1000, 1000), makeTag("1MB", "", 0, 1000, 1000), makeTag("2B..1kB", "", 0, 201, 201), diff --git a/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go b/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go index 428e6257c7..7947e2dd42 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go @@ -240,6 +240,8 @@ type Edge struct { Inline bool } +// WeightValue returns the weight value for this edge, normalizing if a +// divisor is available. func (e *Edge) WeightValue() int64 { if e.WeightDiv == 0 { return e.Weight @@ -800,7 +802,11 @@ func (g *Graph) selectTopNodes(maxNodes int, visualMode bool) Nodes { // If generating a visual graph, count tags as nodes. Update // maxNodes to account for them. for i, n := range g.Nodes { - if count += countTags(n) + 1; count >= maxNodes { + tags := countTags(n) + if tags > maxNodelets { + tags = maxNodelets + } + if count += tags + 1; count >= maxNodes { maxNodes = i + 1 break } @@ -832,17 +838,6 @@ func countTags(n *Node) int { return count } -// countEdges counts the number of edges below the specified cutoff. -func countEdges(el EdgeMap, cutoff int64) int { - count := 0 - for _, e := range el { - if e.Weight > cutoff { - count++ - } - } - return count -} - // RemoveRedundantEdges removes residual edges if the destination can // be reached through another path. This is done to simplify the graph // while preserving connectivity. |
