Skip to content

Commit

Permalink
Kernel wakelocks data source.
Browse files Browse the repository at this point in the history
This polls the suspend control service at a configurable interval and records what we get back. We intern wakelock metadata (name and type) and delta-ify the change to get smaller integers.

Bug: 389077525
Change-Id: I10558d3a5de6bb5a2e5f8a69cea58eebaa4a88aa
  • Loading branch information
Simon MacMullen committed Jan 14, 2025
1 parent 804e1cd commit 1a22d53
Show file tree
Hide file tree
Showing 19 changed files with 667 additions and 5 deletions.
43 changes: 43 additions & 0 deletions Android.bp

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ perfetto_cc_library(
":src_kernel_utils_syscall_table",
":src_protozero_proto_ring_buffer",
":src_traced_probes_android_game_intervention_list_android_game_intervention_list",
":src_traced_probes_android_kernel_wakelocks_android_kernel_wakelocks",
":src_traced_probes_android_log_android_log",
":src_traced_probes_android_system_property_android_system_property",
":src_traced_probes_common_common",
Expand Down Expand Up @@ -1204,6 +1205,7 @@ perfetto_filegroup(
"src/android_internal/power_stats.h",
"src/android_internal/statsd.h",
"src/android_internal/statsd_logging.h",
"src/android_internal/suspend_control_service.h",
"src/android_internal/tracing_service_proxy.h",
],
)
Expand Down Expand Up @@ -3924,6 +3926,15 @@ perfetto_filegroup(
],
)

# GN target: //src/traced/probes/android_kernel_wakelocks:android_kernel_wakelocks
perfetto_filegroup(
name = "src_traced_probes_android_kernel_wakelocks_android_kernel_wakelocks",
srcs = [
"src/traced/probes/android_kernel_wakelocks/android_kernel_wakelocks_data_source.cc",
"src/traced/probes/android_kernel_wakelocks/android_kernel_wakelocks_data_source.h",
],
)

