blob: c04e11ea25befc577341fdff2372a19ba2910fde [file] [log] [blame]
Darren Hsua3792b22023-01-07 13:43:26 +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#pragma once
17
18#include <PowerStatsAidl.h>
19
20namespace aidl {
21namespace android {
22namespace hardware {
23namespace power {
24namespace stats {
25
26class 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
37 /*
38 * path - path to cpupm sysfs node.
39 */
40 CpupmStateResidencyDataProvider(const std::string &path, const Config &config);
41 ~CpupmStateResidencyDataProvider() = 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
54 private:
55 int32_t matchEntity(char const *line);
56 int32_t matchState(char const *line);
57 bool parseState(char const *line, uint64_t *duration, uint64_t *count);
58
59 // A constant to represent the number of microseconds in one millisecond.
60 const uint64_t US_TO_MS = 1000;
61
62 const std::string mPath;
63 const Config mConfig;
64};
65
66} // namespace stats
67} // namespace power
68} // namespace hardware
69} // namespace android
70} // namespace aidl