Search code examples
delphicpudelphi-xeperformancecounter

Get the Percentage of Total CPU Usage


I am trying to get the % of total CPU usage to a label1.Caption

I've searched and found these:

enter image description here

I believe there is a simple way like when we get RAM usage.

 GlobalMemoryStatus(RamStats);
 Label1.Caption := Format('RAM: %d %%', [RamStats.dwMemoryLoad]);

Solution

  • I found t h i s

    does the job

    uses adCpuUsage;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
    i:integer;
    u:string;
    begin
      collectcpudata;
       for i:=0 to GetCPUCount-1 do
    
     u:=FloatToStr(Round(getcpuusage(i)*100));   //Round to approximate 1.0003 to 1
    
    label1.Caption:=u
    end;
    
    end.
    

    worked for me enter image description here