A benchmarking tool that samples CPU, RAM, storage (read/write), and GPU usage of a process over time.
It can either launch an executable or attach to an already-running process (via pidof), then export results as CSV, PNG plots, and LaTeX (pgfplots). Use src/plotter.py to replot existing CSVs with a time window, memory unit scaling, and overlay of multiple series.
- Python 3.x
- Packages listed in
requirements.txt(psutil,matplotlib,pandas,nvidia-ml-py) pidof(for attach mode)- NVIDIA driver + NVML (
libnvidia-ml.so) for GPU metrics (optional; sampling continues without GPU if unavailable)
Create and activate a virtual environment, then install dependencies:
./env.shUsage examples live in src/bench.py and are selected by argument:
python3 src/bench.py <example>| Example | Description |
|---|---|
launch_by_name |
Launch the app and save under results/<name>/ (default) |
launch_per_pid |
Launch the app and save under results/<name>/<pid>/ |
attach_by_name |
Attach via results/<name>/ |
attach_per_pid |
Attach via pidof; save each PID under results/<name>/<pid>/ |
attach_gz_sim |
Attach to gz sim server and gz sim gui concurrently until Ctrl+C |
python3 src/bench.py launch_by_name
python3 src/bench.py attach_per_pid
python3 src/bench.py attach_gz_sim
python3 src/bench.py --helpMost examples target gnome-text-editor by default. Change the process in _base_config() inside src/bench.py, or build your own BencherConfig.
Attaches to the already-running processes named gz sim server and gz sim gui (via pidof) and samples them in the same timestep loop (concurrent / alternating).
This example uses sample_total = 0 (unlimited). Sampling continues until you press Ctrl+C; collected samples are still saved.
Outputs go under:
results/gz-sim-server/results/gz-sim-gui/
Start Gazebo before running this example (or let it wait up to wait_timeout).
Use attach_names on BencherConfig to watch multiple processes together:
cfg.attach = True
cfg.attach_names = ["gz sim server", "gz sim gui"]
cfg.sample_total = 0 # until Ctrl+C| Attribute | Default | Description |
|---|---|---|
name |
"" |
Label used for results directories |
executable |
"" |
Binary to launch, or process name for pidof |
args |
[] |
Arguments passed when launching |
callback |
None |
Optional callback invoked after each sample |
sample_time |
1 |
Seconds between samples |
sample_total |
100 |
Number of samples to collect. 0 means unlimited (until Ctrl+C or processes die) |
attach |
False |
If True, find the process with pidof instead of launching it |
attach_names |
[] |
Process names for pidof; multiple names are sampled concurrently. If empty, uses executable or name |
save_per_pid |
False |
If True, store under results/<name>/<pid>/; otherwise under results/<name>/ |
wait_timeout |
30.0 |
Max seconds to wait for the process when attaching |
wait_timestep |
0.5 |
Poll interval (seconds) while waiting for pidof |
collect_gpu |
True |
Collect per-process GPU util/memory when a supported backend is available |
Bencher records three GPU series per process (also written to CSV):
| Column | Meaning |
|---|---|
gpu_util_pct |
Process SM / compute utilization (%) |
gpu_mem_bytes |
Process GPU memory usage (bytes) |
gpu_mem_util_pct |
Process memory-controller utilization (%) |
GPU activity on child processes is attributed to the nearest watched ancestor PID (so attaching to a parent still sees descendants' GPU use, without double-counting when several related PIDs are watched).
| Vendor | Status | Backend |
|---|---|---|
| NVIDIA | Supported | NVML via nvidia-ml-py (same library nvidia-smi uses) |
| AMD | To come | Planned: AMD SMI / ROCm SMI |
| Intel | To come | Planned: Level Zero Sysman / oneAPI |
Set cfg.collect_gpu = False to skip GPU sampling entirely.
nvidia-smi is a CLI wrapper around NVML. Calling it every sample forks a process, parses text, and adds tens of milliseconds of overhead — costly when sample_time is small (e.g. 0.1 s). Bencher talks to NVML in-process instead, which is:
- as precise as
nvidia-smi(identical data source) - much cheaper per sample
- able to batch all watched PIDs in one query per timestep
Prefer libraries / APIs over CLI scrapers for programmatic sampling:
| Approach | Vendors | Notes |
|---|---|---|
NVML (nvidia-ml-py) |
NVIDIA | What Bencher uses today. Same backend as nvidia-smi; per-process util + memory. |
AMD SMI / ROCm SMI (amdsmi, rocm-smi-lib) |
AMD | Closest AMD equivalent; process-level GPU memory and busy % where the driver exposes them. Planned backend. |
| Intel Level Zero Sysman | Intel | Cross-oneAPI device queries (memory, engines). Planned backend; intel_gpu_top is useful interactively but not ideal as a library. |
| All-SMI | NVIDIA / AMD / Intel (+ NPUs) | Unified CLI for heterogeneous accelerators — good reference for a common metric shape, less ideal as a tight sampling loop dependency. |
| DCGM (Data Center GPU Manager) | NVIDIA (datacenter) | Rich telemetry / health for fleets; heavier than NVML for a single-process bencher. |
| nvtop / nvitop / gpustat | Mostly NVIDIA (nvtop is multi-vendor in the TUI) | Excellent interactive monitors; they sit on NVML (or vendor SMIs) rather than replacing them. |
A durable design (and what src/gpu_metrics.py follows) is a small vendor-agnostic sampler interface (sample_by_pid → util % + memory bytes) with one backend per vendor. That stays as precise as each vendor's management library while remaining generic enough for AMD and Intel later — without scraping *-smi text in the hot path.
from bencher import Bencher, BencherConfig
cfg = BencherConfig()
cfg.name = "firefox"
cfg.executable = "firefox"
cfg.sample_time = 0.1
cfg.sample_total = 50
cfg.attach = True
cfg.save_per_pid = True
cfg.collect_gpu = True
cfg.wait_timeout = 30.0
cfg.wait_timestep = 0.5
b = Bencher()
b.set(cfg)
b.run()
b.save_csv()
b.save_png(show=True)
b.save_latex()After a run, Bencher writes under results/. Each capture session gets a timestamp prefix (YYYYMMDD_HHMMSS) so later runs do not overwrite earlier ones:
- CSV —
{stamp}_{i}.csvor{stamp}_{pid}.csv - PNG plots —
{stamp}_cpu_usage.png,{stamp}_ram_usage.png, and when GPU activity was seen{stamp}_gpu_usage.png,{stamp}_gpu_mem_usage.png - LaTeX plots — matching
*.texfiles (pgfplots)
Layout depends on save_per_pid:
False→results/<name>/...True→results/<name>/<pid>/...
When attaching without save_per_pid, multiple PIDs are stored as separate CSV files under results/<name>/.
Pressing Ctrl+C during sampling stops collection and still writes whatever samples were gathered.
src/plotter.py regenerates PNG and/or LaTeX plots from one or more Bencher CSV files. Useful for time windows, memory unit scaling, and overlaying several captures.
python3 src/plotter.py --help| Flag | Description |
|---|---|
-f / --files |
Explicit list of CSV paths |
-d / --dir + -r / --regex |
Directory search; regex matches basenames (default: all *.csv) |
-g / --glob |
Shell-style glob pattern(s) |
| Flag | Description |
|---|---|
-m / --metrics |
Metrics to plot (default: cpu_pct mem_info). Also supports gpu_util_pct, gpu_mem_bytes, gpu_mem_util_pct, … |
--formats |
png and/or tex (default: both) |
--t-min / --t-max |
Time window in seconds (default: full series) |
--mem-unit |
auto, B, KB, MB, GB, or TB for byte metrics |
-o / --output-dir |
Output directory |
-p / --prefix |
Filename prefix (e.g. plot → plot_cpu_usage.png) |
--labels |
Legend labels, one per CSV (default: basenames) |
--title |
Override plot title |
--show |
Display PNG figures interactively |
Percent metrics (cpu_pct, gpu_util_pct, gpu_mem_util_pct) use a y-axis from 0 to 100.
# Single CSV
python3 src/plotter.py -f results/gz-sim-gui/20260731_164234_0.csv -o plots -p gui
# Directory + regex
python3 src/plotter.py -d results/gz-sim-gui -r '20260731_.*\.csv' --t-min 10 --t-max 30
# Overlay GUI and server with shared MB scale
python3 src/plotter.py \
-g 'results/gz-sim-*/20260731_164234_*.csv' \
--labels gui server \
--mem-unit MB \
-o plots -p gz
# GPU metrics
python3 src/plotter.py \
-f results/gz-sim-gui/20260731_164234_0.csv \
-m gpu_util_pct gpu_mem_bytes \
--mem-unit MB \
-o plots -p gui-gpu