From 1000b4e9fa0e72c81f2fcee40cf5ea953aec4efb Mon Sep 17 00:00:00 2001 From: Kelly Rossmoyer Date: Fri, 12 Oct 2018 17:38:28 -0700 Subject: [PATCH] PowerHAL: add debug support for low power stats The HAL API includes a "debug" interface that can be invoked from the command line to get debug output for a particular HAL. While the existing PowerHAL implementation includes support for the "debug" interface, it only includes data for the performance hinting side of the HAL. To facilitate device troubleshooting (not just of the HAL itself, but of power drain), this change expands that implementation to also include the output from calls to getPlatformLowPowerStats() and getSubsystemLowPowerStats(). On existing in-market devices where this support is present, the command lshal debug android.hardware.power@1.3::IPower/default will produce the "debug" output. The code for dumping the PowerHAL stats data is generic across device-specific PowerHAL implementations, so it is all pushed up into a new library (see topic CLs) that will eventually host additional PowerHAL implementation code. Bug: 116750864 Test: Ran code on an active P17 device. Test: Added temporary test code (triggered by appending " test" to the command above) to cover all base cases of data being present absent (test code is included in first uploaded patchset on the corresponding crosshatch CL). Change-Id: Id97534a2a9fe05bbca614c763c907daea37e9723 --- Android.bp | 17 +++++++++++++++++ device.mk | 4 ++++ power-libperfmgr/Android.bp | 3 +++ power-libperfmgr/Power.cpp | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 Android.bp diff --git a/Android.bp b/Android.bp new file mode 100644 index 00000000..61f4f2f2 --- /dev/null +++ b/Android.bp @@ -0,0 +1,17 @@ +// +// Copyright (C) 2018 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. +soong_namespace { + imports: ["hardware/google/pixel"], +} diff --git a/device.mk b/device.mk index 7d785b7e..053b3bc3 100755 --- a/device.mk +++ b/device.mk @@ -14,6 +14,10 @@ # limitations under the License. # +PRODUCT_SOONG_NAMESPACES += \ + device/google/wahoo \ + hardware/google/pixel + ifneq (,$(filter 27, $(PRODUCT_EXTRA_VNDK_VERSIONS))) _vndk_test := true endif diff --git a/power-libperfmgr/Android.bp b/power-libperfmgr/Android.bp index 8deca675..c76ff9bc 100644 --- a/power-libperfmgr/Android.bp +++ b/power-libperfmgr/Android.bp @@ -21,6 +21,9 @@ cc_binary { "-Wall", "-Werror", ], + static_libs: [ + "libpixelpowerstats", + ], shared_libs: [ "libbase", "libhidlbase", diff --git a/power-libperfmgr/Power.cpp b/power-libperfmgr/Power.cpp index 0b36c9e9..90381faf 100644 --- a/power-libperfmgr/Power.cpp +++ b/power-libperfmgr/Power.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -50,6 +52,8 @@ using ::android::hardware::power::V1_1::PowerStateSubsystemSleepState; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; +using ::hardware::google::pixel::powerstats::DumpPowerHal1_0PlatStatsToFd; +using ::hardware::google::pixel::powerstats::DumpPowerHal1_1SubsysStatsToFd; Power::Power() : mHintManager(nullptr), @@ -545,6 +549,21 @@ Return Power::debug(const hidl_handle& handle, const hidl_vec if (!android::base::WriteStringToFd(buf, fd)) { PLOG(ERROR) << "Failed to dump state to fd"; } + + // Dump platform low power stats + getPlatformLowPowerStats([fd](const auto& platStats, const auto result) { + if (!DumpPowerHal1_0PlatStatsToFd(result, platStats, fd)) { + PLOG(ERROR) << "Failed to dump platform low power stats to fd"; + } + }); + + // Dump subsystem low power stats + getSubsystemLowPowerStats([fd](const auto& subsysStats, const auto result) { + if (!DumpPowerHal1_1SubsysStatsToFd(result, subsysStats, fd)) { + PLOG(ERROR) << "Failed to dump subsystem low power stats to fd"; + } + }); + fsync(fd); } return Void();