Perfetto工具用法

一、抓取trace

Perfetto配置

Perfetto在Android 9以上默认预制,但没有开启
开启方法: adb shell setprop presist.traced.enable 1

Perfetto实现类似systrace或atrace功能

adb shell perfetto -o /data/misc/perfetto-traces/trace -t 20s schedfreq idle am wm gfx view

adb shell perfetto \
  -c - --txt \
  -o /data/misc/perfetto-traces/trace \
<

也可以将配置文件push进设备。如:
adb push config.txt /data/local/tmp/trace_config.txt
adb shell 'perfetto --txt -c - -o /data/misc/perfetto-traces/trace < /data/local/tmp/trace_config.txt'

二、Trace转换

支持的格式
  • text - protobuf text format: a text based representation of protos
  • json - Chrome JSON format: the format used by chrome://tracing
  • systrace: the ftrace text format used by Android systrace
  • profile (heap profiler only): pprof-like format. This is only valid for traces with native heap profiler dumps.
工具下载及用法
curl -LO https://get.perfetto.dev/traceconv
chmod +x traceconv
./traceconv [text|json|systrace|profile] [input proto file] [output file]

三、Heap profiling

环境配置
  • Android 10以上设备
  • 如果是user版本需要在manifest配置profileable 或debuggable

    
        
        ...
    

工具下载及抓取方法
curl -LO https://raw.githubusercontent.com/google/perfetto/master/tools/heap_profile
chmod +x heap_profile

./heap_profile -n system_server

四、LMK和oom_score_adj抓取

adb shell perfetto \
  -c - --txt \
  -o /data/misc/perfetto-traces/trace \
<

五、Java Heap

curl -LO https://raw.githubusercontent.com/google/perfetto/master/tools/java_heap_dump
chmod +x java_heap_dump

java_heap_dump -n com.android.systemui

你可能感兴趣的:(Perfetto工具用法)