Skip to content

Commit fb1cd94

Browse files
committed
runtime/pprof: export max rss when saving memory profiles.
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 2e918c3 commit fb1cd94

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/go/build/deps_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ var pkgDeps = map[string][]string{
195195
"regexp": {"L2", "regexp/syntax"},
196196
"regexp/syntax": {"L2"},
197197
"runtime/debug": {"L2", "fmt", "io/ioutil", "os", "time"},
198-
"runtime/pprof": {"L2", "compress/gzip", "context", "encoding/binary", "fmt", "io/ioutil", "os", "text/tabwriter", "time"},
198+
"runtime/pprof": {"L2", "compress/gzip", "context", "encoding/binary", "fmt", "io/ioutil", "os", "syscall", "text/tabwriter", "time"},
199199
"runtime/trace": {"L0", "context", "fmt"},
200200
"text/tabwriter": {"L2"},
201201

src/runtime/pprof/pprof.go

+3
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ func writeHeapInternal(w io.Writer, debug int, defaultSampleType string) error {
630630
fmt.Fprintf(w, "# GCCPUFraction = %v\n", s.GCCPUFraction)
631631
fmt.Fprintf(w, "# DebugGC = %v\n", s.DebugGC)
632632

633+
// Also flush out MaxRSS on supported platforms.
634+
addMaxRSS(w)
635+
633636
tw.Flush()
634637
return b.Flush()
635638
}

src/runtime/pprof/pprof_norusage.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build !darwin,!linux
6+
7+
package pprof
8+
9+
import (
10+
"io"
11+
)
12+
13+
// Stub call for platforms that don't support rusage.
14+
func addMaxRSS(w io.Writer) {
15+
}

src/runtime/pprof/pprof_rusage.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build darwin linux
6+
7+
package pprof
8+
9+
import (
10+
"fmt"
11+
"io"
12+
"syscall"
13+
)
14+
15+
// Adds MaxRSS to platforms that are supported.
16+
func addMaxRSS(w io.Writer) {
17+
var rusage syscall.Rusage
18+
syscall.Getrusage(0, &rusage)
19+
fmt.Fprintf(w, "# MaxRSS = %d\n", rusage.Maxrss)
20+
}

0 commit comments

Comments
 (0)