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++.
// Declare
PerformanceCounter cpuCounter = null;
// initialize somewhere in the constructor..
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
Then to get the CPU usage in % just call
cpuCounter.NextValue()
Source:http://zamov.online.fr/EXHTML/CSharp/CSharp_927308.html