]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: fix units of MaxRSS on Linux
authorAustin Clements <austin@google.com>
Wed, 29 Apr 2020 19:06:21 +0000 (15:06 -0400)
committerAustin Clements <austin@google.com>
Wed, 29 Apr 2020 20:33:31 +0000 (20:33 +0000)
Rusage.Maxrss is in bytes on Darwin but in KiB on Linux. Fix this
discrepancy so it's always in bytes.

Change-Id: Ic714abc3276566b8fe5e30565072092212610854
Reviewed-on: https://go-review.googlesource.com/c/go/+/230979
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/runtime/pprof/pprof_rusage.go

index 6eaf16844426c18ab0ce72f5f4e1e6f32782d4c0..d42e6ed4737cb6689b79a7f30947de674286f09b 100644 (file)
@@ -9,12 +9,23 @@ package pprof
 import (
        "fmt"
        "io"
+       "runtime"
        "syscall"
 )
 
 // Adds MaxRSS to platforms that are supported.
 func addMaxRSS(w io.Writer) {
+       var rssToBytes uintptr
+       switch runtime.GOOS {
+       case "linux", "android":
+               rssToBytes = 1024
+       case "darwin":
+               rssToBytes = 1
+       default:
+               panic("unsupported OS")
+       }
+
        var rusage syscall.Rusage
        syscall.Getrusage(0, &rusage)
-       fmt.Fprintf(w, "# MaxRSS = %d\n", rusage.Maxrss)
+       fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes)
 }