crosvm/tools/contrib/memstats_chart
Keiichi Watanabe 8c4cf3102d tools: contrib: Add memstats_chart
Add a tool to gather and visualize memory data for a running crosvm
instance.

BUG=b:290331222
TEST=Run the tool for ARCVM/Borealis

Change-Id: Iffb3c60dfab6bc9e21979ef3ce367cad0e8b0514
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4712086
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2023-08-10 02:17:22 +00:00
..
src tools: contrib: Add memstats_chart 2023-08-10 02:17:22 +00:00
Cargo.lock tools: contrib: Add memstats_chart 2023-08-10 02:17:22 +00:00
Cargo.toml tools: contrib: Add memstats_chart 2023-08-10 02:17:22 +00:00
plot.py tools: contrib: Add memstats_chart 2023-08-10 02:17:22 +00:00
README.md tools: contrib: Add memstats_chart 2023-08-10 02:17:22 +00:00
requirements.txt tools: contrib: Add memstats_chart 2023-08-10 02:17:22 +00:00
sample.png tools: contrib: Add memstats_chart 2023-08-10 02:17:22 +00:00

memstats chart

Gather and visualize memory information of each crosvm process, the guest and virtio-balllon for a running crosvm instance.

This tool only supports Linux enviroments.

image

Usage

Install dependencies

We need to install some Python libraries for visualization.

$ pip install -r ./requirements.txt

Build

Build the tool with cargo and copy the binary to the device if necessary.

$ cd crosvm/tools/contrib/memstats_chart/
$ cargo build --release
# (optional) If crosvm is running on another machine, copy the binary to the machine.
$ scp ./target/release/memstats $DUT:/your/favorite/directory/

If you want to run the binary on aarch64 while your workstation is x86, dev_container is useful.

$ ${CROSVM_PATH}/tools/dev_container
(container)$ cd tools/contrib/memstats_chart
(container)$ cargo build --target aarch64-unknown-linux-gnu
(container)$ cp /scratch/cargo_target/aarch64-unknown-linux-gnu/debug/memstats

Collect data

Run the binary. Note that this tool is assuming that only one crosvm is running on the system. If there are multiple crosvm instances running, this tool will abort.

$ ./memstats --output memory-data.json
# Press Ctrl-C to stop collecting data

Visualize the data

Visualize the obtained JSON file with plot.py.

$ python3 plot.py -i ./memory-data.json
./memory-data.html is written
$ google-chrome ./memory-data.html