power.stats: Add more informative default implementation
The original default implementation for power.stats HAL did not have a
good example implementation of the power statistics related APIs. Adding
a new default implementation that gives a more informative example
Bug: 122267057
Test: run vts -m VtsHalPowerStatsV1_0Target
Test: adb shell "lshal debug android.hardware.power.stats@1.0::IPowerStats/default"
Observed the following output
========== PowerStats HAL 1.0 state residencies ==========
Entity State Total time Total entries Last entry timestamp
DefaultEntity Active 1 ms 2 3 ms
DefaultEntity Sleep 4 ms 5 6 ms
========== End of PowerStats HAL 1.0 state residencies ==========
Change-Id: Ida0951c267f609b16bb6406da150ed2e504ced9a
diff --git a/power/stats/1.0/default/PowerStats.h b/power/stats/1.0/default/PowerStats.h
index fb2c6a8..d67fb35 100644
--- a/power/stats/1.0/default/PowerStats.h
+++ b/power/stats/1.0/default/PowerStats.h
@@ -21,6 +21,7 @@
#include <fmq/MessageQueue.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
+#include <unordered_map>
namespace android {
namespace hardware {
@@ -60,8 +61,19 @@
std::unique_ptr<MessageQueueSync> fmqSynchronized;
};
+class IStateResidencyDataProvider {
+ public:
+ virtual ~IStateResidencyDataProvider() = default;
+ virtual bool getResults(
+ std::unordered_map<uint32_t, PowerEntityStateResidencyResult>& results) = 0;
+ virtual std::vector<PowerEntityStateSpace> getStateSpaces() = 0;
+};
+
struct PowerStats : public IPowerStats {
+ public:
PowerStats();
+ uint32_t addPowerEntity(const std::string& name, PowerEntityType type);
+ void addStateResidencyDataProvider(std::shared_ptr<IStateResidencyDataProvider> p);
// Methods from ::android::hardware::power::stats::V1_0::IPowerStats follow.
Return<void> getRailInfo(getRailInfo_cb _hidl_cb) override;
Return<void> getEnergyData(const hidl_vec<uint32_t>& railIndices,
@@ -75,12 +87,19 @@
const hidl_vec<uint32_t>& powerEntityIds,
getPowerEntityStateResidencyData_cb _hidl_cb) override;
+ // Methods from ::android::hidl::base::V1_0::IBase follow.
+ Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override;
+
private:
OnDeviceMmt mPm;
void findIioPowerMonitorNodes();
size_t parsePowerRails();
int parseIioEnergyNode(std::string devName);
Status parseIioEnergyNodes();
+ std::vector<PowerEntityInfo> mPowerEntityInfos;
+ std::unordered_map<uint32_t, PowerEntityStateSpace> mPowerEntityStateSpaces;
+ std::unordered_map<uint32_t, std::shared_ptr<IStateResidencyDataProvider>>
+ mStateResidencyDataProviders;
};
} // namespace implementation