Last active
August 29, 2015 14:03
-
-
Save maliubiao/d8f7a0cfa95130ea4569 to your computer and use it in GitHub Desktop.
memstat.go
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 ( | |
| "fmt" | |
| "runtime" | |
| ) | |
| type Stats struct { | |
| name string | |
| value uint64 | |
| } | |
| func PrintStats() { | |
| var m runtime.MemStats | |
| runtime.ReadMemStats(&m) | |
| stats := []Stats{ | |
| {"Alloc", m.Alloc}, | |
| {"TotalAlloc", m.TotalAlloc}, | |
| {"Sys", m.Sys}, | |
| {"Lookups", m.Lookups}, | |
| {"Mallocs", m.Mallocs}, | |
| {"HeapAlloc", m.HeapAlloc}, | |
| {"HeapSys", m.HeapSys}, | |
| {"HeapIdle", m.HeapIdle}, | |
| {"HeapInuse", m.HeapInuse}, | |
| {"HeapReleased", m.HeapReleased}, | |
| {"HeapObjects", m.HeapObjects}, | |
| {"StackInuse", m.StackInuse}, | |
| {"StackSys", m.StackSys}, | |
| {"MSpanInuse", m.MSpanInuse}, | |
| {"MSpanSys", m.MSpanSys}, | |
| {"MCacheInuse", m.MCacheInuse}, | |
| {"MCacheSys", m.MCacheSys}, | |
| {"BuckHashSys", m.BuckHashSys}, | |
| {"GCSys", m.GCSys}, | |
| {"OtherSys", m.OtherSys}, | |
| {"NextGC", m.NextGC}, | |
| {"LastGC", m.LastGC}, | |
| {"PauseTotalNs", m.PauseTotalNs}, | |
| {"NumGC", (uint64)(m.NumGC)}, | |
| } | |
| for _, v := range stats { | |
| fmt.Printf("%-15s: %-10d\n", v.name, v.value) | |
| } | |
| fmt.Printf("%-15s: %-10t\n", "EnableGC", m.EnableGC) | |
| fmt.Printf("%-15s: %-10t\n", "DebugGC", m.DebugGC) | |
| } | |
| func main() { | |
| PrintStats() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment