收集性能數據

看門狗本機服務記錄系統啟動期間早期初始化以來的 I/O 效能資料。本機服務將收集到的效能資料轉儲到錯誤報告中。供應商可以透過 dumpsys 查詢本機服務,以轉儲收集的資料或啟動自訂收集工作階段進行偵錯。

數據收集頻率

性能數據收集的頻率因構建類型而異。

  • 在 userdebug 或 eng 版本中,Watchdog 在系統啟動期間每 (1) 秒收集一次效能數據,並在啟動完成後每 (1) 分鐘收集一次效能數據。
  • 在使用者建置中,Watchdog 在系統啟動期間每 20 秒收集一次效能數據,並在啟動完成後每兩 (2) 分鐘收集一次效能數據。

轉儲性能數據

捕獲錯誤報告後,Watchdog 本機服務會將收集到的效能資料轉儲到錯誤報告中。供應商可以透過以下 dumpsys 命令查詢本機服務以轉儲收集到的效能資料。有關該報告的詳細信息,請參閱了解性能數據報告部分。

$ adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default > /tmp/carwatchdog_dump.txt

收集效能數據以進行調試

供應商可以使用 Watchdog 本機服務自訂收集效能資料以進行調試。例如,為了了解應用程式或服務的 I/O 使用情況,供應商可以執行自訂效能資料收集,以分析特定套件清單或整個系統的 I/O 使用情況。

啟動自訂收集會話

下面顯示的是啟動自訂效能資料收集會話的命令:

$ adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default --start_perf [--interval <seconds>] [--max_duration <seconds>] [--filter_packages <package_name>,<package_name>,...]
  • --start_perf 。啟動自訂效能資料收集會話。
  • --interval <seconds> 。指定分析間隔。缺省情況下,時間間隔為 30 秒。
  • --max_duration <seconds> 。指定自訂效能資料收集會話的最大持續時間。如果未手動停止會話,則會話將停止,並且在此持續時間後將丟棄收集的資料。預設情況下,最大持續時間為 30 分鐘。
  • --filter_packages <package_name>,<package_name>,... 。指定要分析的軟體包名稱的逗號分隔清單。如果提供,性能數據收集僅限於這些包。否則,將對系統中的所有套件進行效能資料收集。

例如,以下命令啟動自訂效能資料收集,分析間隔為10 seconds ,最大收集持續時間為1 hour ,並將分析限制為com.google.android.car.kitchensinkcom.google.android.apps.maps套件。

$ adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default --start_perf --interval 10 --max_duration 3600 --filter_packages com.google.android.car.kitchensink,com.google.android.apps.maps

停止並轉儲自訂收集會話

記錄感興趣的應用程式或服務的 I/O 使用情況後,供應商應停止自訂效能資料收集會話以轉儲收集的資料。

以下命令停止自訂效能資料收集並將收集的資料轉儲到/tmp/carwatchdog_dump.txt

$ adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default --stop-perf > /tmp/carwatchdog_custom_dump.txt

轉儲系統幫助

$ adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default --help

了解性能數據報告

下面顯示的是效能數據報告範例:

$ adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default

------------------------------
WatchdogPerfService report:
------------------------------
Boot-time collection information:
==========================
Event interval: 1 second

Periodic collection information:
=========================
Event interval: 60 seconds
--------------------------------
Boot-time I/O performance report:
============================
Collection duration: 1637609138 seconds
Number of collections: 12

Collection 0: <Fri Jan  7 19:53:53 2022 GMT>
===================================
CPU I/O wait time/percent: 18 / 0.63%
Number of I/O blocked processes/percent: 0 / 0.00%

Top N Reads:
-------------
Android User ID, Package Name, Foreground Bytes, Foreground Bytes %, Foreground Fsync, Foreground Fsync %, Background Bytes, Background Bytes %, Background Fsync, Background Fsync %
0, root, 56123392, 81.95%, 1, 100.00%, 0, 0.00%, 0, 0.00%
0, system, 12333056, 18.01%, 0, 0.00%, 0, 0.00%, 0, 0.00%

Top N Writes:
-------------
Android User ID, Package Name, Foreground Bytes, Foreground Bytes %, Foreground Fsync, Foreground Fsync %, Background Bytes, Background Bytes %, Background Fsync, Background Fsync %
0, root, 53248, 100.00%, 1, 100.00%, 0, 0.00%, 0, 0.00%

Top N I/O waiting UIDs:
-----------------------
Android User ID, Package Name, Number of owned tasks waiting for I/O, Percentage of owned tasks waiting for I/O
        Command, Number of I/O waiting tasks, Percentage of UID's tasks waiting for I/O
0, root, 2, 0.59%
        kworker/7:2+events, 1, 50.00%
        kworker/4:2+events, 1, 50.00%
