Skip to content

Commit 398b1a5

Browse files
committed
Mark inlined frames as such in the traces report.
1 parent f11f1df commit 398b1a5

File tree

5 files changed

+75
-23
lines changed

5 files changed

+75
-23
lines changed

internal/driver/driver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func TestParse(t *testing.T) {
8686
{"tags", "heap"},
8787
{"tags,unit=bytes", "heap"},
8888
{"traces", "cpu"},
89+
{"traces,addresses", "cpu"},
8990
{"traces", "heap_tags"},
9091
{"dot,alloc_space,flat,focus=[234]00", "heap_alloc"},
9192
{"dot,alloc_space,flat,tagshow=[2]00", "heap_alloc"},
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
-----------+-------------------------------------------------------

internal/driver/testdata/pprof.cpu.traces

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ Duration: 10s, Total samples = 1.12s (11.20%)
55
key1: tag1
66
key2: tag1
77
1s line1000
8-
line2001
8+
line2001 (inline)
99
line2000
10-
line3002
11-
line3001
10+
line3002 (inline)
11+
line3001 (inline)
1212
line3000
1313
-----------+-------------------------------------------------------
1414
key1: tag2
1515
key3: tag2
1616
100ms line1000
17-
line3001
17+
line3001 (inline)
1818
line3000
1919
-----------+-------------------------------------------------------
2020
key1: tag3
2121
key2: tag2
22-
10ms line2001
22+
10ms line2001 (inline)
2323
line2000
24-
line3002
24+
line3002 (inline)
2525
line3000
2626
-----------+-------------------------------------------------------
2727
key1: tag4
2828
key2: tag1
29-
10ms line3002
30-
line3001
29+
10ms line3002 (inline)
30+
line3001 (inline)
3131
line3000
3232
-----------+-------------------------------------------------------

internal/driver/testdata/pprof.heap_tags.traces

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ Type: inuse_space
66
bytes: 100kB
77
request: 100kB
88
1000kB line1000
9-
line2001
9+
line2001 (inline)
1010
line2000
11-
line3002
12-
line3001
11+
line3002 (inline)
12+
line3001 (inline)
1313
line3000
1414
-----------+-------------------------------------------------------
1515
bytes: 200kB
1616
3.91MB line1000
17-
line3001
17+
line3001 (inline)
1818
line3000
1919
-----------+-------------------------------------------------------
2020
key1: tag
2121
bytes: 1.56MB
2222
request: 1.56MB
23-
62.50MB line2001
23+
62.50MB line2001 (inline)
2424
line2000
25-
line3002
25+
line3002 (inline)
2626
line3000
2727
-----------+-------------------------------------------------------
2828
bytes: 400kB
29-
31.25MB line3002
30-
line3001
29+
31.25MB line3002 (inline)
30+
line3001 (inline)
3131
line3000
3232
-----------+-------------------------------------------------------

internal/report/report.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,23 @@ func printTraces(w io.Writer, rpt *Report) error {
834834

835835
_, locations := graph.CreateNodes(prof, &graph.Options{})
836836
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
838842
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+
// In this and some other reports the inline flag won't be accurate if
846+
// 'show' or 'hide' filter is used. Those filters may filter out some
847+
// of entries in the line array causing a remaining entry (which is
848+
// physically inlined) to be the rightmost entry in the filtered array,
849+
// and this heuristic will erroneously consider that line entry as not
850+
// inlined. A number of other reports have a similar flaw.
851+
inline := i != len(nodes)-1
852+
stack = append(stack, stk{&n.Info, inline})
853+
}
841854
}
842855

843856
if len(stack) == 0 {
@@ -875,10 +888,16 @@ func printTraces(w io.Writer, rpt *Report) error {
875888
if d != 0 {
876889
v = v / d
877890
}
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())
891+
for i, s := range stack {
892+
var vs string
893+
if i == 0 {
894+
vs = rpt.formatValue(v)
895+
}
896+
fmt.Fprintf(w, "%10s %s", vs, s.PrintableName())
897+
if s.inline {
898+
fmt.Fprint(w, " (inline)")
899+
}
900+
fmt.Fprintln(w)
882901
}
883902
}
884903
fmt.Fprintln(w, separator)

0 commit comments

Comments
 (0)