chore: better memory fetching time

This commit is contained in:
Skyxim 2023-04-27 06:55:53 +00:00
parent e4f762822a
commit 928dcf9af9

View file

@ -61,6 +61,7 @@ func (m *Manager) Now() (up int64, down int64) {
} }
func (m *Manager) Memory() uint64 { func (m *Manager) Memory() uint64 {
m.updateMemory()
return m.memory return m.memory
} }
@ -70,16 +71,6 @@ func (m *Manager) Snapshot() *Snapshot {
connections = append(connections, value.(tracker)) connections = append(connections, value.(tracker))
return true return true
}) })
getMem := func() uint64 {
stat, err := m.process.MemoryInfo()
if err != nil {
return 0
}
return stat.RSS
}
m.memory = getMem()
return &Snapshot{ return &Snapshot{
UploadTotal: m.uploadTotal.Load(), UploadTotal: m.uploadTotal.Load(),
DownloadTotal: m.downloadTotal.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() { func (m *Manager) ResetStatistic() {
m.uploadTemp.Store(0) m.uploadTemp.Store(0)
m.uploadBlip.Store(0) m.uploadBlip.Store(0)