From 928dcf9af9665af763190db52315f619435a3076 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Thu, 27 Apr 2023 06:55:53 +0000 Subject: [PATCH] chore: better memory fetching time --- tunnel/statistic/manager.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tunnel/statistic/manager.go b/tunnel/statistic/manager.go index 381ea7e6..ba2e1298 100644 --- a/tunnel/statistic/manager.go +++ b/tunnel/statistic/manager.go @@ -61,6 +61,7 @@ func (m *Manager) Now() (up int64, down int64) { } func (m *Manager) Memory() uint64 { + m.updateMemory() return m.memory } @@ -70,16 +71,6 @@ func (m *Manager) Snapshot() *Snapshot { connections = append(connections, value.(tracker)) return true }) - - getMem := func() uint64 { - stat, err := m.process.MemoryInfo() - if err != nil { - return 0 - } - return stat.RSS - } - m.memory = getMem() - return &Snapshot{ UploadTotal: m.uploadTotal.Load(), DownloadTotal: m.downloadTotal.Load(), @@ -88,6 +79,14 @@ func (m *Manager) Snapshot() *Snapshot { } } +func (m *Manager) updateMemory() { + stat, err := m.process.MemoryInfo() + if err != nil { + return + } + m.memory = stat.RSS +} + func (m *Manager) ResetStatistic() { m.uploadTemp.Store(0) m.uploadBlip.Store(0)