Skip to content

Commit

Permalink
vm: Rename launch to benchmark script and add benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosperate committed Dec 30, 2023
1 parent ddc85e0 commit 37ac36b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
39 changes: 28 additions & 11 deletions launch-vm.py → benchmark-vm.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Launch a Raspberry PI OS image with Docker and QEMU, run a few commands,
and close it.
This can be used as a simple test to time startup and tear down speed
of different Raspberry Pi emulation configurations.
Launch a Raspberry PI OS image with Docker and QEMU, run a couple of
benchmarks, and close it.
This script requires a Pi OS image with autologin enabled.
"""
Expand Down Expand Up @@ -77,7 +74,7 @@ def close_container(child, docker_container_name):
)
print("{}\n! Exit status: {}".format(cmd_op, exit_status))
else:
print('! Docker container was already stopped.')
print('! Docker container was already stopped')


def run(docker_img, img_path, pi_version):
Expand All @@ -87,17 +84,37 @@ def run(docker_img, img_path, pi_version):
try:
child, docker_container_name = launch_docker_spawn(docker_img, img_path, pi_version)
child.expect_exact(BASH_PROMPT)

# System info
child.sendline("uname -a")
child.expect_exact(BASH_PROMPT)
child.sendline("cat /etc/os-release | head -n 1")
child.expect_exact(BASH_PROMPT)
child.sendline("cat /proc/cpuinfo")
child.expect_exact(BASH_PROMPT)
# child.sendline("sudo apt install -y speedtest-cli")
# child.expect_exact(BASH_PROMPT)
# child.sendline("speedtest-cli --secure")
# child.expect_exact(BASH_PROMPT)
child.sendline('python -c "import platform as p; print(p.machine(), p.architecture())"')

# Benchmarks
child.sendline("sudo apt update -qq")
child.expect_exact(BASH_PROMPT)
child.sendline("sudo apt install -y speedtest-cli sysbench")
child.expect_exact(BASH_PROMPT)
child.sendline("speedtest-cli --secure")
child.expect_exact(BASH_PROMPT)
child.sendline("# CPU test - 1 thread")
child.expect_exact(BASH_PROMPT)
child.sendline("sysbench --num-threads=1 --validate=on --test=cpu --cpu-max-prime=1000 run")
child.expect_exact(BASH_PROMPT)
child.sendline("# CPU test - 4 thread")
child.expect_exact(BASH_PROMPT)
child.sendline("sysbench --num-threads=4 --validate=on --test=cpu --cpu-max-prime=1000 run")
child.expect_exact(BASH_PROMPT)
child.sendline("# Disk test - Write")
child.expect_exact(BASH_PROMPT)
child.sendline("rm -f ~/test.tmp && sync && dd if=/dev/zero of=~/test.tmp bs=1M count=256 conv=fsync")
child.expect_exact(BASH_PROMPT)
child.sendline("# Disk test - Read")
child.expect_exact(BASH_PROMPT)
child.sendline("sync && dd if=~/test.tmp of=/dev/null bs=1M && rm -f ~/test.tmp")
child.expect_exact(BASH_PROMPT)

# We are done, let's exit
Expand Down
13 changes: 8 additions & 5 deletions dev-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ docker tag IMAGE_ID ghcr.io/carlosperate/dockerpi-vm:VERSION
docker push ghcr.io/carlosperate/dockerpi-vm:VERSION
```

### `launch_vm.py` script
### `benchmark_vm.py` script

This is a very simple script that launches the dockerpi vm fork image
pointing to a .img file, runs a couple of commands, and closes it.
pointing to a .img file (with autologin enabled), runs a couple of benchmarks,
and closes it.

It can be used to time how long it takes and compare different vm
configurations.
It can be used to compare performance of different vm configurations.

Dependencies:
- Docker
Expand All @@ -70,6 +70,9 @@ Dependencies:

To run the script:

```bash
python benchmark_vm.py path_to_my.img -p=pi1
```
python launch_vm.py -i path_to_my.img -p=pi1
```bash
python benchmark_vm.py path_to_my.img -p=pi1 -d=ghcr.io/carlosperate/dockerpi-vm:local
```

0 comments on commit 37ac36b

Please sign in to comment.