Android perfetto 工具使用

发布于:2025-07-24 ⋅ 阅读:(30) ⋅ 点赞:(0)

Android perfetto 工具简单使用

官方文档:https://developer.android.google.cn/tools/perfetto?hl=zh-cn

  1. perfetto 工具默认是关闭状态需要手动开启,可以从settings中开启或者写系统属性开启

adb shell setprop persist.traced.enable 1
  1. 开启后可查看服务是否启动:ps -A | grep traced

msm8953_64:/ # ps -A | grep traced
nobody       15225     1   52372   3024 poll_schedule_timeout 0 S traced
nobody       15226     1   52372   2904 poll_schedule_timeout 0 S traced_probes
msm8953_64:/ #
  1. 控制命令介绍

    控制命令 解释 备注
    –background | -d 立即退出命令行界面,并继续在后台记录您的跟踪数据
    –config | -c 自定义配置文件 protobuf格式
    –out | -o 保存的文件
    –dropbox TAG Upload trace into DropBox using tag TAG
    -t+time 检测时长
    –no-guardrails Ignore guardrails triggered when using --dropbox (for testing)
    –txt Parse config as pbtxt. Not a stable API. Not for production use.
    –help | -h 帮助
    –time | -t Trace duration N[s,m,h] (default: 10s) 时长需要跟单位
    –buffer | -b Ring buffer size N[mb,gb] (default: 32mb)
    –size | -s Max file size N[mb,gb] (default: in-memory ring-buffer only)
    ATRACE_CAT Record ATRACE_CAT (e.g. wm)
    FTRACE_GROUP/FTRACE_NAME Record ftrace event (e.g. sched/sched_switch)
    FTRACE_GROUP/* Record all events in group (e.g. sched/*)
    –alert-id ID of the alert that triggered this trace.
    –config-id ID of the triggering config
    –subscription-id ID of the subscription that triggered this trace
    –detach=key Detach from the tracing session with the given key
    –attach=key [–stop] Re-attach to the session (optionally stop tracing once reattached)
    –is_detached=key Check if the session can be re-attached (0:Yes, 2:No, 1:Error)
  2. 常用模块介绍

    模块 模块介绍
    sched 跟踪CPU调度、上下文切换等内核事件‌
    freq 记录CPU频率动态调整过程‌
    idle 监控CPU进入/退出低功耗状态‌
    am 追踪Activity启动、生命周期等应用管理事件‌
    wm 记录窗口管理、Surface布局等图形层操作‌
    gfx 分析UI渲染、VSync信号、GPU活动‌
    view 跟踪View绘制、测量、布局流程‌
    binder_driver 监控进程间通信的Binder调用‌
    hal 记录Camera/Audio/Sensor等HAL层调用‌
    dalvik 追踪ART/Dalvik的GC、JIT编译等事件‌
    camera 分析相机开启、预览、拍照等流程耗时‌
    input 记录触摸、按键等输入事件处理‌
    res 跟踪内存/IO资源分配释放‌
    memory 监控内存压力、OOM事件等‌

    如:perfetto -o /data/trace.perfetto-trace -t 10s sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory

  3. 抓取指定的时候后会自动停止,将文件导出可在:https://ui.perfetto.dev/#!/record地址导入后查看


网站公告

今日签到

点亮在社区的每一天
去签到