mem.go 603 B

12345678910111213141516171819202122232425262728
  1. package subject
  2. import (
  3. "fmt"
  4. "runtime"
  5. )
  6. func toMegaBytes(bytes uint64) float64 {
  7. return float64(bytes) / 1024 / 1024
  8. }
  9. func traceMemStats() {
  10. var ms runtime.MemStats
  11. runtime.ReadMemStats(&ms)
  12. var result = make([]float64, 7)
  13. result[0] = float64(ms.HeapObjects)
  14. result[1] = toMegaBytes(ms.HeapAlloc)
  15. result[2] = toMegaBytes(ms.TotalAlloc)
  16. result[3] = toMegaBytes(ms.HeapSys)
  17. result[4] = toMegaBytes(ms.HeapIdle)
  18. result[5] = toMegaBytes(ms.HeapReleased)
  19. result[6] = toMegaBytes(ms.HeapIdle - ms.HeapReleased)
  20. for _, v := range result {
  21. fmt.Printf("%.2f\t", v)
  22. }
  23. fmt.Printf("\n")
  24. }