From f243fc68311edbf4f1b99c50c20c7f65ee60ec27 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 8 Apr 2024 21:39:52 +0100 Subject: [PATCH] Add debug heap memory allocation --- background/ticker.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/background/ticker.go b/background/ticker.go index 622f348..04dcac5 100644 --- a/background/ticker.go +++ b/background/ticker.go @@ -50,7 +50,17 @@ func goroutineTicker(stop <-chan struct{}) { case <-stop: return case <-ticker.C: - fmt.Printf("Number of goroutines running: %d\n", runtime.NumGoroutine()) + debugLog() } } } + +func debugLog() { + var memStats runtime.MemStats + runtime.ReadMemStats(&memStats) + + goroutines := runtime.NumGoroutine() + + fmt.Printf("\nNumber of goroutines: %d\n", goroutines) + fmt.Printf("Heap Allocated memory: %2f MB\n\n", float64(memStats.HeapAlloc)/(1024*1024)) +}