blob: 0aeafb7cb6bac14f30bdabf364b80f93b0f69a24 [file] [log] [blame]
Darren Hsu673d3b02021-12-28 21:31:24 +08001/*
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#pragma once
17
18#include <PowerStatsAidl.h>
19
20namespace aidl {
21namespace android {
22namespace hardware {
23namespace power {
24namespace stats {
25
26class DvfsStateResidencyDataProvider : public PowerStats::IStateResidencyDataProvider {
27 public:
28 class Config {
29 public:
30 // Power entity name to parse.
31 std::string powerEntityName;
32
33 // List of state pairs (name to display, name to parse).
34 std::vector<std::pair<std::string, std::string>> states;
35 };
36 /*
37 * path - path to dvfs sysfs node.
38 * clockRate - clock rate in KHz.
39 */
40 DvfsStateResidencyDataProvider(std::string path, uint64_t clockRate, std::vector<Config> cfgs);
41 ~DvfsStateResidencyDataProvider() = default;
42
43 /*
44 * See IStateResidencyDataProvider::getStateResidencies
45 */
46 bool getStateResidencies(
47 std::unordered_map<std::string, std::vector<StateResidency>> *residencies) override;
48
49 /*
50 * See IStateResidencyDataProvider::getInfo
51 */
52 std::unordered_map<std::string, std::vector<State>> getInfo() override;
53
Darren Hsu5f322222023-03-13 11:11:55 +080054 protected:
55 std::vector<Config> mPowerEntities;
56
Darren Hsu673d3b02021-12-28 21:31:24 +080057 private:
58 int32_t matchEntity(char const *line);
59 int32_t matchState(char const *line, const Config& powerEntity);
60 bool parseState(char const *line, uint64_t *duration, uint64_t *count);
61
62 const std::string mPath;
63 const uint64_t mClockRate;
Darren Hsu673d3b02021-12-28 21:31:24 +080064};
65
66} // namespace stats
67} // namespace power
68} // namespace hardware
69} // namespace android
70} // namespace aidl