Closed heixiaoma closed 8 months ago
What tool are you using ? iSH Shell or else? And could you share a reproducible source code?
I think we can close this issue now. I am using version v3 and this problem no longer occurs. Thank you for your reply, buddy
func SysInfo() string {
defer func() {
if err := recover(); err != nil {
}
}()
info := bean.SysInfo{}
v, err := mem.VirtualMemory()
if err == nil {
info.TotalMem = v.Total
info.UseMem = v.Used
}
start, err := cpu.Times(false)
if err == nil {
var totalUsed float64
// 计算每个 CPU 核心的使用率并相加
for i := range start {
totalUsed += (start[i].Total() - start[i].Idle) / start[i].Total()
}
info.CpuRate = (totalUsed / float64(len(start))) * 100.0
}
var m runtime.MemStats
runtime.ReadMemStats(&m)
// 程序占用的总内存
totalMemory := m.Sys
// 程序当前使用的内存
usedMemory := m.Alloc
info.HpTotalMem = float64(totalMemory)
info.HpUseMem = float64(usedMemory)
marshal, _ := json.Marshal(info)
return string(marshal)
}
I will encounter this issue with the v2 version of the same code, but not with v3
app logo
I think we can close this issue now. I am using version v3 and this problem no longer occurs.
Thank you for the information and code. v2 is not maintained anymore.
device:iphone 14 pro