0, system, 2, 7.14%
        ais_server, 2, 100.00%

Top N major page faults:
------------------------
Android User ID, Package Name, Number of major page faults, Percentage of total major page faults
        Command, Number of major page faults, Percentage of UID's major page faults
0, system, 48, 53.33%
        ais_server, 13, 27.08%
        audiod, 10, 20.83%
0, root, 41, 45.56%
        init, 39, 95.12%
        ueventd, 1, 2.44%
0, media, 1, 1.11%
        init.qti.media., 1, 100.00%
Number of major page faults since last collection: 90
Percentage of change in major page faults since last collection: 0.00%

Collection 1: <Fri Jan  7 19:53:54 2022 GMT>
===================================
 … Collection data …

Collection 2: <Fri Jan  7 19:53:55 2022 GMT>
===================================
 … Collection data …
 … Repeated collection data until boot-complete …

-----------------------------------------
Last N minutes I/O performance report:
================================
Collection duration: 10797 seconds
Number of collections: 181

Collection 0: <Tue Jan 11 19:43:05 2022 GMT>
====================================
CPU I/O wait time/percent: 18 / 0.04%
Number of I/O blocked processes/percent: 0 / 0.00%

Top N Writes:
-------------
Android User ID, Package Name, Foreground Bytes, Foreground Bytes %, Foreground Fsync, Foreground Fsync %, Background Bytes, Background Bytes %, Background Fsync, Background Fsync %
0, system, 33697792, 92.41%, 0, 0.00%, 0, 0.00%, 0, 0.00%
0, gps, 2420736, 6.64%, 0, 0.00%, 0, 0.00%, 0, 0.00%

Top N I/O waiting UIDs:
-----------------------
Android User ID, Package Name, Number of owned tasks waiting for I/O, Percentage of owned tasks waiting for I/O
        Command, Number of I/O waiting tasks, Percentage of UID's tasks waiting for I/O
0, root, 1, 0.19%
        crtc_commit:244, 1, 100.00%

當捕獲錯誤報告、執行不帶任何參數的 Watchdog dumpsys 命令或停止自訂收集工作階段時,Watchdog 本機服務會轉儲類似於上述報告的效能資料報告。

該報告包含系統啟動期間以及報告產生前最後 N 分鐘收集的數據。

  • Boot-time collection information 。提供有關啟動時效能資料收集會話的資訊。
  • Periodic collection information 。提供有關啟動完成後啟動的定期效能收集會話的資訊。
  • Boot-time I/O performance report 。包含系統啟動期間收集的效能資料。該資料將永久保存在記憶體中,直到系統關閉,因此資料將轉儲到所有報告中。
  • Last N minutes I/O performance report 。包含在產生報告之前的最後 N 分鐘內(透過定期收集會話)收集的效能資料。
  • Collection duration 。性能數據收集的總持續時間。
  • Number of collections 。單一報告中報告的集合總數。

報告中報告的每個集合可能包含以下全部或部分部分。每個集合中報告的統計資料是自上次收集以來的增量,但瞬時統計資料除外(例如,自系統啟動以來未聚合)。

  • CPU I/O wait time/percent 。自上次收集以來,絕對 CPU 時間以及由於 I/O 操作而花費在上下文切換或等待上的總 CPU 時間的百分比。
  • Number of I/O blocked processes/percent 。自上次收集以來,阻塞等待 I/O 的進程總數以及阻塞等待 I/O 的進程百分比。
  • Top N Reads 。自上次收集以來從磁碟讀取最多資料的前 N ​​個包。
    • 每行包含使用者 ID、套件名稱、前台模式與後台模式讀取的總位元組數、系統中所有前台模式與後台模式讀取的位元組百分比、前台模式與後台模式下進行的 fsync 呼叫總數,以及系統中所有前台模式與後台模式fsync 呼叫的fsync 呼叫百分比。
  • Top N Writes 。自上次收集以來將最多資料寫入磁碟的前 N ​​個包。
    • 每行包含與Top N Reads類似的欄位。
  • Top NI/O waiting UIDs 。 I/O 等待任務最多的前 N ​​個套件。
    • 每個頂級行包含使用者 ID、套件名稱、等待 I/O 的套件所擁有的任務的數量和百分比。
    • 內層行包含套件所擁有的頂級進程的 I/O 等待資訊。
  • Top N major page faults 。自上次收集以來出現最多主要頁面錯誤的前 N ​​個包。
    • 每個頂級行包含使用者 ID、套件名稱、歸因於程式包的主要頁面錯誤的數量和百分比。
    • 內層行包含套件所擁有的頂級進程的主要頁面錯誤訊息。
  • Number of major page faults since last collection
  • Percentage of change in major page faults since last collection