Может быть, я упускаю суть, но, похоже, популярный способ выяснить это — запросить процессор два раза с интервалом не менее 200 мс между каждой проверкой, чтобы избежать проблем с чем-то, называемым... разрешением? Так да! Как, черт возьми, мне это сделать?
Я поделюсь своим исходным кодом, чтобы вы могли увидеть, что именно. До сих пор я это делал. Это все в одном .cpp, я использую VS2013 Express для C++, и он предназначен только для Windows для многоядерных процессоров.
Предупреждаем заранее: мне очень жаль за все комментарии в коде
//included libraries/functionality for input/output
#include
#include
#include
using namespace std;
//creates a static variable to convert Bytes to Megabytes
#define MB 1048576
//main program code loop
int main()
{
//Code block intiialization for the memory referenced in the Kernell
MEMORYSTATUSEX memStat;
memStat.dwLength = sizeof (memStat);
GlobalMemoryStatusEx(&memStat);
//loads the SYSTEMTIME
SYSTEMTIME sysTime;
//Retrieves data so that we have a way to Get it to output when using the pointers
GetSystemTime(&sysTime);
//setting the I/O for our log file to be "myfile"
ofstream myfile;
// ios::out means that we're outputting data to the file
// ios::app means that all the data we're outputting goes to the end of that log file instead of the start
myfile.open("log.csv", ios::out | ios::app);
//a while loop that gathers and logs data every quarter of a second to gather 4 data points in one second
int counter = 0;
while (counter < 4)
{
//Timestamp + Memory Info, and eventually CPU Load percentage
myfile
Подробнее здесь: https://stackoverflow.com/questions/231 ... ows-with-c
Мобильная версия