Android 基于 Perfetto 抓取 trace

news2024/9/25 7:20:37

Perfetto 官方链接地址 https://github.com/google/perfetto/

  • 开启Android的trace跟踪服务
    Perfetto 是基于 Android 的系统追踪服务, 这个配置在 Android11® 之后是默认打开的,但是如果你是 Android 9 ( P ) 或者 10 ( Q ) ,那么就需要手动设置一下相应的 prop 属性。
    adb shell setprop persist.traced.enable 1

  • 使用 adb 抓取
    adb shell perfetto -o /data/misc/perfetto-traces/trace_file.perfetto-trace -t 60s sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory
    -o /data/misc/perfetto-traces/trace_file.perfetto-trace 输出trace的路径
    -t 60s 最多抓取时长,可以Ctrl+C停止
    sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory 要抓取相关模块
    更多配置说明,参见文档:https://perfetto.dev/docs/concepts/config
    使用配置文件,通过adb抓取,参考如下
    adb push atrace.cfg /data/local/tmp/atrace.cfg
    adb shell "cat /data/local/tmp/atrace.cfg | perfetto --txt -c - -o /data/misc/perfetto-traces/trace.perfetto-trace"
    atrace.cfg 是配置信息,默认最多只抓取10秒,可以修改更长
    可以Ctrl+C停止,需执行adb shell ,再执行 cat /data/local/tmp/atrace.cfg | perfetto --txt -c - -o /data/misc/perfetto-traces/trace.perfetto-trace
    更多配置参见 https://github.com/google/perfetto/blob/master/test/configs
    然后 adb pull /data/misc/perfetto-traces/trace.perfetto-trace ,在 https://perfetto.dev/ 导入文件分析

  • 通过 perfetto 网页抓取
    打开 https://ui.perfetto.dev/#!/record
    “Add ADB Device” 选择手机设备
    如下图,有一些参数配置,根据自己的需要添加修改

    最后右上角 “Start Recording”

  • 直接在手机上抓取
    开启开发者模式:系统设置–关于手机–连续点击。部分机型可网上搜索开启方式。
    进入开发者模式,选择"系统跟踪",里面有一些相关设置
    类别,可以选择要抓取的数据种类
    抓取的trace信息会直接存储在手机 /data/local/traces,“查看跟踪文件”,可以分享
    此方式比较适合没有电脑,随时抓取

  • 使用 record_android_trace 抓取
    执行如下命令,会自动抓取,并打开 https://perfetto.dev/ 分析
    python record_android_trace -c atrace.cfg -o out.perfetto.trace
    record_android_trace 是 perfetto 中文件,具体参见以上命令的链接
    atrace.cfg 是配置信息,更多配置说明参见文档:https://perfetto.dev/docs/concepts/config,默认只抓取10秒,可以修改更长,可以Ctrl+C停止,更多配置参见 https://github.com/google/perfetto/blob/master/test/configs
    遇到"连接超时"参见后文,或者 Android基于perfetto分析native内存泄露

  • 熟悉 perfetto 快捷键,会有事半功倍效果

  • 在 Android 上,使用adb shell perfetto 时有一些注意事项
    • 最好先执行adb shell,然后执行perfetto相关命令,因为在某些情况 Ctrl+C不通过ADB传播而无法停止.
    • 在 Android 12 之前的非 root 设备上,由于过度限制的 SELinux 规则,配置只能通过 (cat config | adb shell perfetto -c -) 传递 。由于 Android 12 /data/misc/perfetto-configs可用于存储配置。
    • 在 Android 10 之前的设备上,adb 无法直接拉取 /data/misc/perfetto-traces. 可以用 adb shell cat /data/misc/perfetto-traces/trace > trace变通。
    • 当捕获较长的跟踪时,例如在基准测试或 CI 的上下文中,使用 PID=$(perfetto --background)然后kill $PID停止。

  • 如果遇到curl超时无法访问某些地址,可能需要修改,参见如下
    diff --git a/tools/heap_profile b/tools/heap_profile
    @@ -243,8 +243,9 @@ def download_or_get_cached(file_name, url, sha256):
       if needs_download:
         # Either the filed doesn't exist or the SHA256 doesn't match.
         tmp_path = bin_path + '.tmp'
    +    proxy_7890='http://127.0.0.1:7890'
         print('Downloading ' + url)
    -    subprocess.check_call(['curl', '-f', '-L', '-#', '-o', tmp_path, url])
    +    subprocess.check_call(['curl', '-f', '-L', '-#','-x',proxy_7890, '-o', tmp_path, url])
         with open(tmp_path, 'rb') as fd:
           actual_sha256 = hashlib.sha256(fd.read()).hexdigest()
         if actual_sha256 != sha256:
    

  • 一个参考配置示例如下,更多可参见 https://github.com/google/perfetto/blob/master/test/configs
    buffers: {
        size_kb: 707200
        fill_policy: RING_BUFFER
    }
    buffers: {
        size_kb: 707200
        fill_policy: RING_BUFFER
    }
    data_sources: {
        config {
            name: "linux.process_stats"
            target_buffer: 1
            process_stats_config {
                scan_all_processes_on_start: true
                proc_stats_poll_ms: 1000
            }
        }
    }
    data_sources: {
        config {
            name: "android.log"
            android_log_config {
            }
        }
    }
    data_sources: {
        config {
            name: "android.surfaceflinger.frametimeline"
        }
    }
    data_sources: {
        config {
            name: "linux.sys_stats"
            sys_stats_config {
                meminfo_period_ms: 1000
                vmstat_period_ms: 1000
                stat_period_ms: 1000
                stat_counters: STAT_CPU_TIMES
                stat_counters: STAT_FORK_COUNT
            }
        }
    }
    data_sources: {
        config {
            name: "android.heapprofd"
            target_buffer: 0
            heapprofd_config {
                sampling_interval_bytes: 4096
                shmem_size_bytes: 8388608
                block_client: true
            }
        }
    }
    data_sources: {
        config {
            name: "android.java_hprof"
            target_buffer: 0
            java_hprof_config {
            }
        }
    }
    data_sources: {
        config {
            name: "linux.ftrace"
            ftrace_config {
                ftrace_events: "sched/sched_switch"
                ftrace_events: "power/suspend_resume"
                ftrace_events: "sched/sched_wakeup"
                ftrace_events: "sched/sched_wakeup_new"
                ftrace_events: "sched/sched_waking"
                ftrace_events: "power/cpu_frequency"
                ftrace_events: "power/cpu_idle"
                ftrace_events: "sched/sched_process_exit"
                ftrace_events: "sched/sched_process_free"
                ftrace_events: "task/task_newtask"
                ftrace_events: "task/task_rename"
                ftrace_events: "lowmemorykiller/lowmemory_kill"
                ftrace_events: "oom/oom_score_adj_update"
                ftrace_events: "ftrace/print"
                ftrace_events: "binder/*"
                atrace_categories: "input"
                atrace_categories: "gfx"
                atrace_categories: "view"
                atrace_categories: "webview"
                atrace_categories: "camera"
                atrace_categories: "dalvik"
                atrace_categories: "power"
                atrace_categories: "wm"
                atrace_categories: "am"
                atrace_categories: "ss"
                atrace_categories: "sched"
                atrace_categories: "freq"
                atrace_categories: "binder_driver"
                atrace_categories: "aidl"
                atrace_categories: "binder_lock"
                atrace_apps: "*"
            }
        }
    }
    duration_ms: 300000
    flush_period_ms: 30000
    incremental_state_config {
        clear_period_ms: 5000
    }
    write_into_file: true
    

