]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: export max rss when saving memory profiles.
authorJeremy Faller <jeremy@golang.org>
Tue, 25 Jun 2019 19:43:33 +0000 (15:43 -0400)
committerJeremy Faller <jeremy@golang.org>
Tue, 17 Mar 2020 15:29:08 +0000 (15:29 +0000)
NB: Adds syscall to deps on runtime/pprof.
Change-Id: I5dd14c2b25eb9c3c446832f5818de45fafd48a27
Reviewed-on: https://go-review.googlesource.com/c/go/+/183844
Run-TryBot: Jeremy Faller <jeremy@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/go/build/deps_test.go
src/runtime/pprof/pprof.go
src/runtime/pprof/pprof_norusage.go [new file with mode: 0644]
src/runtime/pprof/pprof_rusage.go [new file with mode: 0644]

index efb11814e761d3fe17acb53d4a4f7f4ac45ed664..9ef85dbf1bab9b282d1ad09ca66b679277ea9895 100644 (file)
@@ -195,7 +195,7 @@ var pkgDeps = map[string][]string{
        "regexp":         {"L2", "regexp/syntax"},
        "regexp/syntax":  {"L2"},
        "runtime/debug":  {"L2", "fmt", "io/ioutil", "os", "time"},
-       "runtime/pprof":  {"L2", "compress/gzip", "context", "encoding/binary", "fmt", "io/ioutil", "os", "text/tabwriter", "time"},
+       "runtime/pprof":  {"L2", "compress/gzip", "context", "encoding/binary", "fmt", "io/ioutil", "os", "syscall", "text/tabwriter", "time"},
        "runtime/trace":  {"L0", "context", "fmt"},
        "text/tabwriter": {"L2"},
 
index bbdc432eec4ca50025ce6ed973d4a90e55d3157a..b4f9ab8f7aa0a1495dde2e032512f62b26239fca 100644 (file)
@@ -630,6 +630,9 @@ func writeHeapInternal(w io.Writer, debug int, defaultSampleType string) error {
        fmt.Fprintf(w, "# GCCPUFraction = %v\n", s.GCCPUFraction)
        fmt.Fprintf(w, "# DebugGC = %v\n", s.DebugGC)
 
+       // Also flush out MaxRSS on supported platforms.
+       addMaxRSS(w)
+
        tw.Flush()
        return b.Flush()
 }
diff --git a/src/runtime/pprof/pprof_norusage.go b/src/runtime/pprof/pprof_norusage.go
new file mode 100644 (file)
index 0000000..6fdcc6c
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2019 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.
+
+// +build !darwin,!linux
+
+package pprof
+
+import (
+       "io"
+)
+
+// Stub call for platforms that don't support rusage.
+func addMaxRSS(w io.Writer) {
+}
diff --git a/src/runtime/pprof/pprof_rusage.go b/src/runtime/pprof/pprof_rusage.go
new file mode 100644 (file)
index 0000000..6eaf168
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2019 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.
+
+// +build darwin linux
+
+package pprof
+
+import (
+       "fmt"
+       "io"
+       "syscall"
+)
+
+// Adds MaxRSS to platforms that are supported.
+func addMaxRSS(w io.Writer) {
+       var rusage syscall.Rusage
+       syscall.Getrusage(0, &rusage)
+       fmt.Fprintf(w, "# MaxRSS = %d\n", rusage.Maxrss)
+}