title: Get Memory Ram and CPU Usage from process
body: <p>How i can get memory ram and cpu usage used of my process? not from entire CPU.</p>
  
  <p>all codes who i search on internet always retrieve from entire CPU, but i need retrieve these informations from my own process.</p>
  
  <p>i'm using delphi 10.1</p>
  
  <p>these code above who i did with others examples show very near the real memory usage:</p>
  
  <pre><code>var
    ProcHand        : THandle;
    i               : integer;
    WorkingSet      : array[0..$3FFF - 1] of DWORD;
    Shared, Privates, total : Integer;
  begin
    ProcHand := OpenProcess(PROCESS_ALL_ACCESS, False, GetCurrentProcessId);
  
    Shared    := 0;
    Privates  := 0;
    total     := 0;
  
    if QueryWorkingSet(ProcHand, @WorkingSet, SizeOf(WorkingSet)) then
    begin
      for I := 1 to WorkingSet[0] do
      begin
        if ((WorkingSet[I] and $00000FFF) and $100 &lt;&gt; 0) then Inc(Shared) else Inc(Privates);
  
        Application.ProcessMessages;
      end;
    end;
  
    total     := WorkingSet[0] * 4;
    Shared    := Shared * 4;
  
    Result := Format('%.2f e %f &gt; Memory %.2f', [total / 1024, shared / 1024, ((total / 1024) - (shared / 1024))]);
  
    CloseHandle(ProcHand);
  </code></pre>
  
  <p>the code are based on <a href="https://www.codeproject.com/Articles/87529/Calculate-Memory-Working-Set-Private-Programmatica" rel="nofollow noreferrer">https://www.codeproject.com/Articles/87529/Calculate-Memory-Working-Set-Private-Programmatica</a></p>