Skip to main content

Row

Struct Row 

Source
pub struct Row {
Show 48 fields pub pid: Pid, pub ppid: Pid, pub pgrp: Pid, pub session: Pid, pub tty_nr: i64, pub tpgid: i64, pub starttime: u64, pub tgid: Pid, pub is_thread: bool, pub thread_id: Option<u64>, pub comm: CommBuf, pub state: u8, pub uid: u32, pub user: Option<u32>, pub priority: i8, pub nice: i8, pub processor: i32, pub nlwp: i32, pub sched_policy: u8, pub ticks: CpuTicks, pub prev_ticks: CpuTicks, pub min_flt: u64, pub maj_flt: u64, pub virt: u64, pub res: u64, pub percent_cpu: f32, pub percent_mem: f32, pub time_ticks: u64, pub elapsed: u64, pub cmdline: Option<Box<str>>, pub exe: Option<Box<str>>, pub cwd: Option<Box<str>>, pub pss: Option<u64>, pub epss: Option<u64>, pub private: Option<u64>, pub swap_bytes: Option<u64>, pub gpu_percent: Option<f32>, pub gpu_ns: Option<u64>, pub cpu_delay_percent: Option<f32>, pub io_delay_percent: Option<f32>, pub swap_delay_percent: Option<f32>, pub cgroup: Option<Box<str>>, pub container: Option<Box<str>>, pub container_runtime: Option<Box<str>>, pub depth: u16, pub has_children: bool, pub is_last_child: bool, pub flags: RowFlags,
}
Expand description

One process, as sampled during a single tick.

Invariant: Row stores raw scalars and interned strings only. Any String produced by format! during a scan is a bug — see docs/DESIGN.md §9.4. Human-readable text is produced by the renderer through crate::format.

Fields§

§pid: Pid§ppid: Pid§pgrp: Pid§session: Pid§tty_nr: i64§tpgid: i64

The process group the controlling terminal is currently signalling.

Equal to pgrp unless a job has the terminal in the foreground, which is the one distinction this column exists to show.

-1 is what the kernel reports when the terminal has no foreground job, and it is also what a thread row carries. The renderer shows - for it rather than the number: -1 is a wire value, not a process group.

§starttime: u64

Field 22 of /proc/<pid>/stat: cache key and PID-reuse detector.

§tgid: Pid

Thread group id: the pid of the process this row belongs to.

For a process this equals pid. For a thread it is the leader’s pid, which is what lets the table nest threads under their process and keep the selection stable while thread enumeration is toggled.

§is_thread: bool

True when this row is a thread rather than a process.

Kept separate from RowFlags::USERLAND_THREAD because that flag answers “is this a userland thread” for display purposes, while this answers a structural question the table has to get right.

§thread_id: Option<u64>

Identity of a thread row, unique across the whole table.

For a process row this is None and pid is the identity. For a thread it is Some, because on macOS a thread has no pid of its own: pth handles are 64-bit (95% exceed u32) and are not globally unique (every process reports the same handle for its main thread). Linux threads do have a tid that fits in pid, but it can coincide with an unrelated process’s pid, so thread rows use this on both platforms.

§comm: CommBuf

ArrayString<64>: no heap allocation per scanned process.

§state: u8§uid: u32§user: Option<u32>§priority: i8§nice: i8§processor: i32§nlwp: i32§sched_policy: u8§ticks: CpuTicks

Raw tick counters, current and previous sample.

§prev_ticks: CpuTicks§min_flt: u64§maj_flt: u64§virt: u64

Virtual and resident size in bytes.

§res: u64§percent_cpu: f32

Derived values, computed at sample time (not at render time).

§percent_mem: f32§time_ticks: u64

utime + stime in ticks, kept for the TIME column.

§elapsed: u64

Seconds since process start.

§cmdline: Option<Box<str>>

Lazily loaded, cached until the process exits.

§exe: Option<Box<str>>§cwd: Option<Box<str>>

The process’s working directory, read from /proc/<pid>/cwd or, on macOS, from proc_pidinfo(PROC_PIDVNODEPATHINFO).

Cached with the identity because a readlink per row per tick is thousands of syscalls for a value that changes rarely — even though, unlike exe, it can change. Accepting a stale value until the process exits is the same trade htop makes.

§pss: Option<u64>

Proportional set size, from /proc/<pid>/smaps_rollup, in bytes.

None means “not read”, not “zero”: the file is expensive enough that it is only opened when a column needing it is visible, and another user’s process may refuse to be read at all. The renderer shows - for None and a real figure for Some(0).

