Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Last active November 8, 2022 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/4276123691f96b052f3ad58ff4c3ff88 to your computer and use it in GitHub Desktop.
Save BetterProgramming/4276123691f96b052f3ad58ff4c3ff88 to your computer and use it in GitHub Desktop.
func (s server) ServeMemProfile(ws *websocket.Conn) {
defer ws.Close()
var payload struct {
MemStats runtime.MemStats
GCStats debug.GCStats
NumGoroutine int
}
for {
payload.NumGoroutine = runtime.NumGoroutine()
runtime.ReadMemStats(&payload.MemStats)
debug.ReadGCStats(&payload.GCStats)
err := websocket.JSON.Send(ws, payload)
if err != nil {
break
}
<-time.After(s.Tick)
}
}​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment