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++.
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++.
Intel VTune is a great tool for anaylzing cpu resources: http://www.intel.com/cd/software/products/asmo-na/eng/239144.htm
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.)
GetProcessTimes
for 100-nanosecond resolution. If you want cycle times, use QueryProcessCycleTime
in Vista and above.
MSN
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.