blob: be8ee46f91b10a734e3f57d647e71216b0246519 [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
Darren Hsu02b8df52023-02-13 22:30:22 +080037 typedef std::vector<std::string> SleepConfig;
38
Darren Hsua3792b22023-01-07 13:43:26 +080039 /*
40 * path - path to cpupm sysfs node.
41 */
Darren Hsu02b8df52023-02-13 22:30:22 +080042 CpupmStateResidencyDataProvider(
43 const std::string &path,
44 const Config &config,
45 const std::string &sleepPath,
46 const SleepConfig &sleepConfig);
Darren Hsua3792b22023-01-07 13:43:26 +080047 ~CpupmStateResidencyDataProvider() = default;
48
49 /*
50 * See IStateResidencyDataProvider::getStateResidencies
51 */
52 bool getStateResidencies(
53 std::unordered_map<std::string, std::vector<StateResidency>> *residencies) override;
54
55 /*
56 * See IStateResidencyDataProvider::getInfo
57 */
58 std::unordered_map<std::string, std::vector<State>> getInfo() override;
59
60 private:
61 int32_t matchEntity(char const *line);
62 int32_t matchState(char const *line);
63 bool parseState(char const *line, uint64_t *duration, uint64_t *count);
64
65 // A constant to represent the number of microseconds in one millisecond.
66 const uint64_t US_TO_MS = 1000;
Darren Hsu02b8df52023-02-13 22:30:22 +080067 // A constant to represent the number of nanoseconds in one millisecond.
68 const uint64_t NS_TO_MS = 1000000;
Darren Hsua3792b22023-01-07 13:43:26 +080069
70 const std::string mPath;
71 const Config mConfig;
Darren Hsu02b8df52023-02-13 22:30:22 +080072 const std::string mSleepPath;
73 const SleepConfig mSleepConfig;
Darren Hsua3792b22023-01-07 13:43:26 +080074};
75
76} // namespace stats
77} // namespace power
78} // namespace hardware
79} // namespace android
80} // namespace aidl