diff --git a/internal/driver/driver_test.go b/internal/driver/driver_test.go index 3dc7c9bfe..96534fbbb 100644 --- a/internal/driver/driver_test.go +++ b/internal/driver/driver_test.go @@ -86,6 +86,7 @@ func TestParse(t *testing.T) { {"tags", "heap"}, {"tags,unit=bytes", "heap"}, {"traces", "cpu"}, + {"traces,addresses", "cpu"}, {"traces", "heap_tags"}, {"dot,alloc_space,flat,focus=[234]00", "heap_alloc"}, {"dot,alloc_space,flat,tagshow=[2]00", "heap_alloc"}, diff --git a/internal/driver/testdata/pprof.cpu.addresses.traces b/internal/driver/testdata/pprof.cpu.addresses.traces new file mode 100644 index 000000000..742b123e1 --- /dev/null +++ b/internal/driver/testdata/pprof.cpu.addresses.traces @@ -0,0 +1,32 @@ +File: testbinary +Type: cpu +Duration: 10s, Total samples = 1.12s (11.20%) +-----------+------------------------------------------------------- + key1: tag1 + key2: tag1 + 1s 0000000000001000 line1000 testdata/file1000.src:1 + 0000000000002000 line2001 testdata/file2000.src:9 (inline) + 0000000000002000 line2000 testdata/file2000.src:4 + 0000000000003000 line3002 testdata/file3000.src:2 (inline) + 0000000000003000 line3001 testdata/file3000.src:5 (inline) + 0000000000003000 line3000 testdata/file3000.src:6 +-----------+------------------------------------------------------- + key1: tag2 + key3: tag2 + 100ms 0000000000001000 line1000 testdata/file1000.src:1 + 0000000000003001 line3001 testdata/file3000.src:8 (inline) + 0000000000003001 line3000 testdata/file3000.src:9 +-----------+------------------------------------------------------- + key1: tag3 + key2: tag2 + 10ms 0000000000002000 line2001 testdata/file2000.src:9 (inline) + 0000000000002000 line2000 testdata/file2000.src:4 + 0000000000003002 line3002 testdata/file3000.src:5 (inline) + 0000000000003002 line3000 testdata/file3000.src:9 +-----------+------------------------------------------------------- + key1: tag4 + key2: tag1 + 10ms 0000000000003000 line3002 testdata/file3000.src:2 (inline) + 0000000000003000 line3001 testdata/file3000.src:5 (inline) + 0000000000003000 line3000 testdata/file3000.src:6 +-----------+------------------------------------------------------- diff --git a/internal/driver/testdata/pprof.cpu.traces b/internal/driver/testdata/pprof.cpu.traces index d9637c0e4..dd31e2e62 100644 --- a/internal/driver/testdata/pprof.cpu.traces +++ b/internal/driver/testdata/pprof.cpu.traces @@ -5,28 +5,28 @@ Duration: 10s, Total samples = 1.12s (11.20%) key1: tag1 key2: tag1 1s line1000 - line2001 + line2001 (inline) line2000 - line3002 - line3001 + line3002 (inline) + line3001 (inline) line3000 -----------+------------------------------------------------------- key1: tag2 key3: tag2 100ms line1000 - line3001 + line3001 (inline) line3000 -----------+------------------------------------------------------- key1: tag3 key2: tag2 - 10ms line2001 + 10ms line2001 (inline) line2000 - line3002 + line3002 (inline) line3000 -----------+------------------------------------------------------- key1: tag4 key2: tag1 - 10ms line3002 - line3001 + 10ms line3002 (inline) + line3001 (inline) line3000 -----------+------------------------------------------------------- diff --git a/internal/driver/testdata/pprof.heap_tags.traces b/internal/driver/testdata/pprof.heap_tags.traces index 547aea74c..694b4b2c5 100644 --- a/internal/driver/testdata/pprof.heap_tags.traces +++ b/internal/driver/testdata/pprof.heap_tags.traces @@ -6,27 +6,27 @@ Type: inuse_space bytes: 100kB request: 100kB 1000kB line1000 - line2001 + line2001 (inline) line2000 - line3002 - line3001 + line3002 (inline) + line3001 (inline) line3000 -----------+------------------------------------------------------- bytes: 200kB 3.91MB line1000 - line3001 + line3001 (inline) line3000 -----------+------------------------------------------------------- key1: tag bytes: 1.56MB request: 1.56MB - 62.50MB line2001 + 62.50MB line2001 (inline) line2000 - line3002 + line3002 (inline) line3000 -----------+------------------------------------------------------- bytes: 400kB - 31.25MB line3002 - line3001 + 31.25MB line3002 (inline) + line3001 (inline) line3000 -----------+------------------------------------------------------- diff --git a/internal/report/report.go b/internal/report/report.go index 1b555a4e2..56083d8ab 100644 --- a/internal/report/report.go +++ b/internal/report/report.go @@ -834,10 +834,19 @@ func printTraces(w io.Writer, rpt *Report) error { _, locations := graph.CreateNodes(prof, &graph.Options{}) for _, sample := range prof.Sample { - var stack graph.Nodes + type stk struct { + *graph.NodeInfo + inline bool + } + var stack []stk for _, loc := range sample.Location { - id := loc.ID - stack = append(stack, locations[id]...) + nodes := locations[loc.ID] + for i, n := range nodes { + // The inline flag may be inaccurate if 'show' or 'hide' filter is + // used. See https://github.com/google/pprof/issues/511. + inline := i != len(nodes)-1 + stack = append(stack, stk{&n.Info, inline}) + } } if len(stack) == 0 { @@ -875,10 +884,15 @@ func printTraces(w io.Writer, rpt *Report) error { if d != 0 { v = v / d } - fmt.Fprintf(w, "%10s %s\n", - rpt.formatValue(v), stack[0].Info.PrintableName()) - for _, s := range stack[1:] { - fmt.Fprintf(w, "%10s %s\n", "", s.Info.PrintableName()) + for i, s := range stack { + var vs, inline string + if i == 0 { + vs = rpt.formatValue(v) + } + if s.inline { + inline = " (inline)" + } + fmt.Fprintf(w, "%10s %s%s\n", vs, s.PrintableName(), inline) } } fmt.Fprintln(w, separator)