I would like to simulate the effect of slow/high-latency disk IO on an Android app I am developing when running on the Android Emulator.
Unlike throttling network IO, I haven't been able to find anything in the Android Emulator documentation on how to do this. I have found that qemu apparently does support throttling disk IO - is it possible to do this for and Android app?
Found how to do it using Android emulator:
QEMU supports the following options for IO throttling (suboptions of -drive option):
|-----------------------+-----------------------|
| -drive | block_set_io_throttle |
|-----------------------+-----------------------|
| throttling.iops-total | iops |
| throttling.iops-read | iops_rd |
| throttling.iops-write | iops_wr |
| throttling.bps-total | bps |
| throttling.bps-read | bps_rd |
| throttling.bps-write | bps_wr |
|-----------------------+-----------------------|
If you run the emulator with -verbose
option you can check what are the QEMU options that were used to launch the VM:
emulator -avd [avd name] -verbose
For example, for userdata image drive option may look like this:
-drive if=none,index=2,id=userdata,file=/path/to/userdata-qemu.img.qcow2,overlap-check=none,cache=unsafe,l2-cache-size=1048576
Copy the path to the image (/path/to/userdata-qemu.img.qcow2
) and pass it manually:
emulator -avd [avd name] -data /path/to/userdata-qemu.img.qcow2
If you launch the emulator using this command it will use this path for the user data image instead of auto-discovery. Now we can use the fact that it just concatenates QEMU options to inject our throttling params:
emulator -avd [avd name] -data /path/to/userdata-qemu.img.qcow2,throttling.iops-total=10,serial=qwerty
The final QEMU options string will look like this:
...
-drive if=none,index=2,id=userdata,file=/path/to/userdata-qemu.img.qcow2,throttling.iops-total=1,serial=test.qcow2,overlap-check=none,cache=unsafe,l2-cache-size=1048576
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With