• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef POWERSTATS_INCLUDE_PIXELPOWERSTATS_POWERSTATS_H_
18 #define POWERSTATS_INCLUDE_PIXELPOWERSTATS_POWERSTATS_H_
19 
20 #include <android/hardware/power/stats/1.0/IPowerStats.h>
21 #include <utils/RefBase.h>
22 #include <functional>
23 #include <memory>
24 #include <string>
25 #include <unordered_map>
26 #include <vector>
27 
28 namespace android {
29 namespace hardware {
30 
31 namespace google {
32 namespace pixel {
33 namespace powerstats {
34 
35 using android::hardware::hidl_vec;
36 using android::hardware::Return;
37 using android::hardware::Void;
38 using android::hardware::power::stats::V1_0::EnergyData;
39 using android::hardware::power::stats::V1_0::IPowerStats;
40 using android::hardware::power::stats::V1_0::PowerEntityInfo;
41 using android::hardware::power::stats::V1_0::PowerEntityStateInfo;
42 using android::hardware::power::stats::V1_0::PowerEntityStateResidencyData;
43 using android::hardware::power::stats::V1_0::PowerEntityStateResidencyResult;
44 using android::hardware::power::stats::V1_0::PowerEntityStateSpace;
45 using android::hardware::power::stats::V1_0::PowerEntityType;
46 using android::hardware::power::stats::V1_0::RailInfo;
47 using android::hardware::power::stats::V1_0::Status;
48 
49 class IRailDataProvider {
50 public:
51     virtual ~IRailDataProvider() = default;
52     virtual Return<void> getRailInfo(IPowerStats::getRailInfo_cb _hidl_cb) = 0;
53     virtual Return<void> getEnergyData(const hidl_vec<uint32_t> &railIndices,
54                                        IPowerStats::getEnergyData_cb _hidl_cb) = 0;
55     virtual Return<void> streamEnergyData(uint32_t timeMs, uint32_t samplingRate,
56                                           IPowerStats::streamEnergyData_cb _hidl_cb) = 0;
57 };
58 
59 class IStateResidencyDataProvider : public virtual RefBase {
60 public:
61     virtual ~IStateResidencyDataProvider() = default;
62     virtual bool getResults(
63         std::unordered_map<uint32_t, PowerEntityStateResidencyResult> &results) = 0;
64     virtual std::vector<PowerEntityStateSpace> getStateSpaces() = 0;
65 };
66 
67 }  // namespace powerstats
68 }  // namespace pixel
69 }  // namespace google
70 
71 namespace power {
72 namespace stats {
73 namespace V1_0 {
74 namespace implementation {
75 
76 using android::hardware::google::pixel::powerstats::IRailDataProvider;
77 using android::hardware::google::pixel::powerstats::IStateResidencyDataProvider;
78 
79 class PowerStats : public IPowerStats {
80 public:
81     PowerStats() = default;
82     void setRailDataProvider(std::unique_ptr<IRailDataProvider> dataProvider);
83     uint32_t addPowerEntity(const std::string &name, PowerEntityType type);
84     // Using shared_ptr here because multiple power entities could depend on the
85     // same IStateResidencyDataProvider.
86     void addStateResidencyDataProvider(sp<IStateResidencyDataProvider> p);
87 
88     // Methods from ::android::hardware::power::stats::V1_0::IPowerStats follow.
89     Return<void> getRailInfo(getRailInfo_cb _hidl_cb) override;
90     Return<void> getEnergyData(const hidl_vec<uint32_t> &railIndices,
91                                getEnergyData_cb _hidl_cb) override;
92     Return<void> streamEnergyData(uint32_t timeMs, uint32_t samplingRate,
93                                   streamEnergyData_cb _hidl_cb) override;
94     Return<void> getPowerEntityInfo(getPowerEntityInfo_cb _hidl_cb) override;
95     Return<void> getPowerEntityStateInfo(const hidl_vec<uint32_t> &powerEntityIds,
96                                          getPowerEntityStateInfo_cb _hidl_cb) override;
97     Return<void> getPowerEntityStateResidencyData(
98         const hidl_vec<uint32_t> &powerEntityIds,
99         getPowerEntityStateResidencyData_cb _hidl_cb) override;
100 
101     // Methods from ::android::hidl::base::V1_0::IBase follow.
102     Return<void> debug(const hidl_handle &fd, const hidl_vec<hidl_string> &args) override;
103 
104 private:
105     std::unique_ptr<IRailDataProvider> mRailDataProvider;
106     std::vector<PowerEntityInfo> mPowerEntityInfos;
107     std::unordered_map<uint32_t, PowerEntityStateSpace> mPowerEntityStateSpaces;
108     std::unordered_map<uint32_t, sp<IStateResidencyDataProvider>> mStateResidencyDataProviders;
109 
110     void debugStateResidency(const std::unordered_map<uint32_t, std::string> &entityNames, int fd,
111                              bool delta);
112     void debugEnergyData(int fd, bool delta);
113 };
114 
115 }  // namespace implementation
116 }  // namespace V1_0
117 }  // namespace stats
118 }  // namespace power
119 }  // namespace hardware
120 }  // namespace android
121 
122 #endif  // POWERSTATS_INCLUDE_PIXELPOWERSTATS_POWERSTATS_H_
123