1
0
mirror of https://github.com/golang/go synced 2024-09-29 13:24:28 -06:00

runtime/pprof: check Getrusage return value in addMaxRSS

Depending on the implementation of the getrusage syscall/function, the
value of rusage.Maxrss may be undefined in case of an error. Thus, only
report MaxRSS in case of no error.

Change-Id: I7572ccc53c49eb460e53bded3eb41736eed8d2ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/424815
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Tobias Klauser 2022-08-18 19:15:51 +02:00 committed by Gopher Robot
parent 2cc6983a21
commit 2e06019dcd

View File

@ -28,6 +28,8 @@ func addMaxRSS(w io.Writer) {
}
var rusage syscall.Rusage
syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes)
err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
if err == nil {
fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes)
}
}