Last active
November 8, 2022 20:14
-
-
Save BetterProgramming/4276123691f96b052f3ad58ff4c3ff88 to your computer and use it in GitHub Desktop.
This file contains 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
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