Skip to content

Commit

Permalink
runtime/pprof: export max rss when saving memory profiles.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jeremyfaller committed Mar 17, 2020
1 parent 2e918c3 commit fb1cd94
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/go/build/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},

Expand Down
3 changes: 3 additions & 0 deletions src/runtime/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
15 changes: 15 additions & 0 deletions src/runtime/pprof/pprof_norusage.go
Original file line number Diff line number Diff line change
@@ -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) {
}
20 changes: 20 additions & 0 deletions src/runtime/pprof/pprof_rusage.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit fb1cd94

Please sign in to comment.