# GN target: //src/traced/probes/android_log:android_log
perfetto_filegroup(
name = "src_traced_probes_android_log_android_log",
Expand Down Expand Up @@ -4731,6 +4742,7 @@ perfetto_proto_library(
"protos/perfetto/config/android/android_polled_state_config.proto",
"protos/perfetto/config/android/android_sdk_sysprop_guard_config.proto",
"protos/perfetto/config/android/android_system_property_config.proto",
"protos/perfetto/config/android/kernel_wakelocks_config.proto",
"protos/perfetto/config/android/network_trace_config.proto",
"protos/perfetto/config/android/packages_list_config.proto",
"protos/perfetto/config/android/pixel_modem_config.proto",
Expand Down Expand Up @@ -5497,6 +5509,7 @@ perfetto_proto_library(
"protos/perfetto/trace/android/gpu_mem_event.proto",
"protos/perfetto/trace/android/graphics_frame_event.proto",
"protos/perfetto/trace/android/initial_display_state.proto",
"protos/perfetto/trace/android/kernel_wakelock_data.proto",
"protos/perfetto/trace/android/network_trace.proto",
"protos/perfetto/trace/android/packages_list.proto",
"protos/perfetto/trace/android/pixel_modem_events.proto",
Expand Down
1 change: 1 addition & 0 deletions protos/perfetto/config/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ perfetto_proto_library("@TYPE@") {
"android_polled_state_config.proto",
"android_sdk_sysprop_guard_config.proto",
"android_system_property_config.proto",
"kernel_wakelocks_config.proto",
"network_trace_config.proto",
"packages_list_config.proto",
"pixel_modem_config.proto",
Expand Down
25 changes: 25 additions & 0 deletions protos/perfetto/config/android/kernel_wakelocks_config.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2025 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;

// Data source that records kernel (and native) wakelock data.
message KernelWakelocksConfig {
// Record at this frequency.
optional uint32 poll_ms = 1;
}
6 changes: 5 additions & 1 deletion protos/perfetto/config/data_source_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import "protos/perfetto/config/android/android_log_config.proto";
import "protos/perfetto/config/android/android_polled_state_config.proto";
import "protos/perfetto/config/android/android_system_property_config.proto";
import "protos/perfetto/config/android/android_sdk_sysprop_guard_config.proto";
import "protos/perfetto/config/android/kernel_wakelocks_config.proto";
import "protos/perfetto/config/android/network_trace_config.proto";
import "protos/perfetto/config/android/packages_list_config.proto";
import "protos/perfetto/config/android/pixel_modem_config.proto";
Expand Down Expand Up @@ -52,7 +53,7 @@ import "protos/perfetto/config/track_event/track_event_config.proto";
import "protos/perfetto/config/system_info/system_info.proto";

// The configuration that is passed to each data source when starting tracing.
// Next id: 132
// Next id: 133
message DataSourceConfig {
enum SessionInitiator {
SESSION_INITIATOR_UNSPECIFIED = 0;
Expand Down Expand Up @@ -210,6 +211,9 @@ message DataSourceConfig {
// Data source name: org.chromium.system_metrics
optional ChromiumSystemMetricsConfig chromium_system_metrics = 131 [lazy = true];

// Data source name: android.kernel_wakelocks
optional KernelWakelocksConfig kernel_wakelocks_config = 132 [lazy = true];

// This is a fallback mechanism to send a free-form text config to the
// producer. In theory this should never be needed. All the code that
// is part of the platform (i.e. traced service) is supposed to *not* truncate
Expand Down
15 changes: 14 additions & 1 deletion protos/perfetto/config/perfetto_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,16 @@ message AndroidSystemPropertyConfig {

// End of protos/perfetto/config/android/android_system_property_config.proto

// Begin of protos/perfetto/config/android/kernel_wakelocks_config.proto

// Data source that records kernel (and native) wakelock data.
message KernelWakelocksConfig {
// Record at this frequency.
optional uint32 poll_ms = 1;
}

// End of protos/perfetto/config/android/kernel_wakelocks_config.proto

// Begin of protos/perfetto/config/android/network_trace_config.proto

// Network tracing data source that records details on all packets sent or
Expand Down Expand Up @@ -3601,7 +3611,7 @@ message TrackEventConfig {
// Begin of protos/perfetto/config/data_source_config.proto

// The configuration that is passed to each data source when starting tracing.
// Next id: 132
// Next id: 133
message DataSourceConfig {
enum SessionInitiator {
SESSION_INITIATOR_UNSPECIFIED = 0;
Expand Down Expand Up @@ -3759,6 +3769,9 @@ message DataSourceConfig {
// Data source name: org.chromium.system_metrics
optional ChromiumSystemMetricsConfig chromium_system_metrics = 131 [lazy = true];

// Data source name: android.kernel_wakelocks
optional KernelWakelocksConfig kernel_wakelocks_config = 132 [lazy = true];

// This is a fallback mechanism to send a free-form text config to the
// producer. In theory this should never be needed. All the code that
// is part of the platform (i.e. traced service) is supposed to *not* truncate
Expand Down
1 change: 1 addition & 0 deletions protos/perfetto/trace/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ perfetto_proto_library("@TYPE@") {
"gpu_mem_event.proto",
"graphics_frame_event.proto",
"initial_display_state.proto",
"kernel_wakelock_data.proto",
"network_trace.proto",
"packages_list.proto",
"pixel_modem_events.proto",
Expand Down
51 changes: 51 additions & 0 deletions protos/perfetto/trace/android/kernel_wakelock_data.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2025 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;

message KernelWakelockData {
message Wakelock {
enum Type {
WAKELOCK_TYPE_UNKNOWN = 0;
WAKELOCK_TYPE_KERNEL = 1;
WAKELOCK_TYPE_NATIVE = 2;
}

// Interning id.
optional uint32 wakelock_id = 1;

// Name of the wakelock.
optional string wakelock_name = 2;

// Type of the wakelock. We record data about both true kernel wakelocks
// and "native" wakelocks which are taken in userspace but are more
// conceptually similar to kernel wakelocks than normal userspace ones.
optional Type wakelock_type = 3;
}

// This is only emitted when we encounter new wakelocks.
repeated Wakelock wakelock = 1;

// Interning id.
repeated uint32 wakelock_id = 2 [packed = true];

// If we interned the wakelock name in this packet, this is the total time
// the wakelock has been held.
// If not, it's a delta from the last time we saw it.
repeated uint64 time_held_millis = 3 [packed = true];
}
55 changes: 53 additions & 2 deletions protos/perfetto/trace/perfetto_trace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,16 @@ message AndroidSystemPropertyConfig {

// End of protos/perfetto/config/android/android_system_property_config.proto

// Begin of protos/perfetto/config/android/kernel_wakelocks_config.proto

// Data source that records kernel (and native) wakelock data.
message KernelWakelocksConfig {
// Record at this frequency.
optional uint32 poll_ms = 1;
}

// End of protos/perfetto/config/android/kernel_wakelocks_config.proto

// Begin of protos/perfetto/config/android/network_trace_config.proto

// Network tracing data source that records details on all packets sent or
Expand Down Expand Up @@ -3601,7 +3611,7 @@ message TrackEventConfig {
// Begin of protos/perfetto/config/data_source_config.proto

// The configuration that is passed to each data source when starting tracing.
// Next id: 132
// Next id: 133
message DataSourceConfig {
enum SessionInitiator {
SESSION_INITIATOR_UNSPECIFIED = 0;
Expand Down Expand Up @@ -3759,6 +3769,9 @@ message DataSourceConfig {
// Data source name: org.chromium.system_metrics
optional ChromiumSystemMetricsConfig chromium_system_metrics = 131 [lazy = true];

// Data source name: android.kernel_wakelocks
optional KernelWakelocksConfig kernel_wakelocks_config = 132 [lazy = true];

// This is a fallback mechanism to send a free-form text config to the
// producer. In theory this should never be needed. All the code that
// is part of the platform (i.e. traced service) is supposed to *not* truncate
Expand Down Expand Up @@ -5242,6 +5255,42 @@ message InitialDisplayState {

// End of protos/perfetto/trace/android/initial_display_state.proto

// Begin of protos/perfetto/trace/android/kernel_wakelock_data.proto

message KernelWakelockData {
message Wakelock {
enum Type {
WAKELOCK_TYPE_UNKNOWN = 0;
WAKELOCK_TYPE_KERNEL = 1;
WAKELOCK_TYPE_NATIVE = 2;
}

// Interning id.
optional uint32 wakelock_id = 1;

// Name of the wakelock.
optional string wakelock_name = 2;

// Type of the wakelock. We record data about both true kernel wakelocks
// and "native" wakelocks which are taken in userspace but are more
// conceptually similar to kernel wakelocks than normal userspace ones.
optional Type wakelock_type = 3;
}

// This is only emitted when we encounter new wakelocks.
repeated Wakelock wakelock = 1;

// Interning id.
repeated uint32 wakelock_id = 2 [packed = true];

// If we interned the wakelock name in this packet, this is the total time
// the wakelock has been held.
// If not, it's a delta from the last time we saw it.
repeated uint64 time_held_millis = 3 [packed = true];
}

// End of protos/perfetto/trace/android/kernel_wakelock_data.proto

// Begin of protos/perfetto/trace/android/network_trace.proto

enum TrafficDirection {
Expand Down Expand Up @@ -15738,7 +15787,7 @@ message UiState {
// See the [Buffers and Dataflow](/docs/concepts/buffers.md) doc for details.
//
// Next reserved id: 14 (up to 15).
// Next id: 115.
// Next id: 116.
message TracePacket {
// The timestamp of the TracePacket.
// By default this timestamps refers to the trace clock (CLOCK_BOOTTIME on
Expand Down Expand Up @@ -15882,6 +15931,8 @@ message TracePacket {

BluetoothTraceEvent bluetooth_trace_event = 114;

KernelWakelockData kernel_wakelock_data = 115;

// This field is only used for testing.
// In previous versions of this proto this field had the id 268435455
// This caused many problems:
Expand Down
5 changes: 4 additions & 1 deletion protos/perfetto/trace/trace_packet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import "protos/perfetto/trace/android/frame_timeline_event.proto";
import "protos/perfetto/trace/android/gpu_mem_event.proto";
import "protos/perfetto/trace/android/graphics_frame_event.proto";
import "protos/perfetto/trace/android/initial_display_state.proto";
import "protos/perfetto/trace/android/kernel_wakelock_data.proto";
import "protos/perfetto/trace/android/network_trace.proto";
import "protos/perfetto/trace/android/packages_list.proto";
import "protos/perfetto/trace/android/pixel_modem_events.proto";
Expand Down Expand Up @@ -105,7 +106,7 @@ package perfetto.protos;
// See the [Buffers and Dataflow](/docs/concepts/buffers.md) doc for details.
//
// Next reserved id: 14 (up to 15).
// Next id: 115.
// Next id: 116.
message TracePacket {
// The timestamp of the TracePacket.
// By default this timestamps refers to the trace clock (CLOCK_BOOTTIME on
Expand Down Expand Up @@ -249,6 +250,8 @@ message TracePacket {

BluetoothTraceEvent bluetooth_trace_event = 114;

KernelWakelockData kernel_wakelock_data = 115;

// This field is only used for testing.
// In previous versions of this proto this field had the id 268435455
// This caused many problems:
Expand Down
3 changes: 3 additions & 0 deletions src/android_internal/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if (perfetto_build_with_android) {
"power_stats.cc",
"statsd.cc",
"statsd_logging.cc",
"suspend_control_service.cc",
"tracing_service_proxy.cc",
]
libs = [
Expand All @@ -42,6 +43,7 @@ if (perfetto_build_with_android) {
"[email protected]",
"android.hardware.power.stats-V1-cpp",
"[email protected]",
"android.system.suspend.control.internal-cpp",
"statslog_perfetto",
"statssocket",
"cutils",
Expand Down Expand Up @@ -79,6 +81,7 @@ source_set("headers") {
"power_stats.h",
"statsd.h",
"statsd_logging.h",
"suspend_control_service.h",
"tracing_service_proxy.h",
]
}
Expand Down
Loading

0 comments on commit 1a22d53

Please sign in to comment.