35 lines
552 B
Go
35 lines
552 B
Go
package giowrap
|
|
|
|
import (
|
|
"runtime"
|
|
)
|
|
|
|
type AllocEntry struct {
|
|
Value uint64
|
|
Text string
|
|
}
|
|
|
|
var (
|
|
memstats runtime.MemStats
|
|
oldMallocs uint64
|
|
AllMallocs []AllocEntry
|
|
)
|
|
|
|
func RecordMallocs() {
|
|
if AllMallocs == nil {
|
|
AllMallocs = make([]AllocEntry, 0, 64)
|
|
} else {
|
|
AllMallocs = AllMallocs[0:0]
|
|
}
|
|
runtime.ReadMemStats(&memstats)
|
|
oldMallocs = memstats.Mallocs
|
|
}
|
|
|
|
func Mallocs(s string) {
|
|
if AllMallocs == nil {
|
|
return
|
|
}
|
|
runtime.ReadMemStats(&memstats)
|
|
AllMallocs = append(AllMallocs, AllocEntry{memstats.Mallocs - oldMallocs, s})
|
|
}
|