sysinfo function
Return system information.
Implementation
Sysinfo sysinfo() {
_sysinfo ??= Libc().dylib.lookupFunction<
ffi.Int32 Function(ffi.Pointer<_sysinfo_t> __info),
_dart_sysinfo>('sysinfo');
final ptr = ffi.malloc<_sysinfo_t>();
final res = _sysinfo!(ptr);
if (res != 0) {
ffi.malloc.free(ptr);
throw PosixException('sysinfo call failed', errno());
}
final info = Sysinfo(
uptime: Duration(seconds: ptr.ref.uptime),
loads: [ptr.ref.loads[0], ptr.ref.loads[1], ptr.ref.loads[2]],
totalram: ptr.ref.totalram,
sharedram: ptr.ref.sharedram,
bufferram: ptr.ref.bufferram,
totalswap: ptr.ref.totalswap,
freeswap: ptr.ref.freeswap,
procs: ptr.ref.procs,
totalhigh: ptr.ref.totalhigh,
freehigh: ptr.ref.freehigh,
mem_unit: ptr.ref.mem_unit,
);
ffi.malloc.free(ptr);
return info;
}