aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata/testprog
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-06-20 14:00:58 -0700
committerIan Lance Taylor <iant@golang.org>2016-06-21 01:44:38 +0000
commit252eda470a3684a1ead5956f7e703532f4213f11 (patch)
tree8f38ecd99ce5ca03932ee6af1be99eb241ca0b48 /src/runtime/testdata/testprog
parent09834d1c082a2437b12584bebaa7353377e66f1a (diff)
downloadgo-252eda470a3684a1ead5956f7e703532f4213f11.tar.xz
cmd/pprof: don't use offset if we don't have a start address
The test is in the runtime package because there are other tests of pprof there. At some point we should probably move them all into a pprof testsuite. Fixes #16128. Change-Id: Ieefa40c61cf3edde11fe0cf04da1debfd8b3d7c0 Reviewed-on: https://go-review.googlesource.com/24274 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/runtime/testdata/testprog')
-rw-r--r--src/runtime/testdata/testprog/memprof.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/runtime/testdata/testprog/memprof.go b/src/runtime/testdata/testprog/memprof.go
new file mode 100644
index 0000000000..a22fee61d7
--- /dev/null
+++ b/src/runtime/testdata/testprog/memprof.go
@@ -0,0 +1,49 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "runtime"
+ "runtime/pprof"
+)
+
+func init() {
+ register("MemProf", MemProf)
+}
+
+var memProfBuf bytes.Buffer
+var memProfStr string
+
+func MemProf() {
+ for i := 0; i < 1000; i++ {
+ fmt.Fprintf(&memProfBuf, "%*d\n", i, i)
+ }
+ memProfStr = memProfBuf.String()
+
+ runtime.GC()
+
+ f, err := ioutil.TempFile("", "memprof")
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ os.Exit(2)
+ }
+
+ if err := pprof.WriteHeapProfile(f); err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ os.Exit(2)
+ }
+
+ name := f.Name()
+ if err := f.Close(); err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ os.Exit(2)
+ }
+
+ fmt.Println(name)
+}