永发信息网

如何获取APP运行时的内存使用情况

答案:2  悬赏:20  手机版
解决时间 2021-03-17 04:36
  • 提问者网友:箛茗
  • 2021-03-16 04:19
如何获取APP运行时的内存使用情况
最佳答案
  • 五星知识达人网友:不甚了了
  • 2021-03-16 05:00
bool UserProfile::GetMemory(double & free2, double & total2)
{
size_t length;
int mib[6];
int result;

int pagesize;
mib[0] = CTL_HW;
mib[1] = HW_PAGESIZE;
length = sizeof(pagesize);
if (sysctl(mib, 2, &pagesize, &length, NULL, 0) < 0)
{
perror("getting page size");
}

mach_msg_type_number_t count = HOST_VM_INFO_COUNT;

vm_statistics_data_t vmstat;
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) != KERN_SUCCESS)
{
//RayLog("Failed to get VM statistics.");
}

double total = vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count;
double wired = vmstat.wire_count / total;
double active = vmstat.active_count / total;
double inactive = vmstat.inactive_count / total;
double free = vmstat.free_count / total;

mib[0] = CTL_HW;
mib[1] = HW_PHYSMEM;
length = sizeof(result);
if (sysctl(mib, 2, &result, &length, NULL, 0) < 0)
{
perror("getting physical memory");
}
mib[0] = CTL_HW;
mib[1] = HW_USERMEM;
length = sizeof(result);
if (sysctl(mib, 2, &result, &length, NULL, 0) < 0)
{
perror("getting user memory");
}

free2 = vmstat.free_count * pagesize;
total2 = total * pagesize;

return true;
}
全部回答
  • 1楼网友:一袍清酒付
  • 2021-03-16 05:47
/proc/进程pid/status这个文件里
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