Obtain the CPU clock speed (processor_power_information) in Windows)

Source: Internet
Author: User

I always wanted to get the CPU clock speed in windows. After searching for a long time, I finally found the callntpowerinformation function. To use it, I must first include powrprof. h header file and link library powerprof. lib. but there are several problems:

First, powrprof. h, like many other header files in the Platform SDK, is still not verified by C ++. If you are not careful about including the header files in the C ++ program, there will still be a link error. It is better to include it like this:

Extern "C "{
# Include <powrprof. h>
}
The second reason is that there is a structure that does not know why it is not included in powrprof. H. This structure is processor_power_information. This problem still exists in Visual C ++ 2008 express edition. To get the correct processor speed, call callntpowerinformation. The processorinformation enumeration value is the first parameter. An array of the processor_power_information structure is used as the output cache (corresponding to each processor chip installed in the system ).

One solution is: this structure is defined in msdn, so we can define it in our own file:

typedef struct _PROCESSOR_POWER_INFORMATION {  ULONG  Number;  ULONG  MaxMhz;  ULONG  CurrentMhz;  ULONG  MhzLimit;  ULONG  MaxIdleState;  ULONG  CurrentIdleState;} PROCESSOR_POWER_INFORMATION , *PPROCESSOR_POWER_INFORMATION;

 

From the definition of the processor_power_information structure, you can find that this structure provides CPU speed information, such as the maximum speed, current speed, there is a related API function getpwucapabilities with the idle status (although I admit that I do not know the idle status bit-I will solve it), which can also achieve some system performance.

 

 

 
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.