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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM