windows查看C++当前进程运行内存占用情况

最近需要查看代码允许过程中内存占用情况,这里利用Windows API获取当前进程占用内存情况,另外也可以借助Intel VTune Profiler工具(更加方便)和Visual Studio一起配合使用,便于查看程序运行时的热点、耗时等。

Windows API代码

#include<psapi.h>

void showMemoryInfo() {
  HANDLE handle = GetCurrentProcess();
  PROCESS_MEMORY_COUNTERS pmc;
  GetProcessMemoryInfo(handle, &pmc, sizeof(pmc));
  std::string strs;
  LOG_PRINT("memory used %d M/ %d M  +  usage %d M/ %d M", pmc.WorkingSetSize / 1024 / 1024, pmc.PeakWorkingSetSize / 1024/1024, pmc.PagefileUsage / 1024 / 1024, pmc.PeakPagefileUsage / 1024 / 1024);
}

参考链接

https://blog.csdn.net/springontime/article/details/80625850

https://docs.csc.fi/apps/vtune/

posted @ 2022-06-14 22:02  半夜打老虎  阅读(2138)  评论(0)    收藏  举报