blob: ffa1414683adb0e41ecf28cb9d328a750f2b75db [file] [log] [blame]
Robin Pengc2b5ca92021-02-23 20:00:28 +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#ifndef HARDWARE_GOOGLE_PIXEL_POWERSTATS_DVFSSTATERESIDENCYDATAPROVIDER_H
17#define HARDWARE_GOOGLE_PIXEL_POWERSTATS_DVFSSTATERESIDENCYDATAPROVIDER_H
18
19#include <pixelpowerstats/PowerStats.h>
20
21namespace android {
22namespace hardware {
23namespace google {
24namespace pixel {
25namespace powerstats {
26
27class 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