memory.go 471 B

12345678910111213141516171819202122232425262728
  1. package stats
  2. import (
  3. "runtime"
  4. )
  5. type MemStatus struct {
  6. Goroutines int
  7. All uint64
  8. Used uint64
  9. Free uint64
  10. Self uint64
  11. Heap uint64
  12. Stack uint64
  13. }
  14. func MemStat() MemStatus {
  15. mem := MemStatus{}
  16. mem.Goroutines = runtime.NumGoroutine()
  17. memStat := new(runtime.MemStats)
  18. runtime.ReadMemStats(memStat)
  19. mem.Self = memStat.Alloc
  20. mem.Heap = memStat.HeapAlloc
  21. mem.Stack = memStat.StackInuse
  22. mem.fillInStatus()
  23. return mem
  24. }