1 /*
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 
17 #pragma once
18 
19 #include <map>
20 #include <unordered_map>
21 #include <vector>
22 #include <string>
23 
24 enum AttributionType {
25     /* Parsing uid_time_in_state like following format.
26      * (see /proc/uid_time_in_state)
27      * uid: state_name_0, state_name_1, ..
28      * uid_0: time_in_state_0, time_in_state_1, ..
29      * uid_1: time_in_state_0, time_in_state_1, ..
30      */
31     UID_TIME_IN_STATE,
32 };
33 
34 // Declaring different return values for each type of attributions
35 struct AttributionStats {
36     /* Members for UID_TIME_IN_STATE
37      * uidTimeInStats: key = uid, val = {uid_time_in_state}
38      * uidTimeInStateNames: state_name_0, state_name_1, ..
39      */
40     std::unordered_map<int32_t, std::vector<long>> uidTimeInStats;
41     std::vector<std::string> uidTimeInStateNames;
42 };
43 
44 namespace aidl {
45 namespace android {
46 namespace hardware {
47 namespace power {
48 namespace stats {
49 
50 class PowerStatsEnergyAttribution {
51   public:
52     PowerStatsEnergyAttribution() = default;
53     ~PowerStatsEnergyAttribution() = default;
54     AttributionStats getAttributionStats(std::unordered_map<int32_t, std::string> paths);
55 private:
56     bool readUidTimeInState(AttributionStats *attrStats, std::string path);
57 };
58 
59 }  // namespace stats
60 }  // namespace power
61 }  // namespace hardware
62 }  // namespace android
63 }  // namespace aidl
64