tags:

views:

595

answers:

5

What is best algorithm for calculating total CPU usage at a particular time during execution of a process.

I am working windows platform in C++.

+1  A: 

Intel VTune is a great tool for anaylzing cpu resources: http://www.intel.com/cd/software/products/asmo-na/eng/239144.htm

A: 

Use WMI to get "PercentProcessorTime"; beware that this will probably have its own performance penalty.

If you are looking to throttle your application, a better way it to have your own internal performance metric specific to your application and throttle based on that (e.g. screen refresh rate, etc.)

Nick
+1  A: 

GetProcessTimes for 100-nanosecond resolution. If you want cycle times, use QueryProcessCycleTime in Vista and above.

MSN

MSN
A: 

Don't use WMI Simply Use win32 NAPI

Uhm... that's was a helpful answer. Could you please elaborate?
Johann Gerell
A: 

Let me recommend you this great article: http://www.codeproject.com/KB/threads/Get_CPU_Usage.aspx

I'm sure you'll find it useful.

David Alfonso