TermUI.Widgets.ProcessMonitor (TermUI v0.2.0)

View Source

ProcessMonitor widget for live BEAM process inspection.

ProcessMonitor displays live process information including PID, name, reductions, memory, and message queue depth. It provides controls for process management and debugging.

Usage

ProcessMonitor.new(
  update_interval: 1000,
  show_system_processes: false
)

Features

  • Live process list with PID, name, reductions, memory
  • Configurable update interval
  • Message queue depth display with warnings
  • Process links/monitors visualization
  • Stack trace display
  • Process actions (kill, suspend, resume)
  • Sorting by any field
  • Filtering by name/module

Keyboard Controls

  • Up/Down: Move selection
  • PageUp/PageDown: Scroll by page
  • Enter: Toggle details panel
  • r: Refresh now
  • s: Cycle sort field
  • S: Toggle sort direction
  • /: Start filter input
  • k: Kill selected process (with confirmation)
  • p: Pause/resume selected process
  • l: Show links/monitors
  • t: Show stack trace
  • Escape: Clear filter/close details

Summary

Functions

Get currently selected process.

Get stack trace for a process.

Creates new ProcessMonitor widget props.

Get process count.

Force refresh the process list.

Set filter pattern.

Set the update interval.

Set sorting options.

Types

process_info()

@type process_info() :: %{
  pid: pid(),
  registered_name: atom() | nil,
  initial_call: {module(), atom(), arity()} | nil,
  current_function: {module(), atom(), arity()} | nil,
  reductions: non_neg_integer(),
  memory: non_neg_integer(),
  message_queue_len: non_neg_integer(),
  status: atom(),
  links: [pid()],
  monitors: [term()],
  monitored_by: [pid()],
  stack_trace: [term()] | nil
}

sort_direction()

@type sort_direction() :: :asc | :desc

sort_field()

@type sort_field() :: :pid | :name | :reductions | :memory | :queue | :status

thresholds()

@type thresholds() :: %{
  queue_warning: non_neg_integer(),
  queue_critical: non_neg_integer(),
  memory_warning: non_neg_integer(),
  memory_critical: non_neg_integer()
}

Functions

get_selected(state)

@spec get_selected(map()) :: process_info() | nil

Get currently selected process.

get_stack_trace(pid)

@spec get_stack_trace(pid()) :: [term()] | nil

Get stack trace for a process.

new(opts)

@spec new(keyword()) :: map()

Creates new ProcessMonitor widget props.

Options

  • :update_interval - Refresh interval in ms (default: 1000)
  • :show_system_processes - Include system processes (default: false)
  • :thresholds - Warning thresholds map
  • :on_select - Callback when process is selected
  • :on_action - Callback when action is performed

process_count(state)

@spec process_count(map()) :: non_neg_integer()

Get process count.

refresh(state)

@spec refresh(map()) :: {:ok, map()}

Force refresh the process list.

set_filter(state, filter)

@spec set_filter(map(), String.t() | nil) :: {:ok, map()}

Set filter pattern.

set_interval(state, interval)

@spec set_interval(map(), non_neg_integer()) :: {:ok, map()}

Set the update interval.

set_sort(state, field, direction)

@spec set_sort(map(), sort_field(), sort_direction()) :: {:ok, map()}

Set sorting options.