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 "json/value.h" 27 28 #include "stats_log.h" 29 30 namespace OHOS { 31 namespace PowerMgr { 32 class BatteryStatsParser { 33 public: BatteryStatsParser()34 explicit BatteryStatsParser() 35 { 36 STATS_HILOGI(COMP_SVC, "BatteryStatsParser instance is created"); 37 } 38 ~BatteryStatsParser() = default; 39 double GetAveragePowerMa(std::string type); 40 double GetAveragePowerMa(std::string type, uint16_t level); 41 uint16_t GetClusterNum(); 42 uint16_t GetSpeedNum(uint16_t cluster); 43 bool Init(); 44 void DumpInfo(std::string& result); 45 private: 46 bool LoadAveragePowerFromFile(const std::string& path); 47 void ParsingArray(const std::string& type, const Json::Value& array); 48 std::map<std::string, double> averageMap_; 49 std::map<std::string, std::vector<double>> averageVecMap_; 50 uint16_t clusterNum_ = 0; 51 std::vector<uint16_t> speedNum_; 52 }; 53 } // namespace PowerMgr 54 } // namespace OHOS 55 #endif // BATTERY_STATS_PARSER_H