mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	Log memory usage every 10s
This commit is contained in:
		| @@ -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() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user