Created
March 12, 2020 06:02
-
-
Save koron/baaca48e007102aed46d18a82cb1b363 to your computer and use it in GitHub Desktop.
a program to check minimum VSZ limitation to start
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/rand" | |
"fmt" | |
"io" | |
"os" | |
"runtime" | |
"time" | |
"github.com/dustin/go-humanize" | |
) | |
func memStat(w io.Writer, n int) { | |
var m runtime.MemStats | |
runtime.ReadMemStats(&m) | |
//fmt.Fprintf(w, "Sys=%s Alloc=%s\n", humanize.IBytes(m.Sys), humanize.IBytes(m.Alloc)) | |
fmt.Fprintf(w, "Sys=%s - Heap=%s Stack=%s MSpan=%s MCache=%s BuckHash=%s GC=%s Other=%s\n", | |
humanize.IBytes(m.Sys), | |
humanize.IBytes(m.HeapSys), | |
humanize.IBytes(m.StackSys), | |
humanize.IBytes(m.MSpanSys), | |
humanize.IBytes(m.MCacheSys), | |
humanize.IBytes(m.BuckHashSys), | |
humanize.IBytes(m.GCSys), | |
humanize.IBytes(m.OtherSys), | |
) | |
} | |
func main() { | |
memStat(os.Stdout, 0) | |
var foo [][]byte | |
for i := 0; i < 10; i++ { | |
time.Sleep(2 * time.Second) | |
bar := make([]byte, 128*1024*1024) | |
rand.Read(bar) | |
foo = append(foo, bar) | |
memStat(os.Stdout, i+1) | |
} | |
fmt.Printf("len(foo)=%d\n", len(foo)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment