Module Proc.Self
Current process (self) statistics.
type t = {utime : float;(*Cumulative user-mode CPU time in seconds.
*)stime : float;(*Cumulative system-mode CPU time in seconds.
*)rss_bytes : int64;(*Resident set size (physical memory) in bytes.
*)vsize_bytes : int64;(*Virtual memory size in bytes.
*)
}Raw process snapshot for delta calculation.
Contains cumulative CPU time and instantaneous memory usage for the current process. CPU times are in seconds (converted from platform-specific units by Unix.times).
type stats = {cpu_percent : float;(*CPU usage percentage (0.0 to 100.0 per core, or total if
*)num_coresprovided).rss_bytes : int64;(*Resident set size in bytes.
*)vsize_bytes : int64;(*Virtual memory size in bytes.
*)
}Computed process statistics.
val sample : unit -> tsample () returns raw CPU times and memory usage for the current process.
Uses Unix.times for CPU times.
compute ~prev ~next ~dt ~num_cores computes CPU usage percentage between two samples.
CPU percentage is calculated as ((utime_delta + stime_delta) / dt) * 100. If num_cores is provided, the percentage is normalized by dividing by the number of cores, yielding a value in 0.0 to 100.0. Without normalization, the value can exceed 100.0 on multi-core systems.
The result is clamped to prevent spurious values from timing anomalies:
- With
num_cores: capped at100.0 - Without
num_cores: capped at800.0
If dt is outside the range (0.01, 10.0), returns 0.0 for cpu_percent to avoid division by near-zero or implausibly large intervals.