MCPcopy Create free account
hub / github.com/daodst/chat / getMemoryStats

Function getMemoryStats

userapi/util/stats.go:27–47  ·  view source on GitHub ↗
(p *phoneHomeStats)

Source from the content-addressed store, hash-verified

25)
26
27func getMemoryStats(p *phoneHomeStats) error {
28 oldUsage := p.prevData
29 newUsage := syscall.Rusage{}
30 if err := syscall.Getrusage(syscall.RUSAGE_SELF, &newUsage); err != nil {
31 logrus.WithError(err).Error("unable to get usage")
32 return err
33 }
34 newData := timestampToRUUsage{timestamp: time.Now().Unix(), usage: newUsage}
35 p.prevData = newData
36
37 usedCPUTime := (newUsage.Utime.Sec + newUsage.Stime.Sec) - (oldUsage.usage.Utime.Sec + oldUsage.usage.Stime.Sec)
38
39 if usedCPUTime == 0 || newData.timestamp == oldUsage.timestamp {
40 p.stats["cpu_average"] = 0
41 } else {
42 // conversion to int64 required for GOARCH=386
43 p.stats["cpu_average"] = int64(usedCPUTime) / (newData.timestamp - oldUsage.timestamp) * 100
44 }
45 p.stats["memory_rss"] = newUsage.Maxrss
46 return nil
47}

Callers 1

collectMethod · 0.70

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected