From: Tobias Klauser Date: Thu, 10 Mar 2022 08:28:09 +0000 (+0100) Subject: runtime/pprof, syscall: report MaxRSS on all unix platforms X-Git-Tag: go1.19beta1~1087 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c1f22134f22158ebeebf450357f711eb22fab202;p=gostls13.git runtime/pprof, syscall: report MaxRSS on all unix platforms 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 Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt Trust: Michael Pratt Reviewed-by: Ian Lance Taylor --- diff --git a/src/runtime/pprof/pprof_norusage.go b/src/runtime/pprof/pprof_norusage.go index cbc5176cfa..3d6052519c 100644 --- a/src/runtime/pprof/pprof_norusage.go +++ b/src/runtime/pprof/pprof_norusage.go @@ -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 diff --git a/src/runtime/pprof/pprof_rusage.go b/src/runtime/pprof/pprof_rusage.go index 46263fedd9..7df81eca23 100644 --- a/src/runtime/pprof/pprof_rusage.go +++ b/src/runtime/pprof/pprof_rusage.go @@ -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 @@ -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") } diff --git a/src/runtime/pprof/rusage_test.go b/src/runtime/pprof/rusage_test.go index b0d651e0eb..f274d0caa3 100644 --- a/src/runtime/pprof/rusage_test.go +++ b/src/runtime/pprof/rusage_test.go @@ -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 diff --git a/src/syscall/syscall_aix.go b/src/syscall/syscall_aix.go index 739c55f179..acc19b4db3 100644 --- a/src/syscall/syscall_aix.go +++ b/src/syscall/syscall_aix.go @@ -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) diff --git a/src/syscall/syscall_solaris.go b/src/syscall/syscall_solaris.go index d01070b2ec..38c82a11e8 100644 --- a/src/syscall/syscall_solaris.go +++ b/src/syscall/syscall_solaris.go @@ -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) diff --git a/src/syscall/zsyscall_aix_ppc64.go b/src/syscall/zsyscall_aix_ppc64.go index 94f1b4371c..2a3411374f 100644 --- a/src/syscall/zsyscall_aix_ppc64.go +++ b/src/syscall/zsyscall_aix_ppc64.go @@ -62,6 +62,7 @@ import "unsafe" //go:cgo_import_dynamic libc_Getppid getppid "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Getpriority getpriority "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Getrlimit getrlimit "libc.a/shr_64.o" +//go:cgo_import_dynamic libc_Getrusage getrusage "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Getuid getuid "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Kill kill "libc.a/shr_64.o" //go:cgo_import_dynamic libc_Lchown lchown "libc.a/shr_64.o" @@ -154,6 +155,7 @@ import "unsafe" //go:linkname libc_Getppid libc_Getppid //go:linkname libc_Getpriority libc_Getpriority //go:linkname libc_Getrlimit libc_Getrlimit +//go:linkname libc_Getrusage libc_Getrusage //go:linkname libc_Getuid libc_Getuid //go:linkname libc_Kill libc_Kill //go:linkname libc_Lchown libc_Lchown @@ -249,6 +251,7 @@ var ( libc_Getppid, libc_Getpriority, libc_Getrlimit, + libc_Getrusage, libc_Getuid, libc_Kill, libc_Lchown, @@ -925,6 +928,16 @@ func Getrlimit(which int, lim *Rlimit) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := rawSyscall6(uintptr(unsafe.Pointer(&libc_Getrusage)), 2, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Getuid() (uid int) { r0, _, _ := rawSyscall6(uintptr(unsafe.Pointer(&libc_Getuid)), 0, 0, 0, 0, 0, 0, 0) uid = int(r0) diff --git a/src/syscall/zsyscall_solaris_amd64.go b/src/syscall/zsyscall_solaris_amd64.go index dad0580027..7b012bf9bb 100644 --- a/src/syscall/zsyscall_solaris_amd64.go +++ b/src/syscall/zsyscall_solaris_amd64.go @@ -35,6 +35,7 @@ import "unsafe" //go:cgo_import_dynamic libc_Getppid getppid "libc.so" //go:cgo_import_dynamic libc_Getpriority getpriority "libc.so" //go:cgo_import_dynamic libc_Getrlimit getrlimit "libc.so" +//go:cgo_import_dynamic libc_Getrusage getrusage "libc.so" //go:cgo_import_dynamic libc_Gettimeofday gettimeofday "libc.so" //go:cgo_import_dynamic libc_Getuid getuid "libc.so" //go:cgo_import_dynamic libc_Kill kill "libc.so" @@ -120,6 +121,7 @@ import "unsafe" //go:linkname libc_Getppid libc_Getppid //go:linkname libc_Getpriority libc_Getpriority //go:linkname libc_Getrlimit libc_Getrlimit +//go:linkname libc_Getrusage libc_Getrusage //go:linkname libc_Gettimeofday libc_Gettimeofday //go:linkname libc_Getuid libc_Getuid //go:linkname libc_Kill libc_Kill @@ -208,6 +210,7 @@ var ( libc_Getppid, libc_Getpriority, libc_Getrlimit, + libc_Getrusage, libc_Gettimeofday, libc_Getuid, libc_Kill, @@ -580,6 +583,16 @@ func Getrlimit(which int, lim *Rlimit) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getrusage(who int, rusage *Rusage) (err error) { + _, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&libc_Getrusage)), 2, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Gettimeofday(tv *Timeval) (err error) { _, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&libc_Gettimeofday)), 1, uintptr(unsafe.Pointer(tv)), 0, 0, 0, 0, 0) if e1 != 0 {