Last active
November 15, 2016 06:54
-
-
Save cep21/0b3b51cf04126e055af2fcfb3f633318 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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