小酌雞湯
獻(xiàn)賦今未售专钉,讀書凡幾秋弦赖。
本文來源《Android 性能優(yōu)化 全家桶》
什么是Perfetto?
?Perfetto 是 Android 10 中引入的全新平臺(tái)級(jí)跟蹤工具。這是適用于 Android将谊、Linux 和 Chrome 的更加通用和復(fù)雜的開源跟蹤項(xiàng)目眨补。與 Systrace 不同命雀,它提供數(shù)據(jù)源超集旗笔,可讓您以 protobuf 編碼的二進(jìn)制流形式記錄任意長(zhǎng)度的跟蹤記錄彪置。您可以在 Perfetto 界面中打開這些跟蹤記錄。
Perfetto和Systrace的關(guān)系?
- 在 Perfetto 界面中打開 Perfetto 文件和 Systrace 文件蝇恶。在 Perfetto 界面中使用舊版 Systrace 查看器打開 Systrace 文件(使用 Open with legacy UI 鏈接)拳魁。
- 使用
traceconv
工具將 Perfetto 跟蹤記錄轉(zhuǎn)換為舊版 Systrace 文本格式。 - Systrace 和 Perfetto 不會(huì)收集有關(guān)應(yīng)用進(jìn)程中代碼執(zhí)行情況的詳細(xì)信息撮弧。如需詳細(xì)了解您的應(yīng)用正在執(zhí)行哪些方法及其占用了多少 CPU 資源潘懊,請(qǐng)使用CPU Profiler。
Perfetto收集性能數(shù)據(jù)來源有哪些?
- 使用 ftrace 收集內(nèi)核信息
- 使用 atrace 收集服務(wù)和應(yīng)用中的用戶空間注釋
- 使用 heapprofd 收集服務(wù)和應(yīng)用的本地內(nèi)存使用情況信息
Perfetto的 文件生成 實(shí)操開始吧~
(1)配置選項(xiàng) - 數(shù)據(jù)源選擇
?perfetto
包含以下兩種模式贿衍,可確定用于記錄跟蹤數(shù)據(jù)的數(shù)據(jù)源:
-
輕量模式:只能選擇一部分?jǐn)?shù)據(jù)源授舟,具體來說就是 atrace 和 ftrace。但此模式可提供類似于
systrace
的接口贸辈。 -
普通模式:從協(xié)議緩沖區(qū)獲取其配置岂却,并且可以讓您使用 atrace 和 ftrace 之外的數(shù)據(jù)源,從而更加充分地利用
perfetto
的功能裙椭。
(2)輕量模式
在輕量模式下使用 perfetto 的一般語(yǔ)法如下:
//輕量模式語(yǔ)法:
adb shell perfetto [ --time <記錄時(shí)間> ] [ --buffer <緩沖區(qū)空間大小> ] [ --size <文件大小上限> ]
[ <atrace類別>| <ftrace事件> | <記錄群組中的所有事件> ]...
//如何你是小白躏哩,不用關(guān)注那些繁瑣的參數(shù),看一個(gè)簡(jiǎn)單實(shí)操栗子:
//(1)--time 5s <記錄5秒鐘>
//(2)--out /data/misc/perfetto-traces/trace <錄制文件輸出到手機(jī)指定位置揉燃,然后adb pull出來即可>
adb shell perfetto --time 5s --out /data/misc/perfetto-traces/trace
//adb pull出來到當(dāng)前路徑.
adb pull /data/misc/perfetto-traces/trace .
//如果不你不是小白扫尺,請(qǐng)移步到文章結(jié)尾,去官網(wǎng)查看
(3)普通模式
在普通模式下使用 perfetto 的一般語(yǔ)法如下:
/普通模式語(yǔ)法:
adb shell perfetto [ --txt <pbtxt標(biāo)志(可忽略)> ] --config CONFIG_FILE <指定配置文件的路徑炊汤,一般使用默認(rèn)test配置即可>
//舉個(gè)栗子
adb shell perfetto --config :test --out /data/misc/perfetto-traces/trace
(4)PerfettoUI打開跟蹤文件預(yù)覽
?怎么樣是不是畫風(fēng)清爽正驻,功能多樣,激動(dòng)不已抢腐,親測(cè)好用姑曙,極力推薦。
(5)會(huì)查字典
?在操作過程中迈倍,肯定會(huì)有操作失誤的時(shí)候伤靠,這個(gè)時(shí)候,切莫著急啼染,打開新華字典
(adb shell perfetto -h)
宴合,然后對(duì)比錯(cuò)誤提示,就可以解決大部分的問題了迹鹅。
E:\>adb shell perfetto -h
perfetto_cmd.cc:205
Usage: perfetto
--background -d : Exits immediately and continues tracing in
background
--config -c : /path/to/trace/config/file or - for stdin
--out -o : /path/to/out/trace/file or - for stdout
--dropbox TAG : Upload trace into DropBox using tag TAG
--no-guardrails : Ignore guardrails triggered when using --dropbox
(for testing).
--txt : Parse config as pbtxt. Not for production use.
Not a stable API.
--reset-guardrails : Resets the state of the guardails and exits
(for testing).
--query : Queries the service state and prints it as
human-readable text.
--query-raw : Like --query, but prints raw proto-encoded bytes
of tracing_service_state.proto.
--help -h
light configuration flags: (only when NOT using -c/--config)
--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'/*')
statsd-specific flags:
--alert-id : ID of the alert that triggered this trace.
--config-id : ID of the triggering config.
--config-uid : UID of app which registered the config.
--subscription-id : ID of the subscription that triggered this trace.
Detach mode. DISCOURAGED, read https://docs.perfetto.dev/#/detached-mode :
--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).
E:\>
?
現(xiàn)在動(dòng)手練習(xí)起來吧
小編的擴(kuò)展鏈接
參考鏈接
遠(yuǎn)處蔚藍(lán)天空下卦洽,涌動(dòng)著金色的麥浪……
?
舉手之勞,贊有余香斜棚!???比心??
?