如何输出Perfetto

2024-08-17 08:46:02 浏览数 (3)

1、可以在串口输入命令

代码语言:javascript复制
atrace -z -b 20000 gfx input view wm am hal res sync freq idle sched rs -t 5 -o /data/youtube.txt

atrace 是 Android 系统中的一个性能分析工具,用于跟踪和记录系统调用和内核事件。这个命令包含了多个参数,每个参数都有特定的含义。

下面是命令中每个参数的解释: -z:这个参数让 atrace 以“压缩”模式运行,即它会尝试减少输出文件的大小,这有助于减少存储空间的占用。 -b 20000:-b 参数后面跟的数字表示输出缓冲区的大小,单位是字节。在这个例子中,缓冲区大小被设置为 20000 字节。 gfx input view wm am hal res sync freq idle sched rs:这些是 atrace 要跟踪的标签(categories)。每个标签代表一个跟踪类别,例如:

gfx

图形相关事件

input:输入设备相关事件

view

视图系统相关事件

wm

窗口管理器相关事件

am

活动管理器相关事件

hal

硬件抽象层相关事件

res

资源管理器相关事件

sync

同步机制相关事件

freq

CPU频率变化事件

idle

CPU空闲状态事件

sched

调度器事件

rs

RenderScript 脚本执行事件

-t 5:-t 参数后面跟的数字表示跟踪持续的时间,单位是秒。这里设置为跟踪 5 秒。 -o /data/youtube.txt:-o 参数后面跟的是输出文件的路径。在这个例子中,跟踪结果将被保存到 /data/youtube.txt 文件中。

总结来说,这个 atrace 命令配置了一个压缩模式的跟踪会话,设置了 20000 字节的缓冲区大小,选择了多个跟踪类别,持续跟踪 5 秒,并将结果输出到 /data/youtube.txt 文件中。这通常用于性能分析和调试,以了解在特定时间段内系统的行为和性能瓶颈。

2、也可以运行shell文件

代码语言:javascript复制
#!/bin/bash
adb shell perfetto 
  -c - --txt 
  -o /data/misc/perfetto-traces/trace 
<<EOF

buffers: {
    size_kb: 129024
    fill_policy: DISCARD
}
buffers: {
    size_kb: 2048
    fill_policy: DISCARD
}
data_sources: {
    config {
        name: "linux.process_stats"
        target_buffer: 1
        process_stats_config {
            scan_all_processes_on_start: true
        }
    }
}
data_sources: {
    config {
        name: "linux.sys_stats"
        sys_stats_config {
            stat_period_ms: 1000
            stat_counters: STAT_CPU_TIMES
            stat_counters: STAT_FORK_COUNT
        }
    }
}
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: "ftrace/print"
            atrace_categories: "gfx"
            atrace_categories: "sm"
            atrace_categories: "audio"
            atrace_categories: "video"
            atrace_categories: "hal"
            atrace_categories: "bionic"
            atrace_categories: "binder_driver"
            atrace_apps: "com.realtek.media.player"
        }
    }
}
duration_ms: 10000

EOF

or

代码语言:javascript复制
adb shell perfetto 
  -c - --txt 
  -o /data/misc/perfetto-traces/trace 
<<EOF

buffers: {
    size_kb: 129024
    fill_policy: DISCARD
}
buffers: {
    size_kb: 2048
    fill_policy: DISCARD
}
data_sources: {
    config {
        name: "android.packages_list"
        target_buffer: 1
    }
}
data_sources: {
    config {
        name: "linux.process_stats"
        target_buffer: 1
        process_stats_config {
            scan_all_processes_on_start: true
        }
    }
}
data_sources: {
    config {
        name: "android.surfaceflinger.frametimeline"
    }
}
data_sources: {
    config {
        name: "linux.ftrace"
        ftrace_config {
            ftrace_events: "binder/*"
            ftrace_events: "block/*"
            ftrace_events: "fastrpc/*"
            ftrace_events: "irq/*"
            ftrace_events: "kmem/*"
            ftrace_events: "mmc/*"
            ftrace_events: "sched/*"
            ftrace_events: "sync/*"
            ftrace_events: "task/*"
            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: "raw_syscalls/sys_enter"
            ftrace_events: "raw_syscalls/sys_exit"
            ftrace_events: "sched/sched_process_exit"
            ftrace_events: "sched/sched_process_free"
            ftrace_events: "task/task_newtask"
            ftrace_events: "task/task_rename"
            ftrace_events: "sched/sched_blocked_reason"
            ftrace_events: "ftrace/print"
            ftrace_events: "mm_event/mm_event_record"
            ftrace_events: "ion/ion_stat"
            ftrace_events: "dmabuf_heap/dma_heap_stat"
            atrace_categories: "am"
            atrace_categories: "adb"
            atrace_categories: "aidl"
            atrace_categories: "dalvik"
            atrace_categories: "audio"
            atrace_categories: "binder_lock"
            atrace_categories: "binder_driver"
            atrace_categories: "bionic"
            atrace_categories: "camera"
            atrace_categories: "database"
            atrace_categories: "gfx"
            atrace_categories: "hal"
            atrace_categories: "input"
            atrace_categories: "network"
            atrace_categories: "nnapi"
            atrace_categories: "pm"
            atrace_categories: "power"
            atrace_categories: "rs"
            atrace_categories: "res"
            atrace_categories: "rro"
            atrace_categories: "sm"
            atrace_categories: "ss"
            atrace_categories: "vibrator"
            atrace_categories: "video"
            atrace_categories: "view"
            atrace_categories: "webview"
            atrace_categories: "wm"
            atrace_apps: "*"
            symbolize_ksyms: true
        }
    }
}
duration_ms: 15000

EOF

参考学习:

  1. https://developer.android.com/tools/perfetto
  2. 主要說明https://perfetto.dev/
  3. https://ui.perfetto.dev/#!/

0 人点赞