github.com/Cloud-Foundations/Dominator@v0.3.4/lib/memstats/memstats.go (about)

     1  package memstats
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"runtime"
     7  
     8  	"github.com/Cloud-Foundations/Dominator/lib/format"
     9  )
    10  
    11  func writeNamedStat(writer io.Writer, name string, value uint64) {
    12  	fmt.Fprintf(writer, "  %s=%s\n", name, format.FormatBytes(value))
    13  }
    14  
    15  func WriteMemoryStats(writer io.Writer) {
    16  	var memStats runtime.MemStats
    17  	runtime.ReadMemStats(&memStats)
    18  	fmt.Fprintln(writer, "MemStats:")
    19  	writeNamedStat(writer, "Alloc", memStats.Alloc)
    20  	writeNamedStat(writer, "Sys", memStats.Sys)
    21  }