Recent

Author Topic: [SOLVED] macOS VM_SWAPUSAGE  (Read 484 times)

trev

  • Sr. Member
  • ****
  • Posts: 350
  • Former Delphi 7 and Delphi 10.2 User
[SOLVED] macOS VM_SWAPUSAGE
« on: June 22, 2019, 09:21:48 am »
In Delphi I used:

Code: Pascal  [Select]
  1. procedure SwapUsage;
  2. type
  3.  swapinfo = record
  4.     xsu_total    : Int64;
  5.     xsu_avail    : Int64;
  6.     xsu_used     : Int64;
  7.     xsu_pagesize : Integer;
  8.     xsu_encrypted: Boolean;
  9. end;
  10.  
  11. var
  12.   mib : array[0..1] of Integer;
  13.   status : Integer;
  14.   len : size_t;
  15.   swap : swapinfo;
  16. begin
  17.   FillChar(swap, sizeof(swap), 0);
  18.   mib[0] := CTL_VM;
  19.   mib[1] := VM_SWAPUSAGE;
  20.   len := sizeof(swap);
  21.   status := SysCtl(@mib, Length(mib), @swap, @len, nil, 0);
  22.   if status <> 0 then RaiseLastOSError;
  23.  
  24.   SwapTotal := (swap.xsu_total /1024 /1024);
  25.   SwapAvail := (swap.xsu_avail /1024 /1024);
  26.   SwapUsed :=  (swap.xsu_used /1024 /1024);
  27.   SwapPageSize := swap.xsu_pagesize;
  28.   if(swap.xsu_encrypted = true) then
  29.     SwapEncrypted := 'Yes' else SwapEncrypted := 'No';
  30. end;
  31.  

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)
« Last Edit: June 22, 2019, 11:21:15 am by trev »
o Lazarus v2.1.0 r62452, FPC v3.3.1 r42644, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

lucamar

  • Hero Member
  • *****
  • Posts: 2271
Re: macOS VM_SWAPUSAGE
« Reply #1 on: June 22, 2019, 10:04:06 am »
Sounds like VM_SWAPUSAGE is not declared anywhere.

It's just an integer, isn't it? You can copy the value over from Delphi or from Apple's docs/headers.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

trev

  • Sr. Member
  • ****
  • Posts: 350
  • Former Delphi 7 and Delphi 10.2 User
Re: macOS VM_SWAPUSAGE
« Reply #2 on: June 22, 2019, 11:21:28 am »
Perfect: const VM_SWAPUSAGE = 5;

Thanks!
« Last Edit: June 22, 2019, 11:26:18 am by trev »
o Lazarus v2.1.0 r62452, FPC v3.3.1 r42644, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

lucamar

  • Hero Member
  • *****
  • Posts: 2271
Re: [SOLVED] macOS VM_SWAPUSAGE
« Reply #3 on: June 22, 2019, 12:38:02 pm »
Glad it helped :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.