【问题标题】:Does starting the adb shell take a lot of resources?启动 adb shell 会占用大量资源吗?
【发布时间】:2016-09-01 22:38:39
【问题描述】:

我在办公室使用 bash 脚本来自动化 Android 设备上的流程。我在脚本中这样调用 shell:(让... 代表任意数量的 adb shell 命令。)

#!/bin/bash

...

adb shell do stuff
adb shell do stuff
adb shell do stuff

...

exit

这些脚本运行良好。我已经研究过将多个命令发送到单个 shell 实例;我想知道他们是否尽可能高效。我使用了大量的系统资源吗?当我将使用此过程运行非常非常大的自动化脚本时,这可能会在将来引发问题吗?

【问题讨论】:

    标签: android bash shell adb


    【解决方案1】:

    启动新的sh 进程不会占用大量时间或资源。将多个命令排队到同一个 sh 实例不会提供任何明显的性能改进。请注意您在这些 shell 会话中运行的命令。像input 这样的一些命令不是本机二进制文件,而是java 应用程序需要更长的时间才能启动 - 所以不要期望每秒能够触发多个。

    【讨论】:

    • 这其实说明了很多。这个问题与我的另一个问题中的一个场景有关,stackoverflow.com/questions/39278510/… 减慢我的input 命令允许这些命令准确地触发。很有趣,input 命令是 java 应用程序。
    【解决方案2】:

    没什么大不了的,但你可以做到

    adb shell <<!
        do stuff
        do stuff
        do stuff
    !
    

    如果您有一些 ifs 或循环,这有时会很有用,因为它更容易编写和可视化。

    【讨论】:

    • 这有时很有用但仍然没有提供任何明显的性能改进
    • 也许是这样:time for n in {0..9999}; do adb shell ls -l "&gt;" /dev/null; done real 3m29.764s user 0m1.032s sys 0m1.560s $ time while [ $i -lt 10000 ] &gt; do &gt; ls -l &gt; /dev/null &gt; i=$(( i + 1 )) &gt; done 2m1.52s real 0m2.43s user 0m5.68s system
    猜你喜欢
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    相关资源
    最近更新 更多