相关文章连接
Android基于perfetto分析native内存泄露

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/439473.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【备考2023年软考】选系统规划与管理师,还是信息系统项目管理师?

目录 一、系统规划与管理师介绍 二、信息系统项目管理师介绍 三、二者区别 四、适合什么人考 五、怎么备考 1.了解考试大纲 2.系统学习(附带资料分享) 3.多做题 4.总结复习 软考系统规划与管理师和信息系统项目管理师是软考中的两个比较热门的证…

CSS——js 动态改变原生 radio、switch 的选中样式

导航 1. radio1-1. 业务场景:1-2. 效果:1-3. 问题点:1-4. 解决方案:1-5. 代码:1-5-1. HTML1-5-2. JS1-5-3. html 内容排版的 css1-5-4. 实现 radio 效果的 css 2. switch2-1. 业务场景:2-2. 效果&#xff1…

Vue3+Typescript+Vitest单元测试环境+组件事件测试篇

上一节我们学会了组件测试的基础测试部分组件测试基础篇,这一节,我们学习一下深入测试组件的事件 在component中增加一个新的组件,名字就叫做Zmbutton2吧 import { defineComponent } from "vue";const ZmButton2 defineComponent({name: &…

《Spring MVC》 第一章 MVC模式

前言 MVC 模式,全称为 Model-View-Controller(模型-视图-控制器)模式。是一种软件架构模式。 分层描述Model(模型)它是应用程序的主体部分,主要由以下 2 部分组成: 实体类 Bean:专…

(4.7-4.13)【大数据新闻速递】上海、广州、青海、贵阳大力发展大数据产业;2026年中国大数据市场规模预计达365亿美元

01【贵阳大数据交易所发布全国首个交易激励计划】 4月6日,贵阳大数据交易所发布了“交易激励计划”,旨在提高数据场内交易的吸引力,解决交易入场难的问题。该计划是落实《关于构建数据基础制度更好发挥数据要素作用的意见》和《关于支持贵州…

阿里云服务器网络收发包PPS性能25万/80万/100万PPS详解

阿里云服务器ECS网络收发包PPS是什么?云服务器PPS多少合适?网络收发包PPS是指云服务器每秒可以处理的网络数据包数量,单位是PPS即packets per second每秒发包数量。阿里云百科来详细说下阿里云服务器网络收发包PPS性能参数表,以及…

Vue 事件处理器

文章目录 Vue 事件处理器事件修饰符按键修饰符 Vue 事件处理器 事件监听可以使用 v-on 指令&#xff1a; v-on <div id"app"><button v-on:click"counter 1">增加 1</button><p>这个按钮被点击了 {{ counter }} 次。</p>…

入门神经网络——浅层神经网络

文章目录 一、基础知识1.浅层神经网络介绍2.浅层神经网络的正向传播3.反向传播 二、浅层神经网络代码实例 一、基础知识 1.浅层神经网络介绍 此次构件浅层神经网络&#xff0c;相比于单神经元&#xff0c;浅层神经网络拥有多个神经元&#xff0c;因此又可以称为多神经元网络&…

【Python杂事】 处理Excel中日期时间之间没有空格问题

目录 一、数据源要求二、逻辑思路1、ROI区域2、对ROI区域进行判定 三、代码实现四、成果展示总结 碰到一个非常有趣的问题&#xff1a; 在我们的日常工作中&#xff0c;常常需要处理各种各样的数据&#xff0c;其中不乏包含日期和时间信息的数据。有时候我们会发现这些数据中日…

事件抽取的概念

1. 事件的定义 事件是指发生在某个特定的时间点或时间段、某个特定的地域范围内&#xff0c;由一个或者多个角色参与的一个或者多个动作组成的事情或状态的改变。 2. 事件基本元素 时间、地点、人物、原因、结果 3.事件抽取的定义 主要研究如何从描述事件信息的文本中抽取…

python共词矩阵分析结果一步到位

import os import re import pandas as pd from PyPDF2 import PdfFileReader import string import yakeif __name__ __main__:# 运行第一部分代码pdf_files_path C:/Users/win10/Documents/美国智库/pdf_files# 定义一个函数&#xff0c;用于读取PDF文件并将其转化成文本de…

C++学习之交互式表达式求值的详细讲解和简单代码示例

一、怎么理解交互式表达式求值&#xff1a; 交互式求表达式值是指通过命令行交互的方式&#xff0c;接收用户输入的数值和运算符号&#xff0c;然后计算出其表达式的值并返回给用户。这种方式可以方便地进行简单的计算和查错&#xff0c;也可以用于程序设计中一系列复杂的计算…

单CDN与融合CDN之间的对比:优缺点及注意事项

CDN是现代互联网服务的重要组成部分&#xff0c;它CDN可帮助内容提供者高速交付内容&#xff0c;不同的服务器部署在全球不同的数据中心&#xff0c;并在它们之间共享相同的网络路径。随着企业意识到CDN的重要性&#xff0c;越来越多的企业正在使用CDN作为内容分发工具。互联网…

完美解决丨RuntimeError: create_session() called before __init__().

错误&#xff1a; import sys sys.path.append(/home/pi/ssd-detect) import ssd_detect ssd_detect.detect(/home/pi/ssd-detect/test.jpg) 报错如下&#xff1a; Traceback (most recent call last): File "test.py", line 6, in <module ssd_detect.detect(/ho…

ArcGIS制作建设项目使用林地现状图

近年来&#xff0c;随着经济社会的快速发展&#xff0c;各地建设项目不断增多&#xff0c;占用征用林地项目的数量也呈逐年上升的趋势。根据《占用征用林地审核审批管理规范》规定&#xff0c;建设项目申请占用征用林地&#xff0c;应编制的项目使用林地可行性报告&#xff1b;…

Linux-升级CMake版本(Ubuntu18.4)

一、简介 在一些场景中&#xff0c;因为CMake版本过低而无法编译&#xff0c;此时就需要升级CMake的版本。 二、升级 卸载 先卸载旧的cmake sudo apt-get autoremove cmake 安装 切换文件夹 cd /usr/src 下载cmake包。需要哪个版本&#xff0c;可以自行修改版本号。 注&#…

中国人工智能公司CIMCAI集装箱识别云服务全球用户量领先核心科技领先,免费人工智能集装箱识别云服务,智能化港航中国人工智能公司

中国人工智能公司CIMCAI集装箱识别云服务全球用户量领先核心科技领先&#xff0c;免费人工智能集装箱识别云服务&#xff0c;智能化港航智慧港航.全球领先CIMCAI ENGINE集装箱AI检测云服务&#xff0c;集装箱号识别率99.98%&#xff0c;全球超4000企业用户使用&#xff0c;集装…

npm 包本地调试(详细流程:包本地路径、npm link 、yalc)

一、使用 包本地路径安装 package.json 中的包名叫 dzmtest&#xff08;这个才是重点&#xff09;&#xff0c;包的文件夹名 test。 获取到包的文件夹路径 执行安装命令&#xff0c;然后提示安装成功 $ npm install 包文件夹路径# 例如&#xff1a; $ npm install /Users/d…

【Linux】Linux第一个小程序-进度条

前言&#xff1a; 在之前的学习中&#xff0c;我们已经基本掌握了关于了 Linux 下的一些工具的使用&#xff0c;接下来我们运用之前学到的知识&#xff0c;我将带领大家写了一个关于 进度条 的小程序来练练手&#xff01;&#xff01;&#xff01; 本文目录 &#xff08;一&am…

密码模块非入侵式攻击及其缓解技术GMT0083-2020

密码模块非入侵式攻击&#xff0c;是一种攻击方式&#xff0c;在这种攻击中&#xff0c;攻击者不会直接访问受攻击者的密码模块。相反&#xff0c;攻击者会利用其他途径获得用户的凭证&#xff0c;然后使用这些凭证去访问密码模块。这种攻击通常使用钓鱼邮件、社交工程等技巧&a…