From 3bad1229625b33809e6feb35310db92f2c361dff Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Thu, 1 Apr 2021 18:25:51 -0700 Subject: [PATCH] power/stats: Index the state residency data providers Data providers that provided data for multiple entities were being added to the data structure as nullptr due to move semantics. Now they will only be added once (ensuring no more nullptr entries) and an index will map each power entity id to its corresponding data provider. Bug: 184290936 Test: Presubmit Change-Id: I858269beb36ba5f87bb14a228079f3abd6c2332f --- power/stats/aidl/default/PowerStats.cpp | 11 ++++++++--- power/stats/aidl/default/PowerStats.h | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/power/stats/aidl/default/PowerStats.cpp b/power/stats/aidl/default/PowerStats.cpp index 7cf591eb66..4b771a8be0 100644 --- a/power/stats/aidl/default/PowerStats.cpp +++ b/power/stats/aidl/default/PowerStats.cpp @@ -32,15 +32,19 @@ void PowerStats::addStateResidencyDataProvider(std::unique_ptrgetInfo(); - for (const auto& [entityName, states] : p->getInfo()) { + size_t index = mStateResidencyDataProviders.size(); + mStateResidencyDataProviders.emplace_back(std::move(p)); + + for (const auto& [entityName, states] : info) { PowerEntity i = { .id = id++, .name = entityName, .states = states, }; mPowerEntityInfos.emplace_back(i); - mStateResidencyDataProviders.emplace_back(std::move(p)); + mStateResidencyDataProviderIndex.emplace_back(index); } } @@ -92,7 +96,8 @@ ndk::ScopedAStatus PowerStats::getStateResidency(const std::vector& in_ // Check to see if we already have data for the given id std::string powerEntityName = mPowerEntityInfos[id].name; if (stateResidencies.find(powerEntityName) == stateResidencies.end()) { - mStateResidencyDataProviders[id]->getStateResidencies(&stateResidencies); + mStateResidencyDataProviders.at(mStateResidencyDataProviderIndex.at(id)) + ->getStateResidencies(&stateResidencies); } // Append results if we have them diff --git a/power/stats/aidl/default/PowerStats.h b/power/stats/aidl/default/PowerStats.h index f4c5e69569..91d272d340 100644 --- a/power/stats/aidl/default/PowerStats.h +++ b/power/stats/aidl/default/PowerStats.h @@ -73,6 +73,8 @@ class PowerStats : public BnPowerStats { private: std::vector> mStateResidencyDataProviders; std::vector mPowerEntityInfos; + /* Index that maps each power entity id to an entry in mStateResidencyDataProviders */ + std::vector mStateResidencyDataProviderIndex; std::vector> mEnergyConsumers; std::vector mEnergyConsumerInfos;