From 0771a8d6fc31d931491cfe9f71d6a1ef91b88268 Mon Sep 17 00:00:00 2001 From: Mark Fasheh Date: Thu, 14 Sep 2023 19:21:15 +0000 Subject: [PATCH] Add android_boot metric For now his computes the total time certain processes spend in uinterruptible sleep as well as the total duration of all scheduling slices owned by the given process. Right now we only care about uninterruptible sleep, but the proto is designed so that we can easily append more fields for different scheduling states. We pick the name 'android_boot' to make it clear that this proto can be used for future boot related metrics. Test: --run-metrics android_boot Test: tools/diff_test_trace_processor.py --name-filter='.*android_boot*' Bug: 300681738 Change-Id: I5ded2c78cdaab32cbca94bd1b9c1ef9149a32ea5 --- Android.bp | 4 ++ BUILD | 2 + protos/perfetto/metrics/android/BUILD.gn | 1 + .../metrics/android/android_boot.proto | 32 ++++++++++++ protos/perfetto/metrics/metrics.proto | 5 +- .../metrics/perfetto_merged_metrics.proto | 21 +++++++- .../trace_processor/metrics.descriptor | 19 +++++-- .../metrics/sql/android/BUILD.gn | 1 + .../metrics/sql/android/android_boot.sql | 51 +++++++++++++++++++ test/data/android_boot.pftrace.sha256 | 1 + .../diff_tests/android/tests.py | 13 +++++ 11 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 protos/perfetto/metrics/android/android_boot.proto create mode 100644 src/trace_processor/metrics/sql/android/android_boot.sql create mode 100644 test/data/android_boot.pftrace.sha256 diff --git a/Android.bp b/Android.bp index 081ab9b155..617ddb5827 100644 --- a/Android.bp +++ b/Android.bp @@ -4589,6 +4589,7 @@ genrule { srcs: [ "protos/perfetto/metrics/android/android_blocking_call.proto", "protos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto", + "protos/perfetto/metrics/android/android_boot.proto", "protos/perfetto/metrics/android/android_frame_timeline_metric.proto", "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto", "protos/perfetto/metrics/android/android_trusty_workqueues.proto", @@ -4669,6 +4670,7 @@ genrule { srcs: [ "protos/perfetto/metrics/android/android_blocking_call.proto", "protos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto", + "protos/perfetto/metrics/android/android_boot.proto", "protos/perfetto/metrics/android/android_frame_timeline_metric.proto", "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto", "protos/perfetto/metrics/android/android_trusty_workqueues.proto", @@ -4732,6 +4734,7 @@ genrule { srcs: [ "protos/perfetto/metrics/android/android_blocking_call.proto", "protos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto", + "protos/perfetto/metrics/android/android_boot.proto", "protos/perfetto/metrics/android/android_frame_timeline_metric.proto", "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto", "protos/perfetto/metrics/android/android_trusty_workqueues.proto", @@ -10431,6 +10434,7 @@ genrule { "src/trace_processor/metrics/sql/android/android_batt.sql", "src/trace_processor/metrics/sql/android/android_binder.sql", "src/trace_processor/metrics/sql/android/android_blocking_calls_cuj_metric.sql", + "src/trace_processor/metrics/sql/android/android_boot.sql", "src/trace_processor/metrics/sql/android/android_camera.sql", "src/trace_processor/metrics/sql/android/android_camera_unagg.sql", "src/trace_processor/metrics/sql/android/android_cpu.sql", diff --git a/BUILD b/BUILD index ee2d513b37..71f4144fb0 100644 --- a/BUILD +++ b/BUILD @@ -1994,6 +1994,7 @@ perfetto_filegroup( "src/trace_processor/metrics/sql/android/android_batt.sql", "src/trace_processor/metrics/sql/android/android_binder.sql", "src/trace_processor/metrics/sql/android/android_blocking_calls_cuj_metric.sql", + "src/trace_processor/metrics/sql/android/android_boot.sql", "src/trace_processor/metrics/sql/android/android_camera.sql", "src/trace_processor/metrics/sql/android/android_camera_unagg.sql", "src/trace_processor/metrics/sql/android/android_cpu.sql", @@ -4223,6 +4224,7 @@ perfetto_proto_library( srcs = [ "protos/perfetto/metrics/android/android_blocking_call.proto", "protos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto", + "protos/perfetto/metrics/android/android_boot.proto", "protos/perfetto/metrics/android/android_frame_timeline_metric.proto", "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto", "protos/perfetto/metrics/android/android_trusty_workqueues.proto", diff --git a/protos/perfetto/metrics/android/BUILD.gn b/protos/perfetto/metrics/android/BUILD.gn index 74e7a72f7f..a2ae264f44 100644 --- a/protos/perfetto/metrics/android/BUILD.gn +++ b/protos/perfetto/metrics/android/BUILD.gn @@ -22,6 +22,7 @@ perfetto_proto_library("@TYPE@") { sources = [ "android_blocking_call.proto", "android_blocking_calls_cuj_metric.proto", + "android_boot.proto", "android_frame_timeline_metric.proto", "android_sysui_notifications_blocking_calls_metric.proto", "android_trusty_workqueues.proto", diff --git a/protos/perfetto/metrics/android/android_boot.proto b/protos/perfetto/metrics/android/android_boot.proto new file mode 100644 index 0000000000..820b4e05bf --- /dev/null +++ b/protos/perfetto/metrics/android/android_boot.proto @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto2"; + +package perfetto.protos; + +// This metric computes how much time processes spend in UNINTERRUPTIBLE_SLEEP state +message ProcessStateDurations { + optional int64 total_dur = 2; + optional int64 uninterruptible_sleep_dur = 3; +} + +message AndroidBootMetric { + optional ProcessStateDurations system_server_durations = 1; + optional ProcessStateDurations systemui_durations = 2; + optional ProcessStateDurations launcher_durations = 3; + optional ProcessStateDurations gms_durations = 4; +} diff --git a/protos/perfetto/metrics/metrics.proto b/protos/perfetto/metrics/metrics.proto index 94c7666c79..95fd3b4cac 100644 --- a/protos/perfetto/metrics/metrics.proto +++ b/protos/perfetto/metrics/metrics.proto @@ -18,6 +18,7 @@ syntax = "proto2"; package perfetto.protos; +import "protos/perfetto/metrics/android/android_boot.proto"; import "protos/perfetto/metrics/android/android_frame_timeline_metric.proto"; import "protos/perfetto/metrics/android/anr_metric.proto"; import "protos/perfetto/metrics/android/batt_metric.proto"; @@ -108,7 +109,7 @@ message TraceAnalysisStats { // Root message for all Perfetto-based metrics. // -// Next id: 57 +// Next id: 58 message TraceMetrics { reserved 4, 10, 13, 14, 16, 19; @@ -263,6 +264,8 @@ message TraceMetrics { // Aggregated Android Monitor Contention metrics optional AndroidMonitorContentionAggMetric android_monitor_contention_agg = 56; + optional AndroidBootMetric android_boot = 57; + // Demo extensions. extensions 450 to 499; diff --git a/protos/perfetto/metrics/perfetto_merged_metrics.proto b/protos/perfetto/metrics/perfetto_merged_metrics.proto index 70a1f52256..e940682188 100644 --- a/protos/perfetto/metrics/perfetto_merged_metrics.proto +++ b/protos/perfetto/metrics/perfetto_merged_metrics.proto @@ -105,6 +105,23 @@ message AndroidBlockingCallsCujMetric { // End of protos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto +// Begin of protos/perfetto/metrics/android/android_boot.proto + +// This metric computes how much time processes spend in UNINTERRUPTIBLE_SLEEP state +message ProcessStateDurations { + optional int64 total_dur = 2; + optional int64 uninterruptible_sleep_dur = 3; +} + +message AndroidBootMetric { + optional ProcessStateDurations system_server_durations = 1; + optional ProcessStateDurations systemui_durations = 2; + optional ProcessStateDurations launcher_durations = 3; + optional ProcessStateDurations gms_durations = 4; +} + +// End of protos/perfetto/metrics/android/android_boot.proto + // Begin of protos/perfetto/metrics/android/android_frame_timeline_metric.proto message AndroidFrameTimelineMetric { @@ -2266,7 +2283,7 @@ message TraceAnalysisStats { // Root message for all Perfetto-based metrics. // -// Next id: 57 +// Next id: 58 message TraceMetrics { reserved 4, 10, 13, 14, 16, 19; @@ -2421,6 +2438,8 @@ message TraceMetrics { // Aggregated Android Monitor Contention metrics optional AndroidMonitorContentionAggMetric android_monitor_contention_agg = 56; + optional AndroidBootMetric android_boot = 57; + // Demo extensions. extensions 450 to 499; diff --git a/python/perfetto/trace_processor/metrics.descriptor b/python/perfetto/trace_processor/metrics.descriptor index ad0d5dac52..926dee9cd4 100644 --- a/python/perfetto/trace_processor/metrics.descriptor +++ b/python/perfetto/trace_processor/metrics.descriptor @@ -1,4 +1,14 @@ +� +2protos/perfetto/metrics/android/android_boot.protoperfetto.protos"p +ProcessStateDurations + total_dur (RtotalDur: +uninterruptible_sleep_dur (RuninterruptibleSleepDur"� +AndroidBootMetric^ +system_server_durations ( 2&.perfetto.protos.ProcessStateDurationsRsystemServerDurationsU +systemui_durations ( 2&.perfetto.protos.ProcessStateDurationsRsystemuiDurationsU +launcher_durations ( 2&.perfetto.protos.ProcessStateDurationsRlauncherDurationsK + gms_durations ( 2&.perfetto.protos.ProcessStateDurationsR gmsDurations � 6protos/perfetto/metrics/android/process_metadata.protoperfetto.protos"� AndroidProcessMetadata @@ -1041,8 +1051,8 @@ Cprotos/perfetto/metrics/android/monitor_contention_agg_metric.protoperfetto.p total_contention_dur (RtotalContentionDur? main_thread_contention_count (RmainThreadContentionCount; main_thread_contention_dur (RmainThreadContentionDur -�; -%protos/perfetto/metrics/metrics.protoperfetto.protosCprotos/perfetto/metrics/android/android_frame_timeline_metric.proto0protos/perfetto/metrics/android/anr_metric.proto1protos/perfetto/metrics/android/batt_metric.protoWprotos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.protoGprotos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto3protos/perfetto/metrics/android/codec_metrics.proto0protos/perfetto/metrics/android/cpu_metric.proto3protos/perfetto/metrics/android/camera_metric.proto9protos/perfetto/metrics/android/camera_unagg_metric.proto5protos/perfetto/metrics/android/display_metrics.proto5protos/perfetto/metrics/android/dma_heap_metric.proto1protos/perfetto/metrics/android/dvfs_metric.proto4protos/perfetto/metrics/android/fastrpc_metric.proto0protos/perfetto/metrics/android/g2d_metric.proto0protos/perfetto/metrics/android/gpu_metric.proto0protos/perfetto/metrics/android/hwcomposer.proto1protos/perfetto/metrics/android/hwui_metric.proto/protos/perfetto/metrics/android/io_metric.proto5protos/perfetto/metrics/android/io_unagg_metric.proto0protos/perfetto/metrics/android/ion_metric.proto8protos/perfetto/metrics/android/irq_runtime_metric.proto5protos/perfetto/metrics/android/jank_cuj_metric.proto9protos/perfetto/metrics/android/java_heap_histogram.proto5protos/perfetto/metrics/android/java_heap_stats.proto0protos/perfetto/metrics/android/lmk_metric.proto7protos/perfetto/metrics/android/lmk_reason_metric.proto0protos/perfetto/metrics/android/mem_metric.proto6protos/perfetto/metrics/android/mem_unagg_metric.proto6protos/perfetto/metrics/android/multiuser_metric.proto4protos/perfetto/metrics/android/network_metric.proto2protos/perfetto/metrics/android/other_traces.proto2protos/perfetto/metrics/android/package_list.proto5protos/perfetto/metrics/android/powrails_metric.proto4protos/perfetto/metrics/android/profiler_smaps.proto7protos/perfetto/metrics/android/rt_runtime_metric.proto0protos/perfetto/metrics/android/simpleperf.proto4protos/perfetto/metrics/android/startup_metric.proto4protos/perfetto/metrics/android/surfaceflinger.proto0protos/perfetto/metrics/android/task_names.proto3protos/perfetto/metrics/android/trace_quality.proto?protos/perfetto/metrics/android/android_trusty_workqueues.proto9protos/perfetto/metrics/android/unsymbolized_frames.proto3protos/perfetto/metrics/android/binder_metric.proto?protos/perfetto/metrics/android/monitor_contention_metric.protoCprotos/perfetto/metrics/android/monitor_contention_agg_metric.proto"� +�< +%protos/perfetto/metrics/metrics.protoperfetto.protos2protos/perfetto/metrics/android/android_boot.protoCprotos/perfetto/metrics/android/android_frame_timeline_metric.proto0protos/perfetto/metrics/android/anr_metric.proto1protos/perfetto/metrics/android/batt_metric.protoWprotos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.protoGprotos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto3protos/perfetto/metrics/android/codec_metrics.proto0protos/perfetto/metrics/android/cpu_metric.proto3protos/perfetto/metrics/android/camera_metric.proto9protos/perfetto/metrics/android/camera_unagg_metric.proto5protos/perfetto/metrics/android/display_metrics.proto5protos/perfetto/metrics/android/dma_heap_metric.proto1protos/perfetto/metrics/android/dvfs_metric.proto4protos/perfetto/metrics/android/fastrpc_metric.proto0protos/perfetto/metrics/android/g2d_metric.proto0protos/perfetto/metrics/android/gpu_metric.proto0protos/perfetto/metrics/android/hwcomposer.proto1protos/perfetto/metrics/android/hwui_metric.proto/protos/perfetto/metrics/android/io_metric.proto5protos/perfetto/metrics/android/io_unagg_metric.proto0protos/perfetto/metrics/android/ion_metric.proto8protos/perfetto/metrics/android/irq_runtime_metric.proto5protos/perfetto/metrics/android/jank_cuj_metric.proto9protos/perfetto/metrics/android/java_heap_histogram.proto5protos/perfetto/metrics/android/java_heap_stats.proto0protos/perfetto/metrics/android/lmk_metric.proto7protos/perfetto/metrics/android/lmk_reason_metric.proto0protos/perfetto/metrics/android/mem_metric.proto6protos/perfetto/metrics/android/mem_unagg_metric.proto6protos/perfetto/metrics/android/multiuser_metric.proto4protos/perfetto/metrics/android/network_metric.proto2protos/perfetto/metrics/android/other_traces.proto2protos/perfetto/metrics/android/package_list.proto5protos/perfetto/metrics/android/powrails_metric.proto4protos/perfetto/metrics/android/profiler_smaps.proto7protos/perfetto/metrics/android/rt_runtime_metric.proto0protos/perfetto/metrics/android/simpleperf.proto4protos/perfetto/metrics/android/startup_metric.proto4protos/perfetto/metrics/android/surfaceflinger.proto0protos/perfetto/metrics/android/task_names.proto3protos/perfetto/metrics/android/trace_quality.proto?protos/perfetto/metrics/android/android_trusty_workqueues.proto9protos/perfetto/metrics/android/unsymbolized_frames.proto3protos/perfetto/metrics/android/binder_metric.proto?protos/perfetto/metrics/android/monitor_contention_metric.protoCprotos/perfetto/metrics/android/monitor_contention_agg_metric.proto"� TraceMetadata* trace_duration_ns (RtraceDurationNs @@ -1071,7 +1081,7 @@ trace_uuid ( R traceUuid: Source SOURCE_UNKNOWN SOURCE_TRACE -SOURCE_ANALYSIS"� +SOURCE_ANALYSIS"� TraceMetricsH android_batt ( 2%.perfetto.protos.AndroidBatteryMetricR androidBattB android_cpu ( 2!.perfetto.protos.AndroidCpuMetricR @@ -1127,5 +1137,6 @@ android_io5 ( 2.perfetto.protos.AndroidIoR androidIoP android_io_unagg6 ( 2&.perfetto.protos.AndroidIoUnaggregatedRandroidIoUnaggB android_anr7 ( 2!.perfetto.protos.AndroidAnrMetricR androidAnrw -android_monitor_contention_agg8 ( 22.perfetto.protos.AndroidMonitorContentionAggMetricRandroidMonitorContentionAgg*��*��*��*��JJ +android_monitor_contention_agg8 ( 22.perfetto.protos.AndroidMonitorContentionAggMetricRandroidMonitorContentionAggE + android_boot9 ( 2".perfetto.protos.AndroidBootMetricR androidBoot*��*��*��*��JJ  J JJJJJJ \ No newline at end of file diff --git a/src/trace_processor/metrics/sql/android/BUILD.gn b/src/trace_processor/metrics/sql/android/BUILD.gn index 99223c0367..6c31943dda 100644 --- a/src/trace_processor/metrics/sql/android/BUILD.gn +++ b/src/trace_processor/metrics/sql/android/BUILD.gn @@ -23,6 +23,7 @@ perfetto_sql_source_set("android") { "android_batt.sql", "android_binder.sql", "android_blocking_calls_cuj_metric.sql", + "android_boot.sql", "android_camera.sql", "android_camera_unagg.sql", "android_cpu.sql", diff --git a/src/trace_processor/metrics/sql/android/android_boot.sql b/src/trace_processor/metrics/sql/android/android_boot.sql new file mode 100644 index 0000000000..46caea8f3e --- /dev/null +++ b/src/trace_processor/metrics/sql/android/android_boot.sql @@ -0,0 +1,51 @@ +-- +-- Copyright 2023 The Android Open Source Project +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- https://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +INCLUDE PERFETTO MODULE android.process_metadata; + +CREATE PERFETTO FUNCTION get_durations(process_name STRING) +RETURNS TABLE(uint_sleep_dur LONG, total_dur LONG) AS +SELECT + SUM(CASE WHEN thread_state.state="D" then thread_state.dur ELSE 0 END) AS uint_sleep_dur, + SUM(thread_state.dur) as total_dur +FROM android_process_metadata +INNER JOIN thread ON thread.upid=android_process_metadata.upid +INNER JOIN thread_state ON thread.utid=thread_state.utid WHERE android_process_metadata.process_name=$process_name; + +DROP VIEW IF EXISTS android_boot_output; +CREATE VIEW android_boot_output AS +SELECT AndroidBootMetric( + 'system_server_durations', ( + SELECT NULL_IF_EMPTY(ProcessStateDurations( + 'total_dur', total_dur, + 'uninterruptible_sleep_dur', uint_sleep_dur)) + FROM get_durations('system_server')), + 'systemui_durations', ( + SELECT NULL_IF_EMPTY(ProcessStateDurations( + 'total_dur', total_dur, + 'uninterruptible_sleep_dur', uint_sleep_dur)) + FROM get_durations('com.android.systemui')), + 'launcher_durations', ( + SELECT NULL_IF_EMPTY(ProcessStateDurations( + 'total_dur', total_dur, + 'uninterruptible_sleep_dur', uint_sleep_dur)) + FROM get_durations('com.google.android.apps.nexuslauncher')), + 'gms_durations', ( + SELECT NULL_IF_EMPTY(ProcessStateDurations( + 'total_dur', total_dur, + 'uninterruptible_sleep_dur', uint_sleep_dur)) + FROM get_durations('com.google.android.gms.persistent')) +); diff --git a/test/data/android_boot.pftrace.sha256 b/test/data/android_boot.pftrace.sha256 new file mode 100644 index 0000000000..1d9798f483 --- /dev/null +++ b/test/data/android_boot.pftrace.sha256 @@ -0,0 +1 @@ +660231895e7c1816bcbd02771fdf825917ba0540124c3fdd174c1a91470b9448 \ No newline at end of file diff --git a/test/trace_processor/diff_tests/android/tests.py b/test/trace_processor/diff_tests/android/tests.py index fcf165cf6d..8bbbeb7056 100644 --- a/test/trace_processor/diff_tests/android/tests.py +++ b/test/trace_processor/diff_tests/android/tests.py @@ -1173,3 +1173,16 @@ def test_binder_graph_valid_oom(self): /system/bin/servicemanager (0x0) /system/bin/storaged (0x0) """)) + + def test_android_boot(self): + return DiffTestBlueprint( + trace=DataPath('android_boot.pftrace'), + query=Metric('android_boot'), + out=TextProto(r""" + android_boot { + system_server_durations { + total_dur: 267193980530 + uninterruptible_sleep_dur: 3843119529 + } + } + """))