如何在Android Emulator中模拟慢速磁盘IO



当我在Android Emulator上运行时,我想模拟慢/高延迟磁盘IO对我正在开发的Android应用程序的影响。

与节流网络IO不同,我在Android Emulator文档中找不到任何关于如何做到这一点的内容。我发现qemu显然支持限制磁盘IO——有可能为Android应用程序这样做吗?

发现如何使用Android模拟器:

QEMU支持以下IO节流选项(-drive选项的子选项(:

|-----------------------+-----------------------|
| -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                |
|-----------------------+-----------------------|

如果您使用-verbose选项运行模拟器,您可以检查用于启动VM:的QEMU选项是什么

emulator -avd [avd name] -verbose

例如,对于用户数据,图像驱动器选项可能如下所示:

-drive if=none,index=2,id=userdata,file=/path/to/userdata-qemu.img.qcow2,overlap-check=none,cache=unsafe,l2-cache-size=1048576

将路径复制到图像(/path/to/userdata-qemu.img.qcow2(并手动传递:

emulator -avd [avd name] -data /path/to/userdata-qemu.img.qcow2

如果使用此命令启动模拟器,它将为用户数据映像使用此路径,而不是自动发现。现在我们可以利用它只是连接QEMU选项来注入我们的节流参数的事实:

emulator -avd [avd name] -data /path/to/userdata-qemu.img.qcow2,throttling.iops-total=10,serial=qwerty

最后的QEMU选项字符串如下所示:

...
-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
...

最新更新