From ec47f620fe7f56893e6705ac20f19557e0d01e3d Mon Sep 17 00:00:00 2001 From: Darren Hsu Date: Wed, 20 Dec 2023 20:49:37 +0800 Subject: [PATCH] powerstats: use display MRR state residency data provider Bug: 317193845 Test: vts-tradefed run vts -m VtsHalPowerStatsTargetTest Change-Id: If0b226c02eeee67f3dbc3bd0f7551ccb1f13bfee Signed-off-by: Darren Hsu --- powerstats/husky/service.cpp | 68 ++++++++++++++++++++---------------- powerstats/shiba/service.cpp | 30 ++++++++++------ 2 files changed, 57 insertions(+), 41 deletions(-) diff --git a/powerstats/husky/service.cpp b/powerstats/husky/service.cpp index 7bcafbc..2e69292 100644 --- a/powerstats/husky/service.cpp +++ b/powerstats/husky/service.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::EnergyConsumerType; @@ -33,37 +34,44 @@ using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer; void addDisplay(std::shared_ptr p) { // Add display residency stats - std::vector states = { - "Off", - "LP: 1008x2244@1", - "LP: 1008x2244@30", - "On: 1008x2244@1", - "On: 1008x2244@10", - "On: 1008x2244@30", - "On: 1008x2244@60", - "On: 1008x2244@120", - "HBM: 1008x2244@1", - "HBM: 1008x2244@10", - "HBM: 1008x2244@30", - "HBM: 1008x2244@60", - "HBM: 1008x2244@120", - "LP: 1344x2992@1", - "LP: 1344x2992@30", - "On: 1344x2992@1", - "On: 1344x2992@10", - "On: 1344x2992@30", - "On: 1344x2992@60", - "On: 1344x2992@120", - "HBM: 1344x2992@1", - "HBM: 1344x2992@10", - "HBM: 1344x2992@30", - "HBM: 1344x2992@60", - "HBM: 1344x2992@120"}; + struct stat buffer; + if (stat("/sys/class/backlight/panel0-backlight/time_in_state", &buffer)) { + // time_in_state doesn't exist + std::vector states = { + "Off", + "LP: 1008x2244@1", + "LP: 1008x2244@30", + "On: 1008x2244@1", + "On: 1008x2244@10", + "On: 1008x2244@30", + "On: 1008x2244@60", + "On: 1008x2244@120", + "HBM: 1008x2244@1", + "HBM: 1008x2244@10", + "HBM: 1008x2244@30", + "HBM: 1008x2244@60", + "HBM: 1008x2244@120", + "LP: 1344x2992@1", + "LP: 1344x2992@30", + "On: 1344x2992@1", + "On: 1344x2992@10", + "On: 1344x2992@30", + "On: 1344x2992@60", + "On: 1344x2992@120", + "HBM: 1344x2992@1", + "HBM: 1344x2992@10", + "HBM: 1344x2992@30", + "HBM: 1344x2992@60", + "HBM: 1344x2992@120"}; - p->addStateResidencyDataProvider(std::make_unique( - "Display", - "/sys/class/backlight/panel0-backlight/state", - states)); + p->addStateResidencyDataProvider(std::make_unique( + "Display", + "/sys/class/backlight/panel0-backlight/state", + states)); + } else { + // time_in_state exists + addDisplayMRR(p); + } // Add display energy consumer p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterConsumer( diff --git a/powerstats/shiba/service.cpp b/powerstats/shiba/service.cpp index c29fbca..a4c695c 100644 --- a/powerstats/shiba/service.cpp +++ b/powerstats/shiba/service.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::EnergyConsumerType; @@ -33,18 +34,25 @@ using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer; void addDisplay(std::shared_ptr p) { // Add display residency stats - std::vector states = { - "Off", - "LP: 1080x2400@30", - "On: 1080x2400@60", - "On: 1080x2400@120", - "HBM: 1080x2400@60", - "HBM: 1080x2400@120"}; + struct stat buffer; + if (stat("/sys/class/backlight/panel0-backlight/time_in_state", &buffer)) { + // time_in_state doesn't exist + std::vector states = { + "Off", + "LP: 1080x2400@30", + "On: 1080x2400@60", + "On: 1080x2400@120", + "HBM: 1080x2400@60", + "HBM: 1080x2400@120"}; - p->addStateResidencyDataProvider(std::make_unique( - "Display", - "/sys/class/backlight/panel0-backlight/state", - states)); + p->addStateResidencyDataProvider(std::make_unique( + "Display", + "/sys/class/backlight/panel0-backlight/state", + states)); + } else { + // time_in_state exists + addDisplayMRR(p); + } // Add display energy consumer p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterConsumer(