Debian Codegraph @

src/runtime/pprof/pprof_rusage.go

raw
1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build unix
6
7 package pprof
8
9 import (
10 "fmt"
11 "io"
12 "runtime"
13 "syscall"
14 )
15
16 // Adds MaxRSS to platforms that are supported.
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 }