In Delphi I used:
procedure SwapUsage;
type
swapinfo = record
xsu_total : Int64;
xsu_avail : Int64;
xsu_used : Int64;
xsu_pagesize : Integer;
xsu_encrypted: Boolean;
end;
var
mib : array[0..1] of Integer;
status : Integer;
len : size_t;
swap : swapinfo;
begin
FillChar(swap, sizeof(swap), 0);
mib[0] := CTL_VM;
mib[1] := VM_SWAPUSAGE;
len := sizeof(swap);
status := SysCtl(@mib, Length(mib), @swap, @len, nil, 0);
if status <> 0 then RaiseLastOSError;
SwapTotal := (swap.xsu_total /1024 /1024);
SwapAvail := (swap.xsu_avail /1024 /1024);
SwapUsed := (swap.xsu_used /1024 /1024);
SwapPageSize := swap.xsu_pagesize;
if(swap.xsu_encrypted = true) then
SwapEncrypted := 'Yes' else SwapEncrypted := 'No';
end;
to determine swap stats. At the command line 'sysctl vm.swapusage' returns:
vm.swapusage: total = 1024.00M used = 191.00M free = 833.00M (encrypted)
which is what the above code does. Unfortunately, compiling it with Lazarus (after changing SysCtl to fpSysCtl) returns the error: VM_SWAPUSAGE identifier not found
Any ideas? (yes I have the SysCtl unit included)