Recent

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

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 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 »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
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/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 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 »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
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/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018