-1

This is the same question as this which has been marked as duplicate of this accepted answer. I have tested this accepted answer, and believe it only finds the CPU usage percentage relative to 1 CPU:

function wsGetCpuUsage(aCounter:PCPUUsageData):single;
var
    mCreationTime,mExitTime,mKernelTime, mUserTime:_FILETIME;
    DeltaMs,ThisTime:cardinal;
    mKernel,mUser,mDelta:int64;
begin
    result:=aCounter.LastUsage;
    ThisTime:=GetTickCount; //Get the time elapsed since last query

    DeltaMs:=ThisTime-aCounter.LastUpdateTime;
    if DeltaMs < wsMinMeasurementInterval then exit;
      aCounter.LastUpdateTime:=ThisTime;

    GetProcessTimes(aCounter.Handle,mCreationTime, mExitTime, mKernelTime, mUserTime);
    //convert _FILETIME to Int64.
    mKernel:=int64(mKernelTime.dwLowDateTime or (mKernelTime.dwHighDateTime shr 32));
    mUser:=int64(mUserTime.dwLowDateTime or (mUserTime.dwHighDateTime shr 32));
    //get the delta
    mDelta:=mUser+mKernel-aCounter.oldUser-aCounter.oldKernel;

    aCounter.oldUser:=mUser;
    aCounter.oldKernel:=mKernel;

    Result:=(mDelta/DeltaMs)/100;
    //mDelta is in units of 100 nanoseconds, so…

    aCounter.LastUsage:=Result;
    //just in case you want to use it later, too
end;

Here is the question as I understand: We want the CPU usage of the current process for any number of CPUs, as seen in the Windows Task Manager.

Community
  • 1
  • 1
  • 2
    Besides, [the question](http://stackoverflow.com/questions/33571061/get-the-percentage-of-total-cpu-usage) specifically asks how to get the *total* CPU usage, not the usage of a single process, so you haven't even answered the question you set out to answer anyway. – Rob Kennedy Nov 06 '15 at 22:10

0 Answers0