From fafa4280f58c4c6be3646870f9e7cbb4ada15f0b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 30 Mar 2023 21:51:09 +0200 Subject: Log memory usage every 10s --- pkg/gui/background.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'pkg') diff --git a/pkg/gui/background.go b/pkg/gui/background.go index db267c0dc..061502a43 100644 --- a/pkg/gui/background.go +++ b/pkg/gui/background.go @@ -1,6 +1,8 @@ package gui import ( + "fmt" + "runtime" "strings" "time" @@ -46,6 +48,29 @@ func (self *BackgroundRoutineMgr) startBackgroundRoutines() { refreshInterval) } } + + if self.gui.Config.GetDebug() { + self.goEvery(time.Second*time.Duration(10), self.gui.stopChan, func() error { + formatBytes := func(b uint64) string { + const unit = 1000 + if b < unit { + return fmt.Sprintf("%d B", b) + } + div, exp := uint64(unit), 0 + for n := b / unit; n >= unit; n /= unit { + div *= unit + exp++ + } + return fmt.Sprintf("%.1f %cB", + float64(b)/float64(div), "kMGTPE"[exp]) + } + + m := runtime.MemStats{} + runtime.ReadMemStats(&m) + self.gui.c.Log.Infof("Heap memory in use: %s", formatBytes(m.HeapAlloc)) + return nil + }) + } } func (self *BackgroundRoutineMgr) startBackgroundFetch() { -- cgit v1.2.3