Darren Hsu | a3792b2 | 2023-01-07 13:43:26 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | #pragma once |
| 17 | |
| 18 | #include <PowerStatsAidl.h> |
| 19 | |
| 20 | namespace aidl { |
| 21 | namespace android { |
| 22 | namespace hardware { |
| 23 | namespace power { |
| 24 | namespace stats { |
| 25 | |
| 26 | class CpupmStateResidencyDataProvider : public PowerStats::IStateResidencyDataProvider { |
| 27 | public: |
| 28 | class Config { |
| 29 | public: |
| 30 | // List of power entity name pairs (name to display, name to parse) |
| 31 | std::vector<std::pair<std::string, std::string>> entities; |
| 32 | |
| 33 | // List of state pairs (state to display, state to parse). |
| 34 | std::vector<std::pair<std::string, std::string>> states; |
| 35 | }; |
| 36 | |
Darren Hsu | 02b8df5 | 2023-02-13 22:30:22 +0800 | [diff] [blame] | 37 | typedef std::vector<std::string> SleepConfig; |
| 38 | |
Darren Hsu | a3792b2 | 2023-01-07 13:43:26 +0800 | [diff] [blame] | 39 | /* |
| 40 | * path - path to cpupm sysfs node. |
| 41 | */ |
Darren Hsu | 02b8df5 | 2023-02-13 22:30:22 +0800 | [diff] [blame] | 42 | CpupmStateResidencyDataProvider( |
| 43 | const std::string &path, |
| 44 | const Config &config, |
| 45 | const std::string &sleepPath, |
| 46 | const SleepConfig &sleepConfig); |
Darren Hsu | a3792b2 | 2023-01-07 13:43:26 +0800 | [diff] [blame] | 47 | ~CpupmStateResidencyDataProvider() = default; |
| 48 | |
| 49 | /* |
| 50 | * See IStateResidencyDataProvider::getStateResidencies |
| 51 | */ |
| 52 | bool getStateResidencies( |
| 53 | std::unordered_map<std::string, std::vector<StateResidency>> *residencies) override; |
| 54 | |
| 55 | /* |
| 56 | * See IStateResidencyDataProvider::getInfo |
| 57 | */ |
| 58 | std::unordered_map<std::string, std::vector<State>> getInfo() override; |
| 59 | |
| 60 | private: |
| 61 | int32_t matchEntity(char const *line); |
| 62 | int32_t matchState(char const *line); |
| 63 | bool parseState(char const *line, uint64_t *duration, uint64_t *count); |
| 64 | |
| 65 | // A constant to represent the number of microseconds in one millisecond. |
| 66 | const uint64_t US_TO_MS = 1000; |
Darren Hsu | 02b8df5 | 2023-02-13 22:30:22 +0800 | [diff] [blame] | 67 | // A constant to represent the number of nanoseconds in one millisecond. |
| 68 | const uint64_t NS_TO_MS = 1000000; |
Darren Hsu | a3792b2 | 2023-01-07 13:43:26 +0800 | [diff] [blame] | 69 | |
| 70 | const std::string mPath; |
| 71 | const Config mConfig; |
Darren Hsu | 02b8df5 | 2023-02-13 22:30:22 +0800 | [diff] [blame] | 72 | const std::string mSleepPath; |
| 73 | const SleepConfig mSleepConfig; |
Darren Hsu | a3792b2 | 2023-01-07 13:43:26 +0800 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace stats |
| 77 | } // namespace power |
| 78 | } // namespace hardware |
| 79 | } // namespace android |
| 80 | } // namespace aidl |