Small CLI to run a command, sample its memory/CPU usage, and generate graphs.
- Runs your command and monitors RSS + CPU over time.
- Prints ASCII graphs to
stdoutby default. - Can write
PNGand/orSVGgraphs to an output directory. - Returns the wrapped command's exit code.
cargo run -- -- <command> [args...]Modes (-m/--mode) control where graphs go:
terminal(orterm): ASCII graphs to stdout. Default when no mode is passed.png: writememory.pngandcpu.png.svg: writememory.svgandcpu.svg.- Repeat
--modeto combine outputs.
If png or svg mode is enabled and --output is not provided, output files are written to psr-<command>-<timestamp>.
Examples:
# default mode is terminal (ASCII output)
cargo run -- -- python3 -c "import time; x=bytearray(100_000_000); time.sleep(2)"
# PNG output only
cargo run -- --mode png --output out -- sleep 2
# terminal + SVG output
cargo run -- --mode terminal --mode svg --output out -- sleep 3
# PNG + SVG with custom interval/image size
cargo run -- --mode png --mode svg --interval 200 --output out --width 1280 --height 720 -- sleep 3Command used to generate the sample output below:
target/debug/psrecord --mode terminal --mode png --interval 200 --output docs/readme-assets --width 900 --height 540 -- python3 -c 'import math,time; blocks=[]; acc=0.0
for step in range(18):
buf=bytearray(8_000_000)
for i in range(0, len(buf), 4096):
buf[i]=step%251
blocks.append(buf)
end=time.time()+0.25
while time.time()<end:
for i in range(1,3000):
acc += math.sqrt((i*step)%997+1)
time.sleep(0.15)
if step%4==3 and len(blocks)>2:
del blocks[:2]'Terminal output:
Raw terminal text: docs/readme-assets/terminal-output.txt
Rendered PNG output:
Memory graphs auto-select one unit per run based on peak RSS:
< 1 MiB->KB< 1 GiB->MB< 1 TiB->GB>= 1 TiB->TB
The same unit is used for terminal, PNG, and SVG memory graphs.
psrecord image modes (png and svg) render chart text via plotters, which may require native font libraries on Unix-like systems.
Install build tools and font dependencies:
sudo apt update
sudo apt install -y build-essential pkg-config libfontconfig1-dev libfreetype6-dev fontconfig fonts-dejavu-coreOptional sanity checks:
pkg-config --modversion fontconfig
pkg-config --modversion freetype2Install required dependencies:
brew install pkgconf fontconfig freetypeOptional sanity checks:
pkg-config --modversion fontconfig
pkg-config --modversion freetype2cargo +nightly fmt --all
cargo clippy --all-targets --all-features
cargo testApache License 2.0. See LICENSE.

