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 {
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)