1
2
3
4
5
6
7 package pprof
8
9 import (
10 "fmt"
11 "io"
12 "runtime"
13 "syscall"
14 )
15
16
17 func addMaxRSS(w io.Writer) {
18 var rssToBytes uintptr
19 switch runtime.GOOS {
20 case "aix", "android", "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
21 rssToBytes = 1024
22 case "darwin", "ios":
23 rssToBytes = 1
24 case "illumos", "solaris":
25 rssToBytes = uintptr(syscall.Getpagesize())
26 default:
27 panic("unsupported OS")
28 }
29
30 var rusage syscall.Rusage
31 err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
32 if err == nil {
33 fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes)
34 }
35 }
36
View as plain text