Print memory usage in both bytes and megabytes

This commit is contained in:
Dan Sosedoff
2014-11-20 21:00:53 -06:00
parent e1684fc8c0
commit 5ca2abb8d0

View File

@@ -6,6 +6,8 @@ import (
"time" "time"
) )
const MEGABYTE = 1024 * 1024
func startRuntimeProfiler() { func startRuntimeProfiler() {
m := &runtime.MemStats{} m := &runtime.MemStats{}
@@ -14,8 +16,8 @@ func startRuntimeProfiler() {
fmt.Println("-----------------------") fmt.Println("-----------------------")
fmt.Println("Goroutines:", runtime.NumGoroutine()) fmt.Println("Goroutines:", runtime.NumGoroutine())
fmt.Println("Memory acquired:", m.Sys) fmt.Println("Memory acquired:", m.Sys, "bytes,", m.Sys/MEGABYTE, "mb")
fmt.Println("Memory used:", m.Alloc) fmt.Println("Memory used:", m.Alloc, "bytes,", m.Alloc/MEGABYTE, "mb")
time.Sleep(time.Minute) time.Sleep(time.Minute)
} }