mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-17 16:12:42 +08:00
mem usage
This commit is contained in:
35
sys/show_usage.go
Normal file
35
sys/show_usage.go
Normal file
@ -0,0 +1,35 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type MemUsage struct {
|
||||
Alloc float64
|
||||
TotalAlloc float64
|
||||
Sys float64
|
||||
NumGC uint32
|
||||
}
|
||||
|
||||
func (m MemUsage) String() string {
|
||||
return fmt.Sprintf("Alloc = %.2fMB TotalAlloc = %.2fMB Sys = %.2fMB NumGC = %v",
|
||||
m.Alloc,
|
||||
m.TotalAlloc,
|
||||
m.Sys,
|
||||
m.NumGC)
|
||||
}
|
||||
|
||||
func ShowMemUsage() MemUsage {
|
||||
var m runtime.MemStats
|
||||
|
||||
runtime.ReadMemStats(&m)
|
||||
mb := 1024 * 1024.0
|
||||
|
||||
return MemUsage{
|
||||
Alloc: float64(m.Alloc) / mb,
|
||||
TotalAlloc: float64(m.TotalAlloc) / mb,
|
||||
Sys: float64(m.Sys) / mb,
|
||||
NumGC: m.NumGC,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user