简体   繁体   中英

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.

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.

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.

To run the Systrace user interface:

Using Eclipse

  1. In Eclipse, open an Android application project.
  2. Switch to the DDMS perspective, by selecting Window > Perspectives > 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.
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.
  5. Set the tracing options and click OK to start the trace.

Using Android Studio

  1. In Android Studio, open an Android application project.
  2. Open the Device Monitor by selecting Tools > Android > Monitor.
  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.
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.
  5. Set the tracing options and click OK to start the trace.

Using Device Monitor

  1. Navigate to your SDK tools/ directory.
  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.
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.
  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. 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.

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

Android 4.3 and higher options

When you use Systrace on devices running Android 4.3 and higher, you must specify at least one trace category tag. 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.

Android 4.2 and lower options

Using Systrace on the command line with devices running Android 4.2 and lower is typically a two-step process. 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. You can check the prints of activity started & activity displayed from logcat, note the time difference between them to measure launch time.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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