xref: /aosp_15_r20/external/crosvm/tools/contrib/memstats_chart/README.md (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1# memstats chart
2
3Gather and visualize memory information of each crosvm process, the guest and virtio-balllon for a
4running crosvm instance.
5
6This tool only supports Linux enviroments.
7
8![image](./sample.png)
9
10## Usage
11
12## Install dependencies
13
14We need to install some Python libraries for visualization.
15
16```sh
17$ pip install -r ./requirements.txt
18```
19
20## Build
21
22Build the tool with cargo and copy the binary to the device if necessary.
23
24```sh
25$ cd crosvm/tools/contrib/memstats_chart/
26$ cargo build --release
27# (optional) If crosvm is running on another machine, copy the binary to the machine.
28$ scp ./target/release/memstats $DUT:/your/favorite/directory/
29```
30
31If you want to run the binary on aarch64 while your workstation is x86, `dev_container` is useful.
32
33```sh
34$ ${CROSVM_PATH}/tools/dev_container
35(container)$ cd tools/contrib/memstats_chart
36(container)$ cargo build --target aarch64-unknown-linux-gnu
37(container)$ cp /scratch/cargo_target/aarch64-unknown-linux-gnu/debug/memstats
38```
39
40### Collect data
41
42Run the binary. Note that this tool is assuming that only one crosvm is running on the system. If
43there are multiple crosvm instances running, this tool will abort.
44
45```sh
46$ ./memstats --output memory-data.json
47# Press Ctrl-C to stop collecting data
48```
49
50### Visualize the data
51
52Visualize the obtained JSON file with `plot.py`.
53
54```sh
55$ python3 plot.py -i ./memory-data.json
56./memory-data.html is written
57$ google-chrome ./memory-data.html
58```
59
60#### How to interpret the graph
61
62##### crosvm process
63
64The main process's memory usage is divided into the following five sections and shown:
65
66- crosvm (guest disk caches)
67- crosvm (guest shared memory)
68- crosvm (guest unevictable)
69- crosvm (guest used)
70- crosvm (host)
71
72These values are computed by the process's RSS and virtio-balloon's statistics.
73
74##### Other processes
75
76For processes other than the main one, `Private_Dirty` in `/proc/${PID}/smaps` is shown. Unlike
77`Pss`, `Private_Dirty` doesn't include the shared memory for the guest physical memory region that
78the process touched. We use this value because such shared memory regions are counted as a part of
79the crosvm main process's memory usage.
80
81##### Balloon
82
83The blue line is the upper bound of the guest's memory usage limited by virtio-balloon.
84