Skip to content

Instantly share code, notes, and snippets.

@bitsnaps
Created June 9, 2016 23:13
Show Gist options
  • Save bitsnaps/7c1168a6c6534e51d63cf90664b1db7f to your computer and use it in GitHub Desktop.
Save bitsnaps/7c1168a6c6534e51d63cf90664b1db7f to your computer and use it in GitHub Desktop.
Memory and CPU usage (using MinGW in x64 windows machine)
#include <iostream>
#include "windows.h"
//Memory Usage
#include "psapi.h"
//CPU Usage
#include "TCHAR.h"
//1- assuming we are monitoring Windows machine
//2- consider to use Performance Data Helper library which is much more intuitive
using namespace std;
int main()
{
MEMORYSTATUSEX memInfo;
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo);
DWORDLONG totalVirtualMem = memInfo.ullTotalPageFile;
DWORDLONG virtualMemUsed = memInfo.ullTotalPageFile - memInfo.ullAvailPageFile;
DWORDLONG totalPhysMem = memInfo.ullTotalPhys;
DWORDLONG physMemUsed = memInfo.ullTotalPhys - memInfo.ullAvailPhys;
cout << "Virtual Memory: " << totalVirtualMem / (1024*1024) << endl;
cout << "Virtual Used Memory: " << virtualMemUsed / (1024*1024) << endl;
cout << "Physical Memory: " << totalPhysMem / (1024*1024) << endl;
cout << "Physical Memory Used: " << physMemUsed / (1024*1024) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment