Add a MemUsage() helper

This commit is contained in:
Frank Denis 2018-04-07 17:05:55 +02:00
parent 5c86191e43
commit 10986aba62
1 changed files with 11 additions and 0 deletions

View File

@ -3,7 +3,9 @@ package main
import ( import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt"
"net" "net"
"runtime"
"strconv" "strconv"
"strings" "strings"
"unicode" "unicode"
@ -153,3 +155,12 @@ func ExtractHostAndPort(str string, defaultPort int) (host string, port int) {
} }
return return
} }
func MemUsage() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Alloc = %v MiB", m.Alloc/1024/1024)
fmt.Printf("\tTotalAlloc = %v MiB", m.TotalAlloc/1024/1024)
fmt.Printf("\tSys = %v MiB", m.Sys/1024/1024)
fmt.Printf("\tNumGC = %v\n", m.NumGC)
}