Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PowerInformation.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <Windows.h>
- #include <process.h>
- #include <signal.h>
- #include <NTstatus.h>
- #include <Powrprof.h>
- #include <iostream>
- #define WIN32_NO_STATUS
- typedef struct _PROCESSOR_POWER_INFORMATION {
- ULONG Number;
- ULONG MaxMhz;
- ULONG CurrentMhz;
- ULONG MhzLimit;
- ULONG MaxIdleState;
- ULONG CurrentIdleState;
- } PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;
- using namespace std;
- static void startMonitoringCoreSpeeds(void *param)
- {
- while (true)
- {
- // get the number or processors
- SYSTEM_INFO si = { 0 };
- ::GetSystemInfo(&si);
- // allocate buffer to get info for each processor
- const int size = si.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION);
- LPBYTE pBuffer = new BYTE[size];
- NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, pBuffer, size);
- if (STATUS_SUCCESS == status)
- {
- // list each processor frequency
- PPROCESSOR_POWER_INFORMATION ppi = (PPROCESSOR_POWER_INFORMATION)pBuffer;
- for (DWORD nIndex = 0; nIndex < si.dwNumberOfProcessors; nIndex++)
- {
- std::cout << "Processor #" << ppi->Number << " frequency: "
- << ppi->CurrentMhz << " MHz" << std::endl;
- ppi++;
- }
- }
- else
- {
- std::cout << "CallNtPowerInformation failed. Status: " << status << std::endl;
- }
- delete[]pBuffer;
- Sleep(1000);
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- _beginthread(startMonitoringCoreSpeeds, 0, NULL);
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement