This commit is contained in:
Felix Geisendörfer 2021-09-11 15:47:27 +02:00
parent 0fdb5b19fb
commit 7b615d6a34

38
guide/memory-profiler.go Normal file
View file

@ -0,0 +1,38 @@
// +build ignore
package main
import (
"os"
"runtime/pprof"
"time"
)
func main() {
file, _ := os.Create("./mem.pprof")
defer pprof.Lookup("allocs").WriteTo(file, 0)
go allocSmall()
go allocBig()
time.Sleep(1 * time.Second)
}
//go:noinline
func allocSmall() {
for i := 0; ; i++ {
_ = alloc(32)
}
}
//go:noinline
func allocBig() {
for i := 0; ; i++ {
_ = alloc(256)
}
}
//go:noinline
func alloc(size int) []byte {
return make([]byte, size)
}