mirror of
https://github.com/DataDog/go-profiler-notes.git
synced 2026-06-21 00:46:51 +08:00
hack
This commit is contained in:
parent
0fdb5b19fb
commit
7b615d6a34
1 changed files with 38 additions and 0 deletions
38
guide/memory-profiler.go
Normal file
38
guide/memory-profiler.go
Normal 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)
|
||||
}
|
||||
Loading…
Reference in a new issue