监控定时器原生服务会在系统启动期间从 early-init 阶段开始记录 I/O 性能数据。原生服务会将收集的性能数据转储到 bug 报告中。供应商可以通过 dumpsys 查询原生服务,从而转储收集的数据,或启动自定义收集会话以进行调试。
数据收集频率
性能数据收集的频率因 build 类型而异。
- 在 userdebug build 或 eng build 中,监控定时器会在系统启动期间每一 (1) 秒收集一次性能数据,并在启动完成后每 (1) 分钟收集一次性能数据。
- 在 user build 上,监控定时器会在系统启动期间每 20 秒收集一次性能数据,并在启动完成后每二 (2) 分钟收集一次性能数据。
数据收集事件
基于样本的分析会在各种系统事件(例如系统启动、系统唤醒和用户切换)期间和过去 N 分钟的时段内执行。
- 生成 bug 报告前的最近 N 分钟事件:在 30 分钟的滚动窗口期内生成。
- 启动时间事件:在启动后生成。
- 用户切换事件:在用户切换启动后生成。
- 自定义收集事件:可以指定轮询周期、最大时长,并且可以按软件包过滤。
转储性能数据
捕获到 bug 报告时,监控定时器原生服务会将收集的性能数据转储到 bug 报告中。供应商可以通过以下 dumpsys 命令查询原生服务,以转储收集的性能数据。如需详细了解该报告,请参阅了解性能数据报告部分。
adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default > /tmp/carwatchdog_dump.txt
收集性能数据以进行调试
供应商可以出于调试目的,使用监控定时器原生服务自定义收集性能数据。例如,如需了解应用或服务的 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 秒、收集时长上限为 1 小时的自定义性能数据收集,并将分析限制为 com.google.android.car.kitchensink
和 com.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
Dumpsys 帮助
如需获取 dumpsys 帮助,请执行以下操作:
adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default --help
转储为 proto 格式
(可选)可以 proto 格式转储 dumpsys 数据:
adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default --proto
了解效果数据报告
如需了解详情,请参阅以下效果数据报告示例:
adb shell dumpsys android.automotive.watchdog.ICarWatchdog/default --------------------------------- WatchdogPerfService report: --------------------------------- Boot-time collection information: ================================= Event polling interval: 1 second Wake-up collection information: =============================== Event polling interval: 1 second User-switch collection information: =================================== Event polling interval: 1 second Periodic collection information: ================================ Event polling interval: 60 seconds --------------------------------------------------------------------------- Boot-time performance report: ================================= No collection recorded --------------------------------------------------------------------------- Wake-up performance report: =========================== No collection recorded --------------------------------------------------------------------------- User-switch events performance report: ====================================== No collection recorded --------------------------------------------------------------------------- Last N minutes performance report: ====================================== Collection duration: 10800 seconds Number of collections: 181 Collection 0: <Mon Oct 2 18:36:06 2023 GMT> ============================================= Total CPU time (ms): 473210 Total CPU cycles: 39553152000 Total idle CPU time (ms)/percent: 435860 / 92.11% CPU I/O wait time (ms)/percent: 0 / 0.00% Number of context switches: 13723415093 Number of I/O blocked processes/percent: 0 / 0.00% Top N CPU Times: ---------------- Android User ID, Package Name, CPU Time (ms), Percentage of total CPU time, CPU Cycles Command, CPU Time (ms), Percentage of UID's CPU Time, CPU Cycles 10, com.google.android.carassistant, 13357, 2.82%, 16409088000 assistant:interactor, 13360, 100.02%, 16409088000 0, system, 9097, 1.92%, 9640512000 sensors@1.0-ser, 3790, 41.66%, 3773184000 system_server, 2760, 30.34%, 3135936000 com.android.car, 1150, 12.64%, 1099584000 binder:621_4, 1000, 10.99%, 1281024000 surfaceflinger, 230, 2.53%, 245376000 0, audioserver, 4383, 0.93%, 4597248000 Main, 2690, 61.37%, 2980416000 binder:916_2, 950, 21.67%, 925056000 audioserver, 720, 16.43%, 691776000 0, root, 4357, 0.92%, 3727872000 irq/311-iam2068, 2630, 60.36%, 2471616000 irq/26-90b6400., 370, 8.49%, 561024000 kworker/u16:4-bwmon_wq, 290, 6.66%, 48960000 kworker/u16:1-memlat_wq, 270, 6.20%, 0 ipcdaemon, 220, 5.05%, 218304000 10, com.google.android.apps.geo.automotive.adas, 1509, 0.32%, 1756416000 adas:publishing, 1490, 98.74%, 1735680000 as:clientparams, 10, 0.66%, 20736000 0, com.android.vending, 796, 0.17%, 765504000 android.vending, 790, 99.25%, 765504000 0, shared:com.google.uid.shared, 581, 0.12%, 481152000 google.android.gms, 340, 58.52%, 237312000 .gms.persistent, 190, 32.70%, 184512000 process.gservices, 50, 8.61%, 59328000 0, gps, 507, 0.11%, 659136000 binder:920_2, 500, 98.62%, 659136000 10, com.android.vending, 489, 0.10%, 372288000 android.vending, 480, 98.16%, 372288000 0, shared:android.uid.systemui, 438, 0.09%, 449856000 android.systemui, 440, 100.46%, 449856000 Top N Storage I/O 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 Storage I/O Writes: ------------------------- Android User ID, Package Name, Foreground Bytes, Foreground Bytes %, Foreground Fsync, Foreground Fsync %, Background Bytes, Background Bytes %, Background Fsync, Background Fsync % 0, com.android.vending, 0, 0.00%, 0, 0.00%, 520192, 46.35%, 20, 47.62% 10, com.android.vending, 0, 0.00%, 0, 0.00%, 520192, 46.35%, 20, 47.62% 10, shared:com.google.uid.shared, 0, 0.00%, 0, 0.00%, 45056, 4.01%, 0, 0.00% 0, shared:com.google.uid.shared, 0, 0.00%, 0, 0.00%, 36864, 3.28%, 2, 4.76% 0, logd, 24576, 40.00%, 0, 0.00%, 0, 0.00%, 0, 0.00% 0, root, 20480, 33.33%, 0, 0.00%, 0, 0.00%, 0, 0.00% 0, system, 16384, 26.67%, 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, 2, 0.39% dp_hdcp2p2, 1, 50.00% hdcp_2x, 1, 50.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, com.android.vending, 104, 48.83% android.vending, 104, 100.00% 10, com.android.vending, 104, 48.83% android.vending, 104, 100.00% 0, shared:com.google.uid.shared, 4, 1.88% .gms.persistent, 4, 100.00% 10, shared:com.google.uid.shared, 1, 0.47% .gms.persistent, 1, 100.00% Number of major page faults since last collection: 213 Percentage of change in major page faults since last collection: 0.00%
如果捕获 bug 报告,在不使用任何参数的情况下运行监控定时器 dumpsys 命令,或者停止自定义收集会话,监控定时器原生服务会转储与上述报告类似的性能数据报告。
该报告包含系统启动期间收集的数据,以及报告生成前的最后 N 分钟收集的数据。
项 | 说明 |
---|---|
启动时收集信息 | 提供有关启动时性能数据收集会话的信息。 |
唤醒收集信息 | 提供系统从挂起状态唤醒时有关唤醒性能数据收集会话的信息。 |
用户切换集合信息 | 提供用户切换时性能数据收集会话的相关信息。 |
定期收集信息 | 提供有关启动完成后开始的定期性能收集会话的信息。 |
启动时性能报告 | 包含系统启动期间收集的性能数据。在系统关闭之前,这些数据会一直保留在内存中,因此数据会转储到所有报告中。 |
唤醒效果报告 | 包含在唤醒期间收集的性能数据。在系统关闭之前,这些数据将永久保留在内存中,因此这些数据会转储到所有报告中。 |
用户切换效果报告 | 包含在用户切换期间收集的性能数据。在系统关闭之前,这些数据会一直保留在内存中,因此数据会转储到所有报告中。 |
过去 N 分钟的 I/O 性能报告 | 包含报告生成前最后 N 分钟内(通过定期收集会话)收集的性能数据。 |
收集时长 | 性能数据收集的总时长。 |
集合数 | 单个报告中报告的集合总数。 |
报告中报告的每次收集都可能包含以下所有内容或部分内容。每次收集中报告的统计信息都是自上次收集之后的增量数据,但瞬时性的统计信息(例如,自系统启动之后未汇总的统计信息)除外。
项 | 说明 |
---|---|
CPU I/O 等待时间/百分比 | 自上次收集以来,由于 I/O 操作导致上下文切换或等待而花费的绝对 CPU 时间及其占总 CPU 时间的百分比。 |
总 CPU 时间 | 总 CPU 时间(以毫秒为单位)。 |
总空闲 CPU 时间 | 处于空闲状态的总 CPU 时间。 |
CPU I/O 等待时间 | CPU 等待 I/O 操作所用的总时间。 |
上下文切换次数 | 从一个进程或线程切换到另一个进程或线程的 CPU 数量。 |
I/O 阻塞进程数/百分比 | 自上次收集以来,被阻塞等待 I/O 的进程总数和被阻塞的进程所占的百分比。 |
前 N 个 CPU 时间 |
自上次收集以来,占用最多 CPU 时间的前 N 个软件包:
|
前 N 个存储 I/O 读取 |
自上次收集以来,从磁盘读取数据最多的前 N 个软件包。 每行都包含用户 ID、软件包名称、在前台模式与后台模式下读取的字节总数、系统中所有前台模式与后台模式读取的字节百分比、在前台模式与后台模式下进行的 |
前 N 个存储 I/O 写入 | 自上次收集以来,向磁盘写入数据最多的前 N 个软件包。每行包含的字段与“热门 N 次读取”中的字段类似。 |
前 N 个 I/O 等待 UID | I/O 等待任务最多的前 N 个软件包。
|
前 N 个主要页面错误 | 自上次收集以来,出现最严重页面故障的前 N 个软件包。 |