]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof, syscall: report MaxRSS on all unix platforms
authorTobias Klauser <tklauser@distanz.ch>
Thu, 10 Mar 2022 08:28:09 +0000 (09:28 +0100)
committerTobias Klauser <tobias.klauser@gmail.com>
Fri, 11 Mar 2022 06:03:26 +0000 (06:03 +0000)
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 <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Trust: Michael Pratt <mpratt@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/pprof/pprof_norusage.go
src/runtime/pprof/pprof_rusage.go
src/runtime/pprof/rusage_test.go
src/syscall/syscall_aix.go
src/syscall/syscall_solaris.go
src/syscall/zsyscall_aix_ppc64.go
src/syscall/zsyscall_solaris_amd64.go

index cbc5176cfa063b3b09e52ebfb7150fb714798922..3d6052519c4e06cbe8cfef59a78190711e52fb5e 100644 (file)
@@ -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
 
index 46263fedd965da6d97598d81527ed1475ce1b3e7..7df81eca23cf06aa38cba5ccaffa70fbf078f3d0 100644 (file)
@@ -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")
        }
index b0d651e0ebb20197e2e4601464f9990871e9c58e..f274d0caa3ad899344d073c2ef6210098a53c4f0 100644 (file)
@@ -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
 
index 739c55f1793f282af629e8b4dd4f9533327621a6..acc19b4db32b7dc36be78f34738bb33f5ba2afea 100644 (file)
@@ -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)
index d01070b2ec53869abc67da19d218dc5de17623d7..38c82a11e85ce4795f4f655bdf0e039ac283db4d 100644 (file)
@@ -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)
index 94f1b4371c5724bee5b75b0d37e669a0f435c615..2a3411374f5725ebc938dd1620f6b6f1975b7180 100644 (file)
@@ -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)
index dad05800273fec25fc62dc23209542a2997bdd97..7b012bf9bb8a0d2fb9043333c0bf10e6aea2f2de 100644 (file)
@@ -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 {