Android如何用手机抓取Systrace?

一、手机端打开Systrace方法

Systrace 是研发人员用来分析手机卡顿等性能问题的Log,那么如何在手机端抓取Systrace Log呢?

1.手机端抓取Systrace 的方法

System Traceing 打开方法一

进入Settings >> System >> Developer options >> System Traceing点击即可。

System Traceing 打开方法二

Settings 界面直接搜索System Traceing也可以。

二、Systrace 的抓取方法

点击开始记录trace,复现问题,然后点击关闭trace,这样trace 文件就会保存在/data/local/traces目录下,然后pull 出来 ,使用举例如下:

C:\Users\Administrator>adb pull /data/local/traces .
/data/local/traces/: 1 file pulled. 21.6 MB/s (5962270 bytes in 0.263s)

C:\Users\Administrator>

三、Systrace 的打开方法

导出的***.cstrace文件可以通过perfetto网站:https://ui.perfetto.dev/,点击 open with legacy UI打开。


五、Sytrace 转换成html 的方法

使用 systrace.py 脚本既可以将手机抓取的Systrace 转换成Html 文件。

1.systrace.py 文件目录如下:

sdk\platform-tools\systrace\systrace.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())

四、System Traceing的主要功能

System Traceing的主要有以下功能

  1. 记录trace

  2. Debug app trace

  3. 配置Trace 抓取的组件内容

  4. 恢复系统默认trace配置

  5. trace 默认缓存大小配置

  6. 清除之前已经保存的trace

  7. 在SystemUI 快速设置中显示

1. 记录trace

点击开始后手机会有通知提示,然后我们复现问题,问题复现结束后,关闭trace 即可。

2. Debug app trace

此功能可以抓取 app 运行缓慢以及丢帧等问题的trace log。

3. 配置Trace 抓取的组件内容

我们可以根据不同的情况,配置抓取不同的trace 信息。详细配置信息如下:

4. 恢复系统默认trace配置

此功能主要是为了恢复默认的Trace 配置,因为假如抓取配置的组件信息过多,我们的缓存大小又有现在,抓取trace时间长的话,之前的trace会被冲掉,导致可能抓取的trace 被冲掉,抓取无效。

5. trace 默认缓存大小配置

trace 默认缓存大小 主要有:4M8M16M32M64M

6. 清除之前已经保存的trace

清除trace 会清空 /data/local/traces 下所有的trace 文件,请谨慎操作。

7. 在SystemUI 快速设置中显示

开启在SystemUI 快速设置中显示,可以实现在SystemUI 设置栏中快速开始关闭抓取Trace 方法。

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值