Skip to content

Commit

Permalink
Merge "Add android_boot metric" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Oct 9, 2023
2 parents 58c0fe2 + 0771a8d commit 979101f
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,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",
Expand Down Expand Up @@ -4031,6 +4032,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",
Expand Down
1 change: 1 addition & 0 deletions protos/perfetto/metrics/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions protos/perfetto/metrics/android/android_boot.proto
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 4 additions & 1 deletion protos/perfetto/metrics/metrics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
21 changes: 20 additions & 1 deletion protos/perfetto/metrics/perfetto_merged_metrics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
19 changes: 15 additions & 4 deletions python/perfetto/trace_processor/metrics.descriptor
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
 JJJJJJJ
Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/metrics/sql/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
51 changes: 51 additions & 0 deletions src/trace_processor/metrics/sql/android/android_boot.sql
Original file line number Diff line number Diff line change
@@ -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'))
);
1 change: 1 addition & 0 deletions test/data/android_boot.pftrace.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
660231895e7c1816bcbd02771fdf825917ba0540124c3fdd174c1a91470b9448
13 changes: 13 additions & 0 deletions test/trace_processor/diff_tests/android/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
"""))

0 comments on commit 979101f

Please sign in to comment.