瀏覽代碼

Allow trees to trim to the top Nodes by NodeInfo

In a graph, NodeInfo maps one to one to the nodes, so it suffices to
just find the top NodeInfo s and only keep those nodes in the graph. In
a tree however, a single NodeInfo may map to many nodes. As of this
commit, a call to 'web 10' in pprof on a tree will return all the nodes
corresponding with the top 10 NodeInfo s.
Wade Simba Khadder 8 年之前
父節點
當前提交
bee282c062
共有 2 個檔案被更改,包括 3 行新增4 行删除
  1. 1
    2
      internal/graph/graph.go
  2. 2
    2
      internal/report/report.go

+ 1
- 2
internal/graph/graph.go 查看文件

@@ -288,7 +288,6 @@ func newTree(prof *profile.Profile, o *Options) (g *Graph) {
288 288
 	kept := o.KeptNodes
289 289
 	keepBinary := o.ObjNames
290 290
 	parentNodeMap := make(map[*Node]NodeMap, len(prof.Sample))
291
-nextSample:
292 291
 	for _, sample := range prof.Sample {
293 292
 		weight := o.SampleValue(sample.Value)
294 293
 		if weight == 0 {
@@ -311,7 +310,7 @@ nextSample:
311 310
 				}
312 311
 				n := nodeMap.findOrInsertLine(l, lines[lidx], keepBinary, kept)
313 312
 				if n == nil {
314
-					continue nextSample
313
+					continue
315 314
 				}
316 315
 				n.addSample(weight, labels, sample.NumLabel, o.FormatTag, false)
317 316
 				if parent != nil {

+ 2
- 2
internal/report/report.go 查看文件

@@ -84,11 +84,11 @@ func (rpt *Report) newTrimmedGraph() (g *graph.Graph, origCount, droppedNodes, d
84 84
 	nodeCutoff := abs64(int64(float64(totalValue) * o.NodeFraction))
85 85
 	edgeCutoff := abs64(int64(float64(totalValue) * o.EdgeFraction))
86 86
 
87
-	// Visual mode optimization only supports graph output, not tree.
88 87
 	// Do not apply edge cutoff to preserve tree structure.
89 88
 	if o.CallTree {
90
-		visualMode = false
91 89
 		if o.OutputFormat == Dot {
90
+			fmt.Println("WARNING: Trimming trees is unsupported.")
91
+			fmt.Printf("Tree will contain at least %d nodes\n", o.NodeCount)
92 92
 			cumSort = true
93 93
 		}
94 94
 		edgeCutoff = 0