• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BATTERY_STATS_PARSER_H
17 #define BATTERY_STATS_PARSER_H
18 
19 #include <cstdint>
20 #include <functional>
21 #include <iosfwd>
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 #include <cJSON.h>
27 #include "stats_log.h"
28 
29 namespace OHOS {
30 namespace PowerMgr {
31 class BatteryStatsParser {
32 public:
BatteryStatsParser()33     explicit BatteryStatsParser()
34     {
35         STATS_HILOGI(COMP_SVC, "BatteryStatsParser instance is created");
36     }
37     ~BatteryStatsParser() = default;
38     double GetAveragePowerMa(std::string type);
39     double GetAveragePowerMa(std::string type, uint16_t level);
40     uint16_t GetClusterNum();
41     uint16_t GetSpeedNum(uint16_t cluster);
42     bool Init();
43     void DumpInfo(std::string& result);
44 private:
45     bool LoadAveragePowerFromFile(const std::string& path);
46     void ParsingArray(const std::string& type, const cJSON* array);
47     std::map<std::string, double> averageMap_;
48     std::map<std::string, std::vector<double>> averageVecMap_;
49     uint16_t clusterNum_ = 0;
50     std::vector<uint16_t> speedNum_;
51 };
52 } // namespace PowerMgr
53 } // namespace OHOS
54 #endif // BATTERY_STATS_PARSER_H