Skip to content

Commit

Permalink
runtime/pprof, syscall: report MaxRSS on all unix platforms
Browse files Browse the repository at this point in the history
All unix platforms currently supported by Go provide the getrusage
syscall. On aix and solaris the Getrusage syscall wrapper is not
available yet, so add and use it to report MaxRSS in memory profiles.

Change-Id: Ie880a3058171031fd2e12ccf9adfb85ce18858b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/391434
Trust: Tobias Klauser <[email protected]>
Run-TryBot: Tobias Klauser <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
Trust: Michael Pratt <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
tklauser committed Mar 11, 2022
1 parent fe75fe3 commit c1f2213
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/runtime/pprof/pprof_norusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !darwin && !linux
//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris

package pprof

Expand Down
6 changes: 4 additions & 2 deletions src/runtime/pprof/pprof_rusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build darwin || linux
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris

package pprof

Expand All @@ -17,10 +17,12 @@ import (
func addMaxRSS(w io.Writer) {
var rssToBytes uintptr
switch runtime.GOOS {
case "linux", "android":
case "aix", "android", "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
rssToBytes = 1024
case "darwin", "ios":
rssToBytes = 1
case "illumos", "solaris":
rssToBytes = uintptr(syscall.Getpagesize())
default:
panic("unsupported OS")
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pprof/rusage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build darwin || freebsd || linux || netbsd || openbsd
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris

package pprof

Expand Down
1 change: 1 addition & 0 deletions src/syscall/syscall_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ func PtraceDetach(pid int) (err error) { return ptrace64(PT_DETACH, int64(pid),
//sys Getppid() (ppid int)
//sys Getpriority(which int, who int) (n int, err error)
//sysnb Getrlimit(which int, lim *Rlimit) (err error)
//sysnb Getrusage(who int, rusage *Rusage) (err error)
//sysnb Getuid() (uid int)
//sys Kill(pid int, signum Signal) (err error)
//sys Lchown(path string, uid int, gid int) (err error)
Expand Down
1 change: 1 addition & 0 deletions src/syscall/syscall_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ func sendmsgN(fd int, p, oob []byte, ptr unsafe.Pointer, salen _Socklen, flags i
//sys Getppid() (ppid int)
//sys Getpriority(which int, who int) (n int, err error)
//sysnb Getrlimit(which int, lim *Rlimit) (err error)
//sysnb Getrusage(who int, rusage *Rusage) (err error)
//sysnb Gettimeofday(tv *Timeval) (err error)
//sysnb Getuid() (uid int)
//sys Kill(pid int, signum Signal) (err error)
Expand Down
13 changes: 13 additions & 0 deletions src/syscall/zsyscall_aix_ppc64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/syscall/zsyscall_solaris_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1f2213

Please sign in to comment.