master
Evan Chen 2021-11-11 11:02:53 +08:00
commit 38951777fc
4 changed files with 50 additions and 0 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# stat
get simple stat for current go command and stat of a pid

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module kumoly.io/lib/stat
go 1.17

26
stat.go Normal file
View File

@ -0,0 +1,26 @@
package stat
import "runtime"
type Profile struct {
Alloc uint64
TotalAlloc uint64
SysMem uint64
NumGC uint32
}
func GetProfile() *Profile {
var m runtime.MemStats
runtime.ReadMemStats(&m)
return &Profile{
Alloc: bToMb(m.Alloc),
TotalAlloc: bToMb(m.TotalAlloc),
SysMem: bToMb(m.Sys),
NumGC: m.NumGC,
}
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}

18
stat_test.go Normal file
View File

@ -0,0 +1,18 @@
package stat
import (
"fmt"
"testing"
)
func TestStat(t *testing.T) {
fmt.Printf("%+v\n", GetProfile())
buf := make([][]int, 1024)
for i := range buf {
buf[i] = make([]int, 1024)
for j := 0; j < len(buf[i]); j++ {
buf[i][j] = 20
}
}
fmt.Printf("%+v\n", GetProfile())
}