aboutsummaryrefslogtreecommitdiff
path: root/go/stats/memory.go
blob: 0700d92de253f419c80b34f26e223406c7c6b271 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package stats

import (
	"runtime"
)

type MemStatus struct {
	Goroutines int
	All        uint64
	Used       uint64
	Free       uint64
	Self       uint64
	Heap       uint64
	Stack      uint64
}

func MemStat() MemStatus {
	mem := MemStatus{}
	mem.Goroutines = runtime.NumGoroutine()
	memStat := new(runtime.MemStats)
	runtime.ReadMemStats(memStat)
	mem.Self = memStat.Alloc
	mem.Heap = memStat.HeapAlloc
	mem.Stack = memStat.StackInuse

	mem.fillInStatus()
	return mem
}