How I can get the peak memory on Mac OS?

断了今生、忘了曾经 提交于 2020-05-25 19:56:19

问题


In Windows I can get the Peak Memory usage by calling GetProcessMemoryInfo

function TProcess.Peek: Cardinal;
var
  PMC: PPROCESS_MEMORY_COUNTERS;
  PMCSize: Cardinal;
begin
  PMCSize := SizeOf(PROCESS_MEMORY_COUNTERS);
  GetMem(PMC, PMCSize);
  try
    PMC^.cb := PMCSize;
    if GetProcessMemoryInfo(FHandle, PMC, PMCSize) then
      Exit(PMC^.PeakWorkingSetSize)
    else
      Exit(0);
  finally
    FreeMem(PMC);
  end;
end;

What is the Mac OS equivalent to do this?


回答1:


You can use /usr/bin/time -l <cmd> like this:

/usr/bin/time -l sleep 3
        3.00 real         0.00 user         0.00 sys
    552960  maximum resident set size                  <--- this one (in bytes)
         0  average shared memory size
         0  average unshared data size
         0  average unshared stack size
       144  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         0  block output operations
         0  messages sent
         0  messages received
         0  signals received
         0  voluntary context switches
         2  involuntary context switches


来源:https://stackoverflow.com/questions/12476804/how-i-can-get-the-peak-memory-on-mac-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!