1
0
mirror of https://github.com/DataDog/go-profiler-notes.git synced 2025-07-15 23:54:16 +02:00
Files
go-profiler-notes/guide/memory-profiler.go
Felix Geisendörfer 1760fb4061 Update graphics
2022-01-13 14:13:43 +01:00

47 lines
608 B
Go

//go:build ignore
// +build ignore
package main
import (
"fmt"
"os"
"runtime"
"runtime/pprof"
"time"
)
func main() {
file, _ := os.Create("./memory-profiler.pprof")
defer pprof.Lookup("allocs").WriteTo(file, 0)
defer runtime.GC()
go allocSmall()
go allocBig()
time.Sleep(1 * time.Second)
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("%#v\n", m)
}
//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)
}