Source file src/runtime/pprof/pprof_rusage.go
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 darwin || linux 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 "linux", "android": 21 rssToBytes = 1024 22 case "darwin", "ios": 23 rssToBytes = 1 24 default: 25 panic("unsupported OS") 26 } 27 28 var rusage syscall.Rusage 29 syscall.Getrusage(0, &rusage) 30 fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes) 31 } 32