Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate slow disk IO in the Android Emulator?

Tags:

android

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?

like image 381
Maks Avatar asked Oct 12 '25 16:10

Maks


1 Answers

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
...
like image 199
lukaville Avatar answered Oct 14 '25 05:10

lukaville