crosvm/tools/contrib/memstats_chart
Daniel Verkamp 52b8e42869 Cargo.toml: avoid "*" versions for external crates
Ensure that every Cargo.toml dependency on a third-party crates.io crate
specifies at least a major version, or a minor version for 0.x crates,
to ensure that if a new major version is published, it cannot cause API
breaks.

The versions are selected to match the ones already in Cargo.lock, so
this should have no functional change, but it will help prevent new "*"
versions from being introduced via copy-and-paste.

For rationale, see the Cargo FAQ:
<https://doc.rust-lang.org/cargo/faq.html#can-libraries-use--as-a-version-for-their-dependencies>

`minijail`, `audio_streams`, and `cras` are left as "*" for now, since
they have unusual situations (imported from a submodule and/or replaced
at build time with ebuild magic).

BUG=None
TEST=tools/dev_container tools/presubmit
TEST=verify Cargo.lock is unchanged

Change-Id: Ifa18199f812f01d2d10bfb4146b3353c1a76527c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5555656
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-22 01:01:42 +00:00
..
src Apply nightly rustfmt import style 2023-09-06 22:13:26 +00:00
Cargo.lock
Cargo.toml Cargo.toml: avoid "*" versions for external crates 2024-05-22 01:01:42 +00:00
plot.py tools: contrib: Explain memstats tool's graph 2023-11-07 12:33:50 +00:00
README.md tools: contrib: Explain memstats tool's graph 2023-11-07 12:33:50 +00:00
requirements.txt
sample.png

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

How to interpret the graph

crosvm process

The main process's memory usage is divided into the following five sections and shown:

  • crosvm (guest disk caches)
  • crosvm (guest shared memory)
  • crosvm (guest unevictable)
  • crosvm (guest used)
  • crosvm (host)

These values are computed by the process's RSS and virtio-balloon's statistics.

Other processes

For processes other than the main one, Private_Dirty in /proc/${PID}/smaps is shown. Unlike Pss, Private_Dirty doesn't include the shared memory for the guest physical memory region that the process touched. We use this value because such shared memory regions are counted as a part of the crosvm main process's memory usage.

Balloon

The blue line is the upper bound of the guest's memory usage limited by virtio-balloon.