Repository: google/pprof
Pull request #510 (2020-02-15 23:06:58)

Mark inlined frames as such in the traces report.

codecov-io: # [Codecov](https://codecov.io/gh/google/pprof/pull/510?src=pr&el=h1) Report
> Merging [#510](https://codecov.io/gh/google/pprof/pull/510?src=pr&el=desc) into [master](https://codecov.io/gh/google/pprof/commit/f11f1df84d12adcffbe33959f0629087311bd28f?src=pr&el=desc) will **decrease** coverage by `0.07%`.
> The diff coverage is `0%`.

[![Impacted file tree graph](https://codecov.io/gh/google/pprof/pull/510/graphs/tree.svg?width=650&token=nHgs4Smibv&height=150&src=pr)](https://codecov.io/gh/google/pprof/pull/510?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #510      +/-   ##
==========================================
- Coverage   67.13%   67.05%   -0.08%     
==========================================
  Files          37       37              
  Lines        7603     7612       +9     
==========================================
  Hits         5104     5104              
- Misses       2095     2104       +9     
  Partials      404      404
```


| [Impacted Files](https://codecov.io/gh/google/pprof/pull/510?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/report/report.go](https://codecov.io/gh/google/pprof/pull/510/diff?src=pr&el=tree#diff-aW50ZXJuYWwvcmVwb3J0L3JlcG9ydC5nbw==) | `30.59% <0%> (-0.39%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/pprof/pull/510?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/pprof/pull/510?src=pr&el=footer). Last update [f11f1df...398b1a5](https://codecov.io/gh/google/pprof/pull/510?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/internal/report/report.go b/internal/report/report.go
index 1b555a4..56083d8 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)


Test patch:
diff --git a/internal/driver/driver_test.go b/internal/driver/driver_test.go
index 3dc7c9b..96534fb 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 0000000..742b123
--- /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 d9637c0..dd31e2e 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 547aea7..694b4b2 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
 -----------+-------------------------------------------------------