add old lci module
This commit is contained in:
1 parent
38a6e815f0
commit
8499631091
171 files changed
+25562
No files matched your search
@@ -0,0 +1,21 @@
|
||||
#include "hd/mem.h"
|
||||
|
||||
/* 通过SysInfo接口获取内存使用情况 失败会返回NULL */
|
||||
MemoryInfo getMemoryUsageWithSysinfo() {
|
||||
MemoryInfo memInfo = {0};
|
||||
struct sysinfo si;
|
||||
|
||||
if (sysinfo(&si) == 0)
|
||||
{
|
||||
memInfo.totalMemory = si.totalram * si.mem_unit;
|
||||
memInfo.freeMemory = si.freeram * si.mem_unit;
|
||||
memInfo.usedMemory = memInfo.totalMemory - memInfo.freeMemory;
|
||||
|
||||
if (memInfo.totalMemory > 0)
|
||||
memInfo.usageRate = 100.0 * memInfo.usedMemory / memInfo.totalMemory;
|
||||
}
|
||||
else
|
||||
std::cerr << "sysinfo Call Failed" << std::endl;
|
||||
|
||||
return memInfo;
|
||||
}
|
||||
Reference in new issue
Block a user