浏览代码

Mark inlined frames as such in the traces report. (#510)

Alexey Alexandrov 5 年前
父节点
当前提交
d9cc46808a
没有帐户链接到提交者的电子邮件

+ 1
- 0
internal/driver/driver_test.go 查看文件

@@ -86,6 +86,7 @@ func TestParse(t *testing.T) {
86 86
 		{"tags", "heap"},
87 87
 		{"tags,unit=bytes", "heap"},
88 88
 		{"traces", "cpu"},
89
+		{"traces,addresses", "cpu"},
89 90
 		{"traces", "heap_tags"},
90 91
 		{"dot,alloc_space,flat,focus=[234]00", "heap_alloc"},
91 92
 		{"dot,alloc_space,flat,tagshow=[2]00", "heap_alloc"},

+ 32
- 0
internal/driver/testdata/pprof.cpu.addresses.traces 查看文件

@@ -0,0 +1,32 @@
1
+File: testbinary
2
+Type: cpu
3
+Duration: 10s, Total samples = 1.12s (11.20%)
4
+-----------+-------------------------------------------------------
5
+      key1:  tag1
6
+      key2:  tag1
7
+        1s   0000000000001000 line1000 testdata/file1000.src:1
8
+             0000000000002000 line2001 testdata/file2000.src:9 (inline)
9
+             0000000000002000 line2000 testdata/file2000.src:4
10
+             0000000000003000 line3002 testdata/file3000.src:2 (inline)
11
+             0000000000003000 line3001 testdata/file3000.src:5 (inline)
12
+             0000000000003000 line3000 testdata/file3000.src:6
13
+-----------+-------------------------------------------------------
14
+      key1:  tag2
15
+      key3:  tag2
16
+     100ms   0000000000001000 line1000 testdata/file1000.src:1
17
+             0000000000003001 line3001 testdata/file3000.src:8 (inline)
18
+             0000000000003001 line3000 testdata/file3000.src:9
19
+-----------+-------------------------------------------------------
20
+      key1:  tag3
21
+      key2:  tag2
22
+      10ms   0000000000002000 line2001 testdata/file2000.src:9 (inline)
23
+             0000000000002000 line2000 testdata/file2000.src:4
24
+             0000000000003002 line3002 testdata/file3000.src:5 (inline)
25
+             0000000000003002 line3000 testdata/file3000.src:9
26
+-----------+-------------------------------------------------------
27
+      key1:  tag4
28
+      key2:  tag1
29
+      10ms   0000000000003000 line3002 testdata/file3000.src:2 (inline)
30
+             0000000000003000 line3001 testdata/file3000.src:5 (inline)
31
+             0000000000003000 line3000 testdata/file3000.src:6
32
+-----------+-------------------------------------------------------

+ 8
- 8
internal/driver/testdata/pprof.cpu.traces 查看文件

@@ -5,28 +5,28 @@ Duration: 10s, Total samples = 1.12s (11.20%)
5 5
       key1:  tag1
6 6
       key2:  tag1
7 7
         1s   line1000
8
-             line2001
8
+             line2001 (inline)
9 9
              line2000
10
-             line3002
11
-             line3001
10
+             line3002 (inline)
11
+             line3001 (inline)
12 12
              line3000
13 13
 -----------+-------------------------------------------------------
14 14
       key1:  tag2
15 15
       key3:  tag2
16 16
      100ms   line1000
17
-             line3001
17
+             line3001 (inline)
18 18
              line3000
19 19
 -----------+-------------------------------------------------------
20 20
       key1:  tag3
21 21
       key2:  tag2
22
-      10ms   line2001
22
+      10ms   line2001 (inline)
23 23
              line2000
24
-             line3002
24
+             line3002 (inline)
25 25
              line3000
26 26
 -----------+-------------------------------------------------------
27 27
       key1:  tag4
28 28
       key2:  tag1
29
-      10ms   line3002
30
-             line3001
29
+      10ms   line3002 (inline)
30
+             line3001 (inline)
31 31
              line3000
32 32
 -----------+-------------------------------------------------------

+ 8
- 8
internal/driver/testdata/pprof.heap_tags.traces 查看文件

@@ -6,27 +6,27 @@ Type: inuse_space
6 6
      bytes:  100kB
7 7
    request:  100kB
8 8
     1000kB   line1000
9
-             line2001
9
+             line2001 (inline)
10 10
              line2000
11
-             line3002
12
-             line3001
11
+             line3002 (inline)
12
+             line3001 (inline)
13 13
              line3000
14 14
 -----------+-------------------------------------------------------
15 15
      bytes:  200kB
16 16
     3.91MB   line1000
17
-             line3001
17
+             line3001 (inline)
18 18
              line3000
19 19
 -----------+-------------------------------------------------------
20 20
       key1:  tag
21 21
      bytes:  1.56MB
22 22
    request:  1.56MB
23
-   62.50MB   line2001
23
+   62.50MB   line2001 (inline)
24 24
              line2000
25
-             line3002
25
+             line3002 (inline)
26 26
              line3000
27 27
 -----------+-------------------------------------------------------
28 28
      bytes:  400kB
29
-   31.25MB   line3002
30
-             line3001
29
+   31.25MB   line3002 (inline)
30
+             line3001 (inline)
31 31
              line3000
32 32
 -----------+-------------------------------------------------------

+ 21
- 7
internal/report/report.go 查看文件

@@ -834,10 +834,19 @@ func printTraces(w io.Writer, rpt *Report) error {
834 834
 
835 835
 	_, locations := graph.CreateNodes(prof, &graph.Options{})
836 836
 	for _, sample := range prof.Sample {
837
-		var stack graph.Nodes
837
+		type stk struct {
838
+			*graph.NodeInfo
839
+			inline bool
840
+		}
841
+		var stack []stk
838 842
 		for _, loc := range sample.Location {
839
-			id := loc.ID
840
-			stack = append(stack, locations[id]...)
843
+			nodes := locations[loc.ID]
844
+			for i, n := range nodes {
845
+				// The inline flag may be inaccurate if 'show' or 'hide' filter is
846
+				// used. See https://github.com/google/pprof/issues/511.
847
+				inline := i != len(nodes)-1
848
+				stack = append(stack, stk{&n.Info, inline})
849
+			}
841 850
 		}
842 851
 
843 852
 		if len(stack) == 0 {
@@ -875,10 +884,15 @@ func printTraces(w io.Writer, rpt *Report) error {
875 884
 		if d != 0 {
876 885
 			v = v / d
877 886
 		}
878
-		fmt.Fprintf(w, "%10s   %s\n",
879
-			rpt.formatValue(v), stack[0].Info.PrintableName())
880
-		for _, s := range stack[1:] {
881
-			fmt.Fprintf(w, "%10s   %s\n", "", s.Info.PrintableName())
887
+		for i, s := range stack {
888
+			var vs, inline string
889
+			if i == 0 {
890
+				vs = rpt.formatValue(v)
891
+			}
892
+			if s.inline {
893
+				inline = " (inline)"
894
+			}
895
+			fmt.Fprintf(w, "%10s   %s%s\n", vs, s.PrintableName(), inline)
882 896
 		}
883 897
 	}
884 898
 	fmt.Fprintln(w, separator)