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
This commit is contained in:
parent
7af6d0fecc
commit
3bad122962
2 changed files with 10 additions and 3 deletions
|
@ -32,15 +32,19 @@ void PowerStats::addStateResidencyDataProvider(std::unique_ptr<IStateResidencyDa
|
|||
}
|
||||
|
||||
int32_t id = mPowerEntityInfos.size();
|
||||
auto info = p->getInfo();
|
||||
|
||||
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<int32_t>& 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
|
||||
|
|
|
@ -73,6 +73,8 @@ class PowerStats : public BnPowerStats {
|
|||
private:
|
||||
std::vector<std::unique_ptr<IStateResidencyDataProvider>> mStateResidencyDataProviders;
|
||||
std::vector<PowerEntity> mPowerEntityInfos;
|
||||
/* Index that maps each power entity id to an entry in mStateResidencyDataProviders */
|
||||
std::vector<size_t> mStateResidencyDataProviderIndex;
|
||||
|
||||
std::vector<std::unique_ptr<IEnergyConsumer>> mEnergyConsumers;
|
||||
std::vector<EnergyConsumer> mEnergyConsumerInfos;
|
||||
|
|
Loading…
Reference in a new issue