经典好文推荐,通过阅读本文,您将收获以下知识点:
一、手机端打开Systrace方法
二、System Traceing的主要功能
三、Systrace 的抓取方法
四、Systrace 的打开方法
五、Sytrace 转换成html 的方法
一、手机端打开Systrace方法
Systrace 是研发人员用来分析手机卡顿等性能问题的Log,那么如何在手机端抓取Systrace Log呢?
1.手机端抓取Systrace 的方法
System Traceing 打开方法一
进入Settings
>> System
>> Developer options
>> System Traceing
点击即可。
System Traceing 打开方法一
System Traceing 打开方法二
在Settings
界面直接搜索System Traceing
也可以。
System Traceing 打开方法二
二、System Traceing的主要功能
System Traceing的主要有以下功能
-
记录trace
-
Debug app trace
-
配置Trace 抓取的组件内容
-
恢复系统默认trace配置
-
trace 默认缓存大小配置
-
清除之前已经保存的trace
-
在SystemUI 快速设置中显示
System Traceing 的主要功能
1. 记录trace
点击开始后手机会有通知提示,然后我们复现问题,问题复现结束后,关闭trace 即可。
会在traces文件夹下生成某某.ctrace举例
2. Debug app trace
此功能可以抓取 app 运行缓慢以及丢帧等问题的trace log。
3. 配置Trace 抓取的组件内容
我们可以根据不同的情况,配置抓取不同的trace 信息。详细配置信息如下:
配置Trace 抓取的组件内容
4. 恢复系统默认trace配置
此功能主要是为了恢复默认的Trace 配置,因为假如抓取配置的组件信息过多,我们的缓存大小又有现在,抓取trace时间长的话,之前的trace会被冲掉,导致可能抓取的trace 被冲掉,抓取无效。
5. trace 默认缓存大小配置
trace 默认缓存大小 主要有:4M
、8M
、16M
、32M
、64M
trace 默认缓存大小配置
6. 清除之前已经保存的trace
清除trace 会清空 /data/local/traces
下所有的trace 文件,请谨慎操作。
清除保存在/data/local/traces
7. 在SystemUI 快速设置中显示
开启在SystemUI 快速设置中显示,可以实现在SystemUI 设置栏中快速开始关闭抓取Trace 方法。
在SystemUI 快速设置中显示
三、Systrace 的抓取方法
点击开始记录trace,复现问题,然后点击关闭trace,这样trace 文件就会保存在/data/local/traces
目录下,然后pull 出来 ,使用举例如下:
C:UsersAdministrator>adb pull /data/local/traces .
/data/local/traces/: 1 file pulled. 21.6 MB/s (5962270 bytes in 0.263s)
C:UsersAdministrator>
四、Systrace 的打开方法
导出的***.cstrace
文件可以通过perfetto网站:https://ui.perfetto.dev/,点击 open with legacy UI
打开。
打开后的内容
五、Sytrace 转换成html 的方法
使用 systrace.py 脚本既可以将手机抓取的Systrace 转换成Html 文件。
1.systrace.py 文件目录如下:
sdkplatform-toolssystracesystrace.py
2.systrace.py 转换命令如下:
systrace.py --from-file=input.ctrace -o output.html
3.systrace.py 源文件如下:
#!/usr/bin/env python
# Copyright (c) 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import sys
version = sys.version_info[:2]
if version != (2, 7):
sys.stderr.write('Systrace does not support Python %d.%d. '
'Please use Python 2.7.n' % version)
sys.exit(1)
systrace_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'catapult', 'systrace'))
sys.path.insert(0, systrace_dir)
def RemoveAllStalePycFiles(base_dir):
"""Scan directories for old .pyc files without a .py file and delete them."""
for dirname, _, filenames in os.walk(base_dir):
if '.git' in dirname:
continue
for filename in filenames:
root, ext = os.path.splitext(filename)
if ext != '.pyc':
continue
pyc_path = os.path.join(dirname, filename)
py_path = os.path.join(dirname, root + '.py')
try:
if not os.path.exists(py_path):
os.remove(pyc_path)
except OSError:
# Wrap OS calls in try/except in case another process touched this file.
pass
try:
os.removedirs(dirname)
except OSError:
# Wrap OS calls in try/except in case another process touched this dir.
pass
if __name__ == '__main__':
RemoveAllStalePycFiles(os.path.dirname(__file__))
from systrace import run_systrace
sys.exit(run_systrace.main())
推荐阅读
原文始发于微信公众号(哆啦安全):如何用Android手机抓取Systrace
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论