简体   繁体   English

使用 adb 命令测量 Android 应用程序的启动时间

[英]Measure launch time of an android app using adb commands

I want to measure the launch time (from application launch start to application first view render complete).我想测量启动时间(从应用程序启动开始到应用程序第一次查看渲染完成)。 Is there any adb command/combination of adb commands through which I can achieve this.是否有任何 adb 命令/adb 命令的组合可以实现这一点。

I'm not sure if what you want is possible through adb commands, but you can use the systrace tool included in the platform-tools/systrace folder of your Android SDK installation.我不确定通过 adb 命令是否可以实现您想要的功能,但是您可以使用 Android SDK 安装的 platform-tools/systrace 文件夹中包含的 systrace 工具。

The Systrace tool can be run from the Android Developer Tools (ADT) in Eclipse, Android Studio, the Android Device Monitor or even in command line. Systrace 工具可以从 Eclipse、Android Studio、Android 设备监视器甚至命令行中的 Android 开发人员工具 (ADT) 运行。

To run the Systrace user interface:要运行 Systrace 用户界面:

Using Eclipse使用 Eclipse

  1. In Eclipse, open an Android application project.在 Eclipse 中,打开一个 Android 应用程序项目。
  2. Switch to the DDMS perspective, by selecting Window > Perspectives > DDMS.通过选择 Window > Perspectives > DDMS 切换到 DDMS 透视图。
  3. In the Devices tab, select the device on which to run a trace.在设备选项卡中,选择要运行跟踪的设备。 If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.如果未列出任何设备,请确保您的设备已通过 USB 电缆连接并且在设备上启用了调试。
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.单击“设备”面板顶部的 Systrace 图标以配置跟踪。
  5. Set the tracing options and click OK to start the trace.设置跟踪选项并单击确定开始跟踪。

Using Android Studio使用 Android Studio

  1. In Android Studio, open an Android application project.在 Android Studio 中,打开一个 Android 应用程序项目。
  2. Open the Device Monitor by selecting Tools > Android > Monitor.通过选择工具 > Android > 监视器打开设备监视器。
  3. In the Devices tab, select the device on which to run a trace.在设备选项卡中,选择要运行跟踪的设备。 If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.如果未列出任何设备,请确保您的设备已通过 USB 电缆连接并且在设备上启用了调试。
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.单击“设备”面板顶部的 Systrace 图标以配置跟踪。
  5. Set the tracing options and click OK to start the trace.设置跟踪选项并单击确定开始跟踪。

Using Device Monitor使用设备监视器

  1. Navigate to your SDK tools/ directory.导航到您的 SDK tools/ 目录。
  2. Run the monitor program.运行监控程序。
  3. In the Devices tab, select the device on which to run a trace.在设备选项卡中,选择要运行跟踪的设备。 If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.如果未列出任何设备,请确保您的设备已通过 USB 电缆连接并且在设备上启用了调试。
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.单击“设备”面板顶部的 Systrace 图标以配置跟踪。
  5. Set the tracing options and click OK to start the trace.设置跟踪选项并单击确定开始跟踪。

Command Line Usage命令行使用

The Systrace tool has different command line options for devices running Android 4.3 (API level 18) and higher versus devices running Android 4.2 (API level 17) and lower.对于运行 Android 4.3(API 级别 18)及更高版本的设备与运行 Android 4.2(API 级别 17)及更低版本的设备,Systrace 工具具有不同的命令行选项。 The following sections describe the different command line options for each version.以下部分描述了每个版本的不同命令行选项。

The general syntax for running Systrace from the command line is as follows.从命令行运行 Systrace 的一般语法如下。

$ python systrace.py [options] [category1] [category2] ... [categoryN]

Android 4.3 and higher options Android 4.3 及更高版本的选项

When you use Systrace on devices running Android 4.3 and higher, you must specify at least one trace category tag.当您在运行 Android 4.3 及更高版本的设备上使用 Systrace 时,您必须至少指定一个跟踪类别标签。 Here is an example execution run that sets trace tags and generates a trace from a connected device.这是一个示例执行运行,它设置跟踪标记并从连接的设备生成跟踪。

$ cd android-sdk/platform-tools/systrace
$ python systrace.py --time=10 -o mynewtrace.html sched gfx view wm

Tip: If you want to see the names of tasks in the trace output, you must include the sched category in your command parameters.提示:如果要在跟踪输出中查看任务名称,则必须在命令参数中包含 sched 类别。

Android 4.2 and lower options Android 4.2 及更低版本的选项

Using Systrace on the command line with devices running Android 4.2 and lower is typically a two-step process.在运行 Android 4.2 及更低版本的设备上使用命令行上的 Systrace 通常是一个两步过程。 You must first set the trace tags you want to capture and then run the trace.您必须首先设置要捕获的跟踪标记,然后运行跟踪。 Here is an example execution run that sets trace tags and generates a trace from a connected device.这是一个示例执行运行,它设置跟踪标记并从连接的设备生成跟踪。

$ cd android-sdk/platform-tools/systrace
$ python systrace.py --set-tags gfx,view,wm
$ adb shell stop
$ adb shell start
$ python systrace.py --disk --time=10 -o mynewtrace.html

You can measure the launch time of application from adb logcat.您可以从 adb logcat 测量应用程序的启动时间。 You can check the prints of activity started & activity displayed from logcat, note the time difference between them to measure launch time.您可以检查 logcat 显示的活动开始和活动的打印件,注意它们之间的时间差以测量启动时间。

adb logcat -vthreadtime | grep "start"
adb logcat -vthreadtime | grep "Displayed"

Or或者

You can use below command to launch application & find time from it's output : adb shell am start -W您可以使用以下命令启动应用程序并从其输出中查找时间:adb shell am start -W

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM