Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | #ifndef HARDWARE_GOOGLE_PIXEL_POWERSTATS_DVFSSTATERESIDENCYDATAPROVIDER_H |
| 17 | #define HARDWARE_GOOGLE_PIXEL_POWERSTATS_DVFSSTATERESIDENCYDATAPROVIDER_H |
| 18 | |
| 19 | #include <pixelpowerstats/PowerStats.h> |
| 20 | |
| 21 | namespace android { |
| 22 | namespace hardware { |
| 23 | namespace google { |
| 24 | namespace pixel { |
| 25 | namespace powerstats { |
| 26 | |
| 27 | class DvfsStateResidencyDataProvider : public IStateResidencyDataProvider { |
| 28 | public: |
| 29 | /* |
| 30 | * path - path to dvfs sysfs node. |
| 31 | * clockRate - clock rate in KHz. |
| 32 | */ |
| 33 | DvfsStateResidencyDataProvider(std::string path, uint64_t clockRate); |
| 34 | ~DvfsStateResidencyDataProvider() = default; |
| 35 | |
| 36 | /* |
| 37 | * id - the power entity id |
| 38 | * name - the power entity name to parse from sysfs node |
| 39 | * frequencies - list of pairs (frequency display name, frequency in sysfs |
| 40 | * node). |
| 41 | */ |
| 42 | void addEntity(uint32_t id, std::string name, |
| 43 | std::vector<std::pair<std::string, std::string>> frequencies); |
| 44 | |
| 45 | /* |
| 46 | * See IStateResidencyDataProvider::getResults. |
| 47 | */ |
| 48 | bool getResults( |
| 49 | std::unordered_map<uint32_t, PowerEntityStateResidencyResult> &results) override; |
| 50 | |
| 51 | /* |
| 52 | * See IStateResidencyDataProvider::getStateSpaces. |
| 53 | */ |
| 54 | std::vector<PowerEntityStateSpace> getStateSpaces() override; |
| 55 | |
| 56 | private: |
| 57 | int32_t matchEntity(char *line); |
| 58 | int32_t matchState(char *line, int32_t entityId); |
| 59 | bool parseState(char *line, uint64_t &duration, uint64_t &count); |
| 60 | |
| 61 | const std::string mPath; |
| 62 | const uint64_t mClockRate; |
| 63 | |
| 64 | struct config { |
| 65 | // Power entity id. |
| 66 | uint32_t powerEntityId; |
| 67 | |
| 68 | // Power entity name to parse. |
| 69 | std::string powerEntityName; |
| 70 | |
| 71 | // List of state pairs (name to display, name to parse). |
| 72 | std::vector<std::pair<std::string, std::string>> states; |
| 73 | }; |
| 74 | std::vector<config> mPowerEntities; |
| 75 | }; |
| 76 | |
| 77 | } // namespace powerstats |
| 78 | } // namespace pixel |
| 79 | } // namespace google |
| 80 | } // namespace hardware |
| 81 | } // namespace android |
| 82 | |
| 83 | #endif // HARDWARE_GOOGLE_PIXEL_POWERSTATS_DVFSSTATERESIDENCYDATAPROVIDER_H |