Darren Hsu | 5f32222 | 2023-03-13 11:11:55 +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 | #include "AdaptiveDvfsStateResidencyDataProvider.h" |
| 17 | |
| 18 | #include <android-base/logging.h> |
| 19 | #include <android-base/parseint.h> |
| 20 | #include <android-base/strings.h> |
| 21 | |
| 22 | #include <string> |
| 23 | #include <utility> |
| 24 | |
| 25 | using android::base::Split; |
| 26 | using android::base::Trim; |
| 27 | |
| 28 | namespace aidl { |
| 29 | namespace android { |
| 30 | namespace hardware { |
| 31 | namespace power { |
| 32 | namespace stats { |
| 33 | |
| 34 | AdaptiveDvfsStateResidencyDataProvider::AdaptiveDvfsStateResidencyDataProvider( |
| 35 | std::string path, |
| 36 | uint64_t clockRate, |
| 37 | std::string powerEntityName, |
| 38 | std::string freqPath) |
| 39 | : DvfsStateResidencyDataProvider(path, clockRate, {}) { |
| 40 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(freqPath.c_str(), "r"), fclose); |
| 41 | if (!fp) { |
| 42 | PLOG(ERROR) << __func__ << ":Failed to open file " << freqPath; |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | size_t len = 0; |
| 47 | char *line = nullptr; |
| 48 | std::string suffix = "MHz"; |
| 49 | std::vector<std::pair<std::string, std::string>> states = {}; |
| 50 | std::vector<std::string> parts; |
| 51 | std::string freqStr; |
| 52 | |
| 53 | while (getline(&line, &len, fp.get()) != -1) { |
| 54 | parts = Split(line, " "); |
| 55 | if (parts.size() > 0) { |
| 56 | freqStr = Trim(parts[0]); |
| 57 | states.push_back(std::make_pair( |
| 58 | freqStr.substr(0, freqStr.length() - 3) + suffix, |
| 59 | freqStr)); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | mPowerEntities.push_back({powerEntityName, std::move(states)}); |
| 64 | } |
| 65 | |
| 66 | bool AdaptiveDvfsStateResidencyDataProvider::getStateResidencies( |
| 67 | std::unordered_map<std::string, std::vector<StateResidency>> *residencies) { |
| 68 | return DvfsStateResidencyDataProvider::getStateResidencies(residencies); |
| 69 | } |
| 70 | |
| 71 | std::unordered_map<std::string, std::vector<State>> |
| 72 | AdaptiveDvfsStateResidencyDataProvider::getInfo() { |
| 73 | return DvfsStateResidencyDataProvider::getInfo(); |
| 74 | } |
| 75 | |
| 76 | } // namespace stats |
| 77 | } // namespace power |
| 78 | } // namespace hardware |
| 79 | } // namespace android |
| 80 | } // namespace aidl |