feat: core support memory chat

This commit is contained in:
rookisbusy
2023-04-08 00:55:25 +08:00
parent eecd8fff71
commit 76340cc99c
2 changed files with 55 additions and 1 deletions

View File

@ -34,6 +34,7 @@ type Manager struct {
uploadTotal *atomic.Int64
downloadTotal *atomic.Int64
pid int
memory uint64
}
func (m *Manager) Join(c tracker) {
@ -58,6 +59,10 @@ func (m *Manager) Now() (up int64, down int64) {
return m.uploadBlip.Load(), m.downloadBlip.Load()
}
func (m *Manager) Memory() uint64 {
return m.memory
}
func (m *Manager) Snapshot() *Snapshot {
connections := []tracker{}
m.connections.Range(func(key, value any) bool {
@ -76,12 +81,13 @@ func (m *Manager) Snapshot() *Snapshot {
}
return stat.RSS
}
m.memory = getMem()
return &Snapshot{
UploadTotal: m.uploadTotal.Load(),
DownloadTotal: m.downloadTotal.Load(),
Connections: connections,
Memory: getMem(),
Memory: m.memory,
}
}