Skip to content

Instantly share code, notes, and snippets.

@cep21
Last active November 15, 2016 06:54
Show Gist options
  • Save cep21/0b3b51cf04126e055af2fcfb3f633318 to your computer and use it in GitHub Desktop.
Save cep21/0b3b51cf04126e055af2fcfb3f633318 to your computer and use it in GitHub Desktop.
type Stats struct {
prev runtime.MemStats
}
func (p *Stats) stats() {
ms := runtime.MemStats{}
runtime.ReadMemStats(&ms)
mallocCount := ms.Mallocs - p.prev.Mallocs
fmt.Println("malloc change is", mallocCount)
p.prev = ms
}
func (p *Stats) Loop(ctx context.Context) {
runtime.ReadMemStats(&p.prev)
for {
select {
case <-time.After(time.Millisecond * 100):
p.stats()
case <-ctx.Done():
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment