@arthurkim/memtop
v0.0.8
Published
Treemap-based memory monitor for your terminal
Readme
memtop
memtop is a live TUI treemap for Linux and macOS process memory. Instead of showing a flat list of node, python, cargo, browser helpers, and worker processes, it groups memory by the project or app those processes belong to.
224.2 MiB 2.1% memtop (~/dev/private/memtop)
143.9 MiB codex --yolo
28.3 MiB node .../codex
6.8 MiB target/debug/memtop --once
Install
Install from npm or pnpm, then run memtop from any shell:
npm install -g @arthurkim/memtop
# or
pnpm install -g @arthurkim/memtop
memtopCheck the installed command:
memtop --versionThe npm tarball bundles prebuilt native binaries for:
aarch64-apple-darwinx86_64-apple-darwinaarch64-unknown-linux-muslx86_64-unknown-linux-musl
The installed command is a POSIX shell launcher that execs the bundled native
binary, so node is not required at runtime after installation.
Usage
Run the live treemap:
memtopPrint a non-interactive snapshot:
memtop --onceUseful filters:
memtop --top-projects 40
memtop --top-processes 16
memtop --min-memory-kib 8192
memtop --interval-ms 1000
memtop --group-by uidChoose a memory metric:
memtop --metric pss
memtop --metric uss
memtop --metric rssWhy Grouping Matters
Modern development stacks rarely run as one obvious process. A single project can appear as:
nodecargopythonrust-analyzertsserverworker- app bundle helper processes
- container children
memtop recovers that context before drawing the memory map, so you can see whether a repo, desktop app, browser, container, or worker group is responsible for memory growth.
How Grouping Works
memtop inspects process working directories, command paths, executable paths, macOS app bundles, and container metadata.
It recognizes project markers:
.git
Cargo.toml
package.json
pyproject.toml
go.mod
mise.tomlIt also recognizes workspace-style paths:
project
projects
repo
repos
src
workspace
workspacesOn macOS, processes from the same /Applications/*.app, /System/Applications/*.app, /System/Library/CoreServices/*.app, or ~/Applications/*.app bundle are grouped together before repository fallback detection. That keeps apps such as Chrome and their helper processes under one app-level group.
Container metadata takes precedence when a process is known to belong to a container.
When the Docker CLI is available, Docker container IDs are resolved to container names
and Docker Compose project/service metadata.
Docker does not record the host user that launched a container, but memtop displays it
when the container has an optional launcher.uid label:
services:
worker:
labels:
launcher.uid: "${LAUNCHER_UID:-}"LAUNCHER_UID="$(id -u)" docker compose up -dOn Linux, --group-by uid groups processes by the real UID reported in /proc/<pid>/status. In the TUI, press u to toggle between project-aware grouping and UID grouping.
Navigation
| Input | Action |
| --- | --- |
| Up, Down, k, j | Move through groups or processes |
| Enter, z | Zoom into the selected group |
| Backspace, x | Return to the group view |
| u | Toggle project/UID grouping |
| Mouse click | Select a project or process |
| r | Refresh now |
| q, Esc | Quit |
Memory Metrics
On Linux, pss and uss come from /proc/<pid>/smaps_rollup.
pssis usually the best attribution view because it divides shared pages across sharers.rssis fastest, but shared pages can be counted multiple times.ussfocuses on private resident memory.
On macOS, the OS does not expose the same PSS/USS accounting through this CLI, so memtop uses RSS while preserving the same TUI and grouping behavior.
--scan-threads controls Linux PSS/USS collection cost. The default 4 keeps CPU usage bounded. Use --scan-threads 0 to use all available parallelism for faster exact snapshots at higher CPU and memory cost.
Limitations
On Linux, the first TUI frame can show inflated memory. This is intentional: when the requested metric is pss or uss, memtop opens with a fast RSS preview, then replaces it with the slower smaps_rollup result in the background.
Example from a real host:
RSS preview: process RSS sum 979.6 GiB, system used 88.1 GiB
PSS refresh: process PSS sum 77.7 GiB, system used 88.7 GiBThe 979.6 GiB preview is not host memory usage. It is the sum of per-process RSS, so shared pages are counted once for every process that maps them. In the same snapshot:
training group: 963.9 GiB RSS -> 63.1 GiB PSS
training worker: 15.0 GiB RSS -> 1.5 GiB PSS
serving group: 2.9 GiB RSS -> 2.0 GiB PSS
serving worker: 692.6 MiB RSS -> 480.1 MiB PSSThe header has two totals with different meanings:
system usedcomes from/proc/meminfoasMemTotal - MemAvailable. This is the kernel's host-wide memory pressure signal.process <metric> sumis the sum of sampled processes above--min-memory-kib. It drives treemap tile sizes. It is an attribution view, so it will not exactly matchsystem used.
Reading Linux smaps_rollup is slower because the kernel must summarize memory mappings for each process. If smaps_rollup cannot be read, that process falls back to RSS.
Development
Run from source:
cargo runRun a snapshot from source:
cargo run -- --onceYou can also use the package scripts as Cargo aliases:
pnpm test
pnpm buildThe npm package exposes bin/memtop, a POSIX shell launcher that chooses the
bundled vendor/<target>/memtop binary for the current Linux or macOS platform.
Source checkouts run through Cargo directly; release packages do not depend on
Node.js to start memtop.
Release
Version tags (v*) automatically publish GitHub Releases and @arthurkim/memtop to npm via OIDC trusted publishing.
