blob: 28b076cea4af3aa6068c79daf6c1b571981b36df [file] [log] [blame]
Darren Hsu5f322222023-03-13 11:11:55 +08001/*
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
25using android::base::Split;
26using android::base::Trim;
27
28namespace aidl {
29namespace android {
30namespace hardware {
31namespace power {
32namespace stats {
33
34AdaptiveDvfsStateResidencyDataProvider::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
66bool AdaptiveDvfsStateResidencyDataProvider::getStateResidencies(
67 std::unordered_map<std::string, std::vector<StateResidency>> *residencies) {
68 return DvfsStateResidencyDataProvider::getStateResidencies(residencies);
69}
70
71std::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