RSS counts a shared page once per process, so two processes sharing 100 MB of libraries report 100 MB each and the machine appears to use 200 MB. PSS splits that page between them, which is the only figure that adds up across the table.

§epss: Option<u64>

Pss + SwapPss: what the process costs including what it pushed to swap.

§private: Option<u64>

Memory exclusively this process’s (Private_Clean + Private_Dirty).

The complement of the shared part: PSS minus this is what would be freed if the process exited and nothing else changed.

§swap_bytes: Option<u64>

Bytes of this process’s memory currently in swap (Swap from rollup).

§gpu_percent: Option<f32>

GPU utilisation in percent, from drm-usage-stats keys in fdinfo.

None when the process holds no DRM descriptor, or holds one whose driver reports no drm-busy, or the fdinfo files are unreadable. Those are three different reasons for the same thing — “no percentage is available” — and none of them is zero.

§gpu_ns: Option<u64>

Cumulative GPU nanoseconds, across every engine class the driver reports.

§cpu_delay_percent: Option<f32>

Share of this task’s life spent runnable but waiting for a CPU.

From TASKSTATS; see linux::delayacct. None means unread — no CAP_NET_ADMIN, no CONFIG_TASKSTATS, or no delay column visible — and renders -, never 0.0.

§io_delay_percent: Option<f32>

Share of this task’s life spent waiting for synchronous block I/O.

§swap_delay_percent: Option<f32>

Share of this task’s life spent waiting for a page to be swapped in.

§cgroup: Option<Box<str>>

The process’s cgroup path, e.g. /system.slice/docker-1f2e….scope.

The path, not the raw /proc/<pid>/cgroup line: the raw line is 12:cpuset:/docker/abc and carries the hierarchy id and controller list, which no column wants. The v2 entry (empty controller list) is preferred when present, because that is the hierarchy the whole machine shares.

§container: Option<Box<str>>

The container this process belongs to, if any.

Derived from cgroup once per process and cached with it. Linux-only because the detection is cgroup-based; None everywhere else.

§container_runtime: Option<Box<str>>

The runtime that owns the container (docker, kubepods, …), kept apart from container so the CONTAINER column can show docker:1f2e… without re-parsing the path at render time.

§depth: u16

Tree bookkeeping, filled by tree::build.

§has_children: bool§is_last_child: bool§flags: RowFlags

Implementations§

Source§

impl Row

Source

pub fn default_for_test(pid: Pid) -> Self

Construct a minimal row, used by tests and by the tree helpers.

Source

pub const fn maj_flt_count(&self) -> u64

Major page faults.

Exposed as a method so sort keys and renderers read symmetrically.

Source

pub const fn time_ticks_total(&self) -> u64

Total CPU ticks consumed by the process.

Source

pub fn is_kernel_thread(&self) -> bool

Source

pub fn identity(&self) -> u64

The value that identifies this row across samples.

pid for a process, a thread-specific id for a thread. Used wherever a row must be told apart from another row with the same pid, which on macOS every thread of a process shares.

Source

pub fn display_command(&self) -> &str

Text for the command column: cmdline if known, else comm, with kernel threads bracketed per htop’s convention.

Source

pub fn base_name_span(&self) -> Option<(usize, usize)>

The executable’s base name, and where it sits in Self::display_command.

Returns (start, end) byte offsets into display_command() so the renderer can emphasise those cells without re-deriving the text or allocating.

§Why this is not just “the last path component”

The command line is argv joined by spaces, so a naive split on / finds a path in an argument too (grep /usr/lib/foo). The base name is taken from exe when the sampler has it, and located in the command text as a prefix match on that path; when exe is unavailable (another user’s process) it falls back to the first word of the command, which is what argv[0] is.

Returns None when there is nothing worth highlighting — a kernel thread in brackets, or a command whose base name is the whole string.

Source

pub fn base_name_span_in(&self, text: &str) -> Option<(usize, usize)>

Self::base_name_span against text instead of the command column text.

The renderer prepends the tree branch prefix to the command column, so the span it needs is offset by that prefix’s length. Searching the finished text is simpler and more robust than adding an offset to the span: the prefix can only appear before the command, and the exe path search below does not match it.

Trait Implementations§

Source§

impl Clone for Row

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Row

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Row

§

impl RefUnwindSafe for Row

§

impl Send for Row

§

impl Sync for Row

§

impl Unpin for Row

§

impl UnsafeUnpin for Row

§

impl UnwindSafe for Row

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.