Skip to main content

memsparkline

Track the RAM usage (resident set size) of a process, its children, its children's children, etc. in real time with a Unicode text sparkline. See the average and the maximum usage after the process exits, as well as the run time.

Examples

> memsparkline -- chromium-browser --incognito http://localhost:8081/
▁▁▁▁▄▇▇▇█ 789.5
 avg: 371.0
 max: 789.5
time: 0:00:12.0
> memsparkline -n -o log du /usr/ >/dev/null 2>&1 &
> tail -f log
█ 2.8
▆█ 3.3
▆▇█ 3.6
▆▇▇█ 3.9
▆▇▇█▆ 3.3
▆▇▇█▆▆ 3.3
▆▇▇█▆▆▆ 3.3
▆▇▇█▆▆▆▆ 3.3
▄▅▅▆▅▅▅▅█ 5.2
▄▅▅▆▅▅▅▅██ 5.2
 avg: 3.7
 max: 5.2
time: 0:00:10.1

Compatibility and limitations

memsparkline works on POSIX systems supported by psutil. It has been tested on Debian, Ubuntu, FreeBSD, NetBSD, and OpenBSD.

Although memsparkline seems to work on Windows, Windows support has received little testing outside of CI. The sparkline displays incorrectly in the Command Prompt and ConEmu on Windows 7 with the stock console fonts. It displays correctly on Windows 10 with the font NSimSun.

Operation

Usage

usage: memsparkline [-h] [-v] [-d path] [-l n] [-m fmt] [-n] [-o path] [-q]
                    [-r ms] [-s ms] [-t fmt] [-w ms]
                    command ...

Track the RAM usage (resident set size) of a process and its descendants in
real time.

positional arguments:
  command               command to run
  args                  arguments to command

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -d path, --dump path  file in which to write full memory usage history when
                        finished
  -l n, --length n      sparkline length (default: 20)
  -m fmt, --mem-format fmt
                        format string for memory amounts (default: "%0.1f")
  -n, --newlines        print new sparkline on new line instead of over
                        previous
  -o path, --output path
                        output file to append to ("-" for standard error)
  -q, --quiet           do not print sparklines, only final report
  -r ms, --record ms    how frequently to record/report memory usage (default:
                        every 1000 ms)
  -s ms, --sample ms    how frequently to sample memory usage (default: every
                        200 ms)
  -t fmt, --time-format fmt
                        format string for run time (default: "%d:%02d:%04.1f")
  -w ms, --wait ms      set "--sample" and "--record" time simultaneously
                        (that both options override)

Samples and records

memsparkline differentiates between samples and records. Samples are measurements of memory usage. Records are information about memory usage printed to the chosen output (given by --output) and added to history (saved using the --dump option).

There is a separate setting for the sample time and the record time. The sample time determines the interval between when memory usage is measured. The record time determines the interval between when a record is made (written to the output and added to history). When sampling is more frequent than recording (as with the default settings), memsparkline uses the highest sampled value since the last record.

A short sample time like 5 ms can result in high CPU usage, up to 100% of one CPU core. To reduce CPU usage, sample less frequently. The default sample time of 200 ms results in memsparkline using around 10% of a 2019 x86-64 core on the developer's machine.

Records are only created after a sample has been taken. Setting the record time shorter than the sample time is allowed for convenience but equivalent to setting it to the sample time.

Installation

memsparkline requires Python 3.8 or later.

Installing from PyPI

The recommended way to install memsparkline is from PyPI with pipx.

pipx install memsparkline

You can also use pip:

pip install --user memsparkline

Manual installation

  1. Install the dependencies from the package repositories for your OS. You will find instructions for some operating systems below.
  2. Download src/memsparkline/main.py and copy it to a directory in PATH as memsparkline. For example:
git clone https://github.com/dbohdan/memsparkline
sudo install memsparkline/src/memsparkline/main.py /usr/local/bin/memsparkline

Dependencies

Debian/Ubuntu
sudo apt install python3-psutil
DragonFly BSD 6.6, FreeBSD 13.1
sudo pkg install py39-psutil
NetBSD 9.3
sudo pkgin in py310-psutil
OpenBSD
doas pkg_add py3-psutil

License

MIT.

See also

memusg and spark (both linked below) inspired this project.

Tracking memory usage

Sparklines

  • spark — a Bash script that generates a Unicode text sparkline from a list of numbers.
  • sparkline.tcl — a Tcl script by the developer of this project that does the same. Adds a --min and --max option for setting the scale.

Metadata

Release files for memsparkline 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memsparkline 0.6.0
File Size Uploaded Provenance
memsparkline-0.6.0.tar.gz 11.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for memsparkline 0.6.0
File Interpreter ABI Platform
memsparkline-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.6 kB

Release files / memsparkline-0.6.0.tar.gz

Download URL memsparkline-0.6.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
57ba8f5994a8accb068f68de6d55722b760090eab1ac2cf4aa8f25563014e9f2
BLAKE2b-256 checksum
How to use checksums
b9c9062414be58ef1e0ddac2c0846334967517c7dba074ffd289b6f0fc86fef9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.1 Linux/6.8.0-44-generic

Release files / memsparkline-0.6.0-py3-none-any.whl

Download URL memsparkline-0.6.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e49325c28ceb6d62792b408431d5f2ea82e96735d18fa74a4ad38356e1f51719
BLAKE2b-256 checksum
How to use checksums
5a247ae0328f53e1da00ab8172a67f151d24d0417e22f42037a9da39451c07a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.1 Linux/6.8.0-44-generic

Security for memsparkline 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page