Source file src/runtime/pprof/pprof_rusage.go
Documentation: runtime/pprof
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 // +build darwin linux 7 8 package pprof 9 10 import ( 11 "fmt" 12 "io" 13 "runtime" 14 "syscall" 15 ) 16 17 // Adds MaxRSS to platforms that are supported. 18 func addMaxRSS(w io.Writer) { 19 var rssToBytes uintptr 20 switch runtime.GOOS { 21 case "linux", "android": 22 rssToBytes = 1024 23 case "darwin", "ios": 24 rssToBytes = 1 25 default: 26 panic("unsupported OS") 27 } 28 29 var rusage syscall.Rusage 30 syscall.Getrusage(0, &rusage) 31 fmt.Fprintf(w, "# MaxRSS = %d\n", uintptr(rusage.Maxrss)*rssToBytes) 32 } 33