Переглянути джерело

Merge pull request #105 from rauls5382/calltree

Do not honor call_tree option when generating non-visual reports.
Raul Silvera 8 роки тому
джерело
коміт
a73f05e803

+ 4
- 1
internal/driver/driver_test.go Переглянути файл

@@ -49,7 +49,7 @@ func TestParse(t *testing.T) {
49 49
 	}{
50 50
 		{"text,functions,flat", "cpu"},
51 51
 		{"tree,addresses,flat,nodecount=4", "cpusmall"},
52
-		{"text,functions,flat", "unknown"},
52
+		{"text,functions,flat,nodecount=5,call_tree", "unknown"},
53 53
 		{"text,alloc_objects,flat", "heap_alloc"},
54 54
 		{"text,files,flat", "heap"},
55 55
 		{"text,inuse_objects,flat", "heap"},
@@ -59,8 +59,10 @@ func TestParse(t *testing.T) {
59 59
 		{"tree,lines,cum,focus=[24]00", "heap"},
60 60
 		{"tree,relative_percentages,cum,focus=[24]00", "heap"},
61 61
 		{"callgrind", "cpu"},
62
+		{"callgrind,call_tree", "cpu"},
62 63
 		{"callgrind", "heap"},
63 64
 		{"dot,functions,flat", "cpu"},
65
+		{"dot,functions,flat,call_tree", "cpu"},
64 66
 		{"dot,lines,flat,focus=[12]00", "heap"},
65 67
 		{"dot,addresses,flat,ignore=[X3]002,focus=[X1]000", "contention"},
66 68
 		{"dot,files,cum", "contention"},
@@ -222,6 +224,7 @@ func solutionFilename(source string, f *testFlags) string {
222 224
 	name = addString(name, f, []string{"inuse_space", "inuse_objects", "alloc_space", "alloc_objects"})
223 225
 	name = addString(name, f, []string{"relative_percentages"})
224 226
 	name = addString(name, f, []string{"seconds"})
227
+	name = addString(name, f, []string{"call_tree"})
225 228
 	name = addString(name, f, []string{"text", "tree", "callgrind", "dot", "svg", "tags", "dot", "traces", "disasm", "peek", "weblist", "topproto", "comments"})
226 229
 	if f.strings["focus"] != "" || f.strings["tagfocus"] != "" {
227 230
 		name = append(name, "focus")

+ 99
- 0
internal/driver/testdata/pprof.cpu.call_tree.callgrind Переглянути файл

@@ -0,0 +1,99 @@
1
+positions: instr line
2
+events: cpu(ms)
3
+
4
+ob=(1) /path/to/testbinary
5
+fl=(1) testdata/file1000.src
6
+fn=(1) line1000
7
+0x1000 1 1000
8
+* 1 100
9
+
10
+ob=(1)
11
+fl=(2) testdata/file2000.src
12
+fn=(2) line2001
13
++4096 9 10
14
+
15
+ob=(1)
16
+fl=(3) testdata/file3000.src
17
+fn=(3) line3002
18
++4096 2 10
19
+cfl=(2)
20
+cfn=(4) line2000 [1/2]
21
+calls=0 * 4
22
+* * 1000
23
+
24
+ob=(1)
25
+fl=(2)
26
+fn=(5) line2000
27
+-4096 4 0
28
+cfl=(2)
29
+cfn=(6) line2001 [2/2]
30
+calls=0 -4096 9
31
+* * 1000
32
+* 4 0
33
+cfl=(2)
34
+cfn=(7) line2001 [1/2]
35
+calls=0 * 9
36
+* * 10
37
+
38
+ob=(1)
39
+fl=(2)
40
+fn=(2)
41
+* 9 0
42
+cfl=(1)
43
+cfn=(8) line1000 [1/2]
44
+calls=0 -4096 1
45
+* * 1000
46
+
47
+ob=(1)
48
+fl=(3)
49
+fn=(9) line3000
50
++4096 6 0
51
+cfl=(3)
52
+cfn=(10) line3001 [1/2]
53
+calls=0 +4096 5
54
+* * 1010
55
+
56
+ob=(1)
57
+fl=(3)
58
+fn=(11) line3001
59
+* 5 0
60
+cfl=(3)
61
+cfn=(12) line3002 [1/2]
62
+calls=0 * 2
63
+* * 1010
64
+
65
+ob=(1)
66
+fl=(3)
67
+fn=(9)
68
++1 9 0
69
+cfl=(3)
70
+cfn=(13) line3001 [2/2]
71
+calls=0 +1 8
72
+* * 100
73
+
74
+ob=(1)
75
+fl=(3)
76
+fn=(11)
77
+* 8 0
78
+cfl=(1)
79
+cfn=(14) line1000 [2/2]
80
+calls=0 -8193 1
81
+* * 100
82
+
83
+ob=(1)
84
+fl=(3)
85
+fn=(9)
86
++1 9 0
87
+cfl=(3)
88
+cfn=(15) line3002 [2/2]
89
+calls=0 +1 5
90
+* * 10
91
+
92
+ob=(1)
93
+fl=(3)
94
+fn=(3)
95
+* 5 0
96
+cfl=(2)
97
+cfn=(16) line2000 [2/2]
98
+calls=0 -4098 4
99
+* * 10

+ 21
- 0
internal/driver/testdata/pprof.cpu.flat.functions.call_tree.dot Переглянути файл

@@ -0,0 +1,21 @@
1
+digraph "testbinary" {
2
+node [style=filled fillcolor="#f8f8f8"]
3
+subgraph cluster_L { "File: testbinary" [shape=box fontsize=16 label="File: testbinary\lType: cpu\lDuration: 10s, Total samples = 1.12s (11.20%)\lShowing nodes accounting for 1.11s, 99.11% of 1.12s total\lDropped 3 nodes (cum <= 0.06s)\l"] }
4
+N1 [label="line1000\nfile1000.src\n1s (89.29%)" fontsize=24 shape=box tooltip="line1000 testdata/file1000.src (1s)" color="#b20500" fillcolor="#edd6d5"]
5
+N1_0 [label = "key1:tag1\nkey2:tag1" fontsize=8 shape=box3d tooltip="1s"]
6
+N1 -> N1_0 [label=" 1s" weight=100 tooltip="1s" labeltooltip="1s"]
7
+N2 [label="line3000\nfile3000.src\n0 of 1.12s (100%)" fontsize=8 shape=box tooltip="line3000 testdata/file3000.src (1.12s)" color="#b20000" fillcolor="#edd5d5"]
8
+N3 [label="line3001\nfile3000.src\n0 of 1.11s (99.11%)" fontsize=8 shape=box tooltip="line3001 testdata/file3000.src (1.11s)" color="#b20000" fillcolor="#edd5d5"]
9
+N4 [label="line1000\nfile1000.src\n0.10s (8.93%)" fontsize=14 shape=box tooltip="line1000 testdata/file1000.src (0.10s)" color="#b28b62" fillcolor="#ede8e2"]
10
+N4_0 [label = "key1:tag2\nkey3:tag2" fontsize=8 shape=box3d tooltip="0.10s"]
11
+N4 -> N4_0 [label=" 0.10s" weight=100 tooltip="0.10s" labeltooltip="0.10s"]
12
+N5 [label="line3002\nfile3000.src\n0.01s (0.89%)\nof 1.01s (90.18%)" fontsize=10 shape=box tooltip="line3002 testdata/file3000.src (1.01s)" color="#b20500" fillcolor="#edd6d5"]
13
+N6 [label="line2000\nfile2000.src\n0 of 1s (89.29%)" fontsize=8 shape=box tooltip="line2000 testdata/file2000.src (1s)" color="#b20500" fillcolor="#edd6d5"]
14
+N7 [label="line2001\nfile2000.src\n0 of 1s (89.29%)" fontsize=8 shape=box tooltip="line2001 testdata/file2000.src (1s)" color="#b20500" fillcolor="#edd6d5"]
15
+N2 -> N3 [label=" 1.11s\n (inline)" weight=100 penwidth=5 color="#b20000" tooltip="line3000 testdata/file3000.src -> line3001 testdata/file3000.src (1.11s)" labeltooltip="line3000 testdata/file3000.src -> line3001 testdata/file3000.src (1.11s)"]
16
+N3 -> N5 [label=" 1.01s\n (inline)" weight=91 penwidth=5 color="#b20500" tooltip="line3001 testdata/file3000.src -> line3002 testdata/file3000.src (1.01s)" labeltooltip="line3001 testdata/file3000.src -> line3002 testdata/file3000.src (1.01s)"]
17
+N6 -> N7 [label=" 1s\n (inline)" weight=90 penwidth=5 color="#b20500" tooltip="line2000 testdata/file2000.src -> line2001 testdata/file2000.src (1s)" labeltooltip="line2000 testdata/file2000.src -> line2001 testdata/file2000.src (1s)"]
18
+N7 -> N1 [label=" 1s" weight=90 penwidth=5 color="#b20500" tooltip="line2001 testdata/file2000.src -> line1000 testdata/file1000.src (1s)" labeltooltip="line2001 testdata/file2000.src -> line1000 testdata/file1000.src (1s)"]
19
+N5 -> N6 [label=" 1s" weight=90 penwidth=5 color="#b20500" tooltip="line3002 testdata/file3000.src -> line2000 testdata/file2000.src (1s)" labeltooltip="line3002 testdata/file3000.src -> line2000 testdata/file2000.src (1s)"]
20
+N3 -> N4 [label=" 0.10s" weight=9 color="#b28b62" tooltip="line3001 testdata/file3000.src -> line1000 testdata/file1000.src (0.10s)" labeltooltip="line3001 testdata/file3000.src -> line1000 testdata/file1000.src (0.10s)"]
21
+}

internal/driver/testdata/pprof.unknown.flat.functions.text → internal/driver/testdata/pprof.unknown.flat.functions.call_tree.text Переглянути файл

@@ -1,8 +1,8 @@
1 1
 Showing nodes accounting for 1.12s, 100% of 1.12s total
2
+Showing top 5 nodes out of 6
2 3
       flat  flat%   sum%        cum   cum%
3 4
      1.10s 98.21% 98.21%      1.10s 98.21%  line1000 testdata/file1000.src
4 5
      0.01s  0.89% 99.11%      1.01s 90.18%  line2001 testdata/file2000.src (inline)
5 6
      0.01s  0.89%   100%      1.02s 91.07%  line3002 testdata/file3000.src (inline)
6 7
          0     0%   100%      1.01s 90.18%  line2000 testdata/file2000.src
7 8
          0     0%   100%      1.12s   100%  line3000 testdata/file3000.src
8
-         0     0%   100%      1.11s 99.11%  line3001 testdata/file3000.src (inline)

+ 5
- 2
internal/report/report.go Переглянути файл

@@ -125,6 +125,9 @@ func (rpt *Report) newTrimmedGraph() (g *graph.Graph, origCount, droppedNodes, d
125 125
 	visualMode := o.OutputFormat == Dot
126 126
 	cumSort := o.CumSort
127 127
 
128
+	// The call_tree option is only honored when generating visual representations of the callgraph.
129
+	callTree := o.CallTree && (o.OutputFormat == Dot || o.OutputFormat == Callgrind)
130
+
128 131
 	// First step: Build complete graph to identify low frequency nodes, based on their cum weight.
129 132
 	g = rpt.newGraph(nil)
130 133
 	totalValue, _ := g.Nodes.Sum()
@@ -133,7 +136,7 @@ func (rpt *Report) newTrimmedGraph() (g *graph.Graph, origCount, droppedNodes, d
133 136
 
134 137
 	// Filter out nodes with cum value below nodeCutoff.
135 138
 	if nodeCutoff > 0 {
136
-		if o.CallTree {
139
+		if callTree {
137 140
 			if nodesKept := g.DiscardLowFrequencyNodePtrs(nodeCutoff); len(g.Nodes) != len(nodesKept) {
138 141
 				droppedNodes = len(g.Nodes) - len(nodesKept)
139 142
 				g.TrimTree(nodesKept)
@@ -154,7 +157,7 @@ func (rpt *Report) newTrimmedGraph() (g *graph.Graph, origCount, droppedNodes, d
154 157
 		// Remove low frequency tags and edges as they affect selection.
155 158
 		g.TrimLowFrequencyTags(nodeCutoff)
156 159
 		g.TrimLowFrequencyEdges(edgeCutoff)
157
-		if o.CallTree {
160
+		if callTree {
158 161
 			if nodesKept := g.SelectTopNodePtrs(nodeCount, visualMode); len(g.Nodes) != len(nodesKept) {
159 162
 				g.TrimTree(nodesKept)
160 163
 				g.SortNodes(cumSort, visualMode)