package kaun-board

  1. Overview
  2. Docs

Module Proc.TableSource

Process table statistics.

Sourcetype t = {
  1. pid : int;
    (*

    Process ID.

    *)
  2. ppid : int;
    (*

    Parent process ID.

    *)
  3. name : string;
    (*

    Process name (comm).

    *)
  4. cmdline : string;
    (*

    Full command line with arguments. Empty if unavailable.

    *)
  5. state : state;
    (*

    Current process state.

    *)
  6. user : string;
    (*

    Owner username. Empty if UID lookup fails.

    *)
  7. priority : int;
    (*

    Scheduling priority.

    *)
  8. nice : int;
    (*

    Nice value (-20 to 19).

    *)
  9. user_time : int64;
    (*

    Cumulative user-mode CPU time in ticks.

    *)
  10. system_time : int64;
    (*

    Cumulative system-mode CPU time in ticks.

    *)
  11. resident_size : int64;
    (*

    Resident set size in bytes.

    *)
  12. virtual_size : int64;
    (*

    Virtual memory size in bytes.

    *)
  13. num_threads : int;
    (*

    Number of threads.

    *)
  14. num_running : int;
    (*

    Number of running threads (macOS only, 0 on Linux).

    *)
  15. faults : int64;
    (*

    Page faults (macOS only, 0L on Linux).

    *)
  16. mem_percent : float;
    (*

    Memory usage as percentage of total physical memory.

    *)
}

Raw process snapshot for delta calculation.

Contains cumulative CPU time, state, and instantaneous memory/thread information for a process. CPU times are in platform-specific ticks (Linux jiffies or macOS Mach ticks).

Sourcetype stats = {
  1. pid : int;
    (*

    Process ID.

    *)
  2. name : string;
    (*

    Process name.

    *)
  3. cpu_percent : float;
    (*

    CPU usage percentage between samples.

    *)
  4. mem_percent : float;
    (*

    Memory usage as percentage of total physical memory.

    *)
  5. rss_bytes : int64;
    (*

    Resident set size in bytes.

    *)
}

Computed process statistics.

Contains derived CPU percentage and filtered memory information. Only processes with non-zero CPU or memory usage are included.

Sourceval sample : unit -> t list

sample () returns raw process snapshots for all running processes.

Enumerates all processes visible to the current user and reads their statistics.

Returns an empty list if an error occurs during enumeration. Individual process errors (e.g., process termination during sampling) are silently skipped.

Sourceval compute : prev:t list -> next:t list -> dt:float -> stats list

compute ~prev ~next ~dt calculates CPU percentages and filters processes.

Matches processes by PID between prev and next samples. For matched processes, computes CPU percentage as: (cpu_time_delta_ns / interval_ns) * 100.

Only processes with non-zero cpu_percent or mem_percent are included in the result. New processes (in next but not prev) are included if their mem_percent is non-zero, with cpu_percent set to 0.0.