作者:手机用户2502895085 | 来源:互联网 | 2023-07-05 20:23
Systrace是分析性能问题的最基本的工具,那么如何抓取systrace呢?
- 手机准备好你要进行抓取的界面 点击开始抓取(命令行的话就是开始执行命令)
- 手机上开始操作 设定好的时间到了之后,会将生成 Trace 文件,
- 使用 Chrome 将这个文件打开进行分析
下面介绍了四种使用工具抓取 Systrace 的方法:
一、使用Eclipse/Android Studio/Device Monitor抓取
- In Eclipse, open an Android application project.
- Switch to the DDMS perspective, by selecting Window > Perspectives > DDMS.
- 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.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace
- In Android Studio, open an Android application project.
- Open the Device Monitor by selecting Tools > Android > Monitor.
- 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.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace.
- Navigate to your SDK tools/ directory.
- Run the monitor program.
- 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.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace.
具体步骤见截图:
二、 使用命令行工具
命令行形式比较灵活,速度也比较快,一次性配置好之后,以后再使用的时候就会很快就出结果.
- cd android-sdk/platform-tools/systrace
- python systrace.py --time=5 -o mysystrace.html sched freq gfx input view webview wm am dalvik idle power
参数解释:
a.--time后面是你要抓的时间的长度,--time=5表示抓的时间长为5s.
b.mysystrace.html是要生成的systrace文件的名称
c. sched以及后面的参数表示,你要抓的systrace信息,这个不同手机可能有不同,你可以通过一下命令查看你手机支持的systrace Tag.
adb shell atrace --list
三、perfdump(这个是高通平台支持的一个工具)
- am start -n com.qualcomm.qti.perfdump/.MainActivity :打开这个工具
- systrace.py --from-file trace_output -o output.htm:把生成的文件转换成systrace文件
用命令1打开工具后可以看到图一(从左到右数),在图一选择你要抓的信息,然后保存,在图二中选择开始,当你发现卡顿就可以点击下载的那个图标,就可以保存之前抓的systrace文件到你手机里面
四、抓离线systrace(高通平台)
1.使用手机连接上wifi
2.确保手机和PC网络可以互通(可以ping相互的ip地址)
3.确保手机usb调试打开,使用usb连接手机,然后执行命令:adb tcpip 5555
4.断开usb连接
5.输入命令:adb connect 手机ip地址(如 adb connect 192.168.1.111)
6.通过方法一到三中的一种方法来抓