diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-03-30 21:51:09 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 11:48:40 +0200 |
commit | fafa4280f58c4c6be3646870f9e7cbb4ada15f0b (patch) | |
tree | a9ac5c31087897a0766f61d7d3c7de82ee1332a4 /pkg | |
parent | 5a5cd849d18779ff8f2d057a70550fa737a238fc (diff) |
Log memory usage every 10s
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/background.go | 25 |
1 files changed, 25 insertions, 0 deletions
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() { |