Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. // PowerInformation.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <Windows.h>
  6. #include <process.h>
  7. #include <signal.h>
  8. #include <NTstatus.h>
  9. #include <Powrprof.h>
  10. #include <iostream>
  11.  
  12. #define WIN32_NO_STATUS
  13.  
  14. typedef struct _PROCESSOR_POWER_INFORMATION {
  15.     ULONG  Number;
  16.     ULONG  MaxMhz;
  17.     ULONG  CurrentMhz;
  18.     ULONG  MhzLimit;
  19.     ULONG  MaxIdleState;
  20.     ULONG  CurrentIdleState;
  21. } PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;
  22.  
  23. using namespace std;
  24.  
  25. static void startMonitoringCoreSpeeds(void *param)
  26. {
  27.     while (true)
  28.     {
  29.         // get the number or processors
  30.         SYSTEM_INFO si = { 0 };
  31.         ::GetSystemInfo(&si);
  32.         // allocate buffer to get info for each processor
  33.         const int size = si.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION);
  34.         LPBYTE pBuffer = new BYTE[size];
  35.  
  36.         NTSTATUS status = ::CallNtPowerInformation(ProcessorInformation, NULL, 0, pBuffer, size);
  37.         if (STATUS_SUCCESS == status)
  38.         {
  39.             // list each processor frequency
  40.             PPROCESSOR_POWER_INFORMATION ppi = (PPROCESSOR_POWER_INFORMATION)pBuffer;
  41.             for (DWORD nIndex = 0; nIndex < si.dwNumberOfProcessors; nIndex++)
  42.             {
  43.                 std::cout << "Processor #" << ppi->Number << " frequency: "
  44.                     << ppi->CurrentMhz << " MHz" << std::endl;
  45.                 ppi++;
  46.             }
  47.         }
  48.         else
  49.         {
  50.             std::cout << "CallNtPowerInformation failed. Status: " << status << std::endl;
  51.         }
  52.         delete[]pBuffer;
  53.         Sleep(1000);
  54.     }
  55. }
  56.  
  57. int _tmain(int argc, _TCHAR* argv[])
  58. {
  59.     _beginthread(startMonitoringCoreSpeeds, 0, NULL);
  60.     cin.get();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement