silk.system.system_info_native.
The native provider of the SystemInfo effect: facts about the computer and the process from
the C library and the kernel.
When to use#
Provide OsSystemInfo for SystemInfo in a native program. In a test, provide a fake with
fixed values.
Details#
Each operation makes a few system calls and returns: none of them waits for an event. On Linux,
the provider reads /proc, /sys, uname, getifaddrs, getpwuid_r, getrusage, and
sched_getaffinity. On macOS, it uses sysctl, the Mach host and task calls, getifaddrs,
getpwuid_r, and getrusage. Every list and copy that the system gives is freed before the
operation returns, also on errors.
Gotchas#
The memory limit of a control group is read from cgroup v2
memory.maxor cgroup v1memory.limit_in_bytes. Other limits, such asulimit, are not reported.The provider exists on Darwin on x86_64 or aarch64, and on GNU Linux on x86_64 or aarch64.
Examples#
Read the processors and the user#
import silk.collections.bytes { Bytes }
import silk.collections.list { List }
import silk.core.effect { Effect }
import silk.core.result { Result }
import silk.mem.allocator { Allocator, OutOfMemoryError }
import silk.system.system_info { ProcessorInfo, SystemInfo, SystemInfoError }
import silk.system.system_info_native { OsSystemInfo }
effect fn program() -> i32 ! SystemInfoError | OutOfMemoryError ? &mut SystemInfo | &mut Allocator {
let processors = run SystemInfo.processors()
let parallelism = run SystemInfo.availableParallelism()
if List<ProcessorInfo>.length(&processors) == 0 || parallelism == 0 {
return 1
}
let user = run SystemInfo.currentUser()
if Bytes.length(&user.name) == 0 {
return 1
}
return 0
}
pub effect fn main() -> i32 {
let mut allocator = Allocator.systemAllocatorProvider()
let mut provider = OsSystemInfo.make()
let result = run Effect.result(program()) |> Effect.provideMut<SystemInfo>(&mut provider)
|> Effect.provideMut<Allocator>(&mut allocator)
return match move result {
Result<i32, SystemInfoError | OutOfMemoryError>.Success { value } => value
Result<i32, SystemInfoError | OutOfMemoryError>.Failure { .. } => 1
}
}Import as OsSystemInfo with import silk.system.system_info_native { OsSystemInfo }.
Public declarations: 1.
OsSystemInfo#
pub struct OsSystemInfoThe native SystemInfo provider. It has no state.
Details#
On Linux, it reads /proc, /sys, uname, getifaddrs, getpwuid_r, getrusage, and
sched_getaffinity. On macOS, it uses sysctl, the Mach host and task calls, getifaddrs,
getpwuid_r, and getrusage. No operation waits for an event.
Gotchas#
The memory limit of a control group is read from cgroup v2
memory.maxor cgroup v1memory.limit_in_bytes. Other limits, such asulimit, are not reported.The provider exists on Darwin on x86_64 or aarch64, and on GNU Linux on x86_64 or aarch64.
Implementation OsSystemInfo#
impl OsSystemInfoAssociated function make#
pub fn make() -> OsSystemInfoReturns the provider. It makes no system call.
Implementation SystemInfo for OsSystemInfo#
impl SystemInfo for OsSystemInfoOperation hostName#
effect fn hostName(self: &mut Self) -> Bytes ! SystemInfoError | OutOfMemoryError ? &mut AllocatorOperation kernel#
effect fn kernel(self: &mut Self) -> KernelInfo ! SystemInfoError | OutOfMemoryError ? &mut AllocatorOperation uptime#
effect fn uptime(self: &mut Self) -> u64 ! SystemInfoErrorOperation loadAverage#
effect fn loadAverage(self: &mut Self) -> [f64; 3] ! SystemInfoErrorOperation memory#
effect fn memory(self: &mut Self) -> MemoryInfo ! SystemInfoErrorOperation processors#
effect fn processors(self: &mut Self) -> List<ProcessorInfo> ! SystemInfoError | OutOfMemoryError ? &mut AllocatorOperation availableParallelism#
effect fn availableParallelism(self: &mut Self) -> usize ! SystemInfoErrorOperation networkInterfaces#
effect fn networkInterfaces(self: &mut Self) -> List<NetworkInterface> ! SystemInfoError | OutOfMemoryError ? &mut AllocatorOperation currentUser#
effect fn currentUser(self: &mut Self) -> UserInfo ! SystemInfoError | OutOfMemoryError ? &mut AllocatorOperation user#
effect fn user(self: &mut Self, uid: u32) -> UserInfo ! SystemInfoError | OutOfMemoryError ? &mut AllocatorOperation priority#
effect fn priority(self: &mut Self, pid: i32) -> i32 ! SystemInfoErrorOperation setPriority#
effect fn setPriority(self: &mut Self, pid: i32, value: i32) -> () ! SystemInfoErrorOperation resourceUsage#
effect fn resourceUsage(self: &mut Self, scope: UsageScope) -> ResourceUsage ! SystemInfoErrorOperation residentSetSize#
effect fn residentSetSize(self: &mut Self) -> u64 ! SystemInfoErrorOperation executablePath#
effect fn executablePath(self: &mut Self) -> Bytes ! SystemInfoError | OutOfMemoryError ? &mut AllocatorOperation processId#
effect fn processId(self: &mut Self) -> i32Operation parentProcessId#
effect fn parentProcessId(self: &mut Self) -> i32Category: System.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, x86_64-unknown-linux-gnu.