blob: ca8ab22bbd7e904743198482f5fd7a9e3c582929 [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 */
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080016#pragma once
Robin Pengc2b5ca92021-02-23 20:00:28 +080017
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080018#include <PowerStatsAidl.h>
Robin Pengc2b5ca92021-02-23 20:00:28 +080019
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080020namespace aidl {
Robin Pengc2b5ca92021-02-23 20:00:28 +080021namespace android {
22namespace hardware {
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080023namespace power {
24namespace stats {
Robin Pengc2b5ca92021-02-23 20:00:28 +080025
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080026class DvfsStateResidencyDataProvider : public PowerStats::IStateResidencyDataProvider {
Robin Pengc2b5ca92021-02-23 20:00:28 +080027 public:
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080028 class Config {
29 public:
Robin Pengc2b5ca92021-02-23 20:00:28 +080030 // 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 };
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080036 /*
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
54 private:
55 int32_t matchEntity(char const *line);
56 int32_t matchState(char const *line, const Config& powerEntity);
57 bool parseState(char const *line, uint64_t *duration, uint64_t *count);
58
59 const std::string mPath;
60 const uint64_t mClockRate;
61 std::vector<Config> mPowerEntities;
Robin Pengc2b5ca92021-02-23 20:00:28 +080062};
63
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080064} // namespace stats
65} // namespace power
Robin Pengc2b5ca92021-02-23 20:00:28 +080066} // namespace hardware
67} // namespace android
Benjamin Schwartz0d6392e2021-03-09 09:02:06 -080068} // namespace aidl