]> Cypherpunks repositories - gostls13.git/commitdiff
internal/pprof: don't discard allocations called by reflect.Call
authorIan Lance Taylor <iant@golang.org>
Mon, 28 Nov 2016 20:18:29 +0000 (12:18 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 28 Nov 2016 21:52:15 +0000 (21:52 +0000)
The pprof code discards all heap allocations made by runtime
routines. This caused it to discard heap allocations made by functions
called by reflect.Call, as the calls are made via the functions
`runtime.call32`, `runtime.call64`, etc. Fix the profiler to retain
these heap allocations.

Fixes #18077.

Change-Id: I8962d552f1d0b70fc7e6f7b2dbae8d5bdefb0735
Reviewed-on: https://go-review.googlesource.com/33635
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/internal/pprof/profile/legacy_profile.go
src/runtime/pprof/mprof_test.go

index 5ad3e256408228ecb11bcc67c7d4fa2615140d7a..d3041d3b00e8189803fc6dbc0bd6cc143cebb4d1 100644 (file)
@@ -1224,6 +1224,8 @@ var allocSkipRxStr = strings.Join([]string{
        // Preserve Go runtime frames that appear in the middle/bottom of
        // the stack.
        `runtime\.panic`,
+       `runtime\.reflectcall`,
+       `runtime\.call[0-9]*`,
 }, `|`)
 
 var cpuProfilerRxStr = strings.Join([]string{
index 0fff9d46d9e139f1c0c297b5abf102bd66090828..df4f6f8bed5084c358ba55212d0add1fe9aa94c1 100644 (file)
@@ -7,6 +7,7 @@ package pprof_test
 import (
        "bytes"
        "fmt"
+       "reflect"
        "regexp"
        "runtime"
        . "runtime/pprof"
@@ -42,6 +43,17 @@ func allocatePersistent1K() {
        }
 }
 
+// Allocate transient memory using reflect.Call.
+
+func allocateReflectTransient() {
+       memSink = make([]byte, 2<<20)
+}
+
+func allocateReflect() {
+       rv := reflect.ValueOf(allocateReflectTransient)
+       rv.Call(nil)
+}
+
 var memoryProfilerRun = 0
 
 func TestMemoryProfiler(t *testing.T) {
@@ -61,6 +73,7 @@ func TestMemoryProfiler(t *testing.T) {
        allocateTransient1M()
        allocateTransient2M()
        allocatePersistent1K()
+       allocateReflect()
        memSink = nil
 
        runtime.GC() // materialize stats
@@ -73,18 +86,22 @@ func TestMemoryProfiler(t *testing.T) {
 
        tests := []string{
                fmt.Sprintf(`%v: %v \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-#      0x[0-9,a-f]+    runtime/pprof_test\.allocatePersistent1K\+0x[0-9,a-f]+  .*/runtime/pprof/mprof_test\.go:40
-#      0x[0-9,a-f]+    runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+    .*/runtime/pprof/mprof_test\.go:63
+#      0x[0-9,a-f]+    runtime/pprof_test\.allocatePersistent1K\+0x[0-9,a-f]+  .*/runtime/pprof/mprof_test\.go:41
+#      0x[0-9,a-f]+    runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+    .*/runtime/pprof/mprof_test\.go:75
 `, 32*memoryProfilerRun, 1024*memoryProfilerRun, 32*memoryProfilerRun, 1024*memoryProfilerRun),
 
                fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-#      0x[0-9,a-f]+    runtime/pprof_test\.allocateTransient1M\+0x[0-9,a-f]+   .*/runtime/pprof/mprof_test.go:21
-#      0x[0-9,a-f]+    runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+    .*/runtime/pprof/mprof_test.go:61
+#      0x[0-9,a-f]+    runtime/pprof_test\.allocateTransient1M\+0x[0-9,a-f]+   .*/runtime/pprof/mprof_test.go:22
+#      0x[0-9,a-f]+    runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+    .*/runtime/pprof/mprof_test.go:73
 `, (1<<10)*memoryProfilerRun, (1<<20)*memoryProfilerRun),
 
                fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+ 0x[0-9,a-f]+
-#      0x[0-9,a-f]+    runtime/pprof_test\.allocateTransient2M\+0x[0-9,a-f]+   .*/runtime/pprof/mprof_test.go:27
-#      0x[0-9,a-f]+    runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+    .*/runtime/pprof/mprof_test.go:62
+#      0x[0-9,a-f]+    runtime/pprof_test\.allocateTransient2M\+0x[0-9,a-f]+   .*/runtime/pprof/mprof_test.go:28
+#      0x[0-9,a-f]+    runtime/pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+    .*/runtime/pprof/mprof_test.go:74
+`, memoryProfilerRun, (2<<20)*memoryProfilerRun),
+
+               fmt.Sprintf(`0: 0 \[%v: %v\] @( 0x[0-9,a-f]+)+
+#      0x[0-9,a-f]+    runtime/pprof_test\.allocateReflectTransient\+0x[0-9,a-f]+      .*/runtime/pprof/mprof_test.go:49
 `, memoryProfilerRun, (2<<20)*memoryProfilerRun),
        }