mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
chore: better memory fetching time
This commit is contained in:
parent
e4f762822a
commit
928dcf9af9
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user