1 /* 2 * Copyright (c) 2025 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 STORAGE_STATISTICS_FILE_H 17 #define STORAGE_STATISTICS_FILE_H 18 19 #include <string> 20 #include <map> 21 22 namespace OHOS { 23 namespace StorageDaemon { 24 struct RadarStatisticInfo { 25 uint64_t keyLoadSuccCount; 26 uint64_t keyLoadFailCount; 27 uint64_t keyUnloadSuccCount; 28 uint64_t keyUnloadFailCount; 29 uint64_t userAddSuccCount; 30 uint64_t userAddFailCount; 31 uint64_t userRemoveSuccCount; 32 uint64_t userRemoveFailCount; 33 uint64_t userStartSuccCount; 34 uint64_t userStartFailCount; 35 uint64_t userStopSuccCount; 36 uint64_t userStopFailCount; 37 }; 38 39 class StorageStatisticRadar { 40 public: GetInstance()41 static StorageStatisticRadar &GetInstance() 42 { 43 static StorageStatisticRadar instance; 44 return instance; 45 } 46 47 /** 48 * @brief 创建统计文件 49 * 50 */ 51 bool CreateStatisticFile(); 52 53 /** 54 * @brief 清理统计文件 55 * 56 */ 57 void CleanStatisticFile(); 58 59 /** 60 * @brief 刷新统计文件 61 * 62 *@param statistics 业务执行成功失败次数统计信息 63 */ 64 bool UpdateStatisticFile(const std::map<uint32_t, RadarStatisticInfo> &statistics); 65 66 /** 67 * @brief 读取统计文件 68 * 69 * @param statistics 业务执行成功失败次数统计信息 70 */ 71 bool ReadStatisticFile(std::map<uint32_t, RadarStatisticInfo> &statistics); 72 private: 73 std::string GetCountInfoString(const RadarStatisticInfo &info); 74 std::string CreateJsonString(const std::map<uint32_t, RadarStatisticInfo> &statistics); 75 bool ParseJsonInfo(uint32_t userId, const std::string &countInfo, std::map<uint32_t, 76 RadarStatisticInfo> &statistics); 77 private: 78 StorageStatisticRadar() = default; 79 ~StorageStatisticRadar() = default; 80 }; 81 } // namespace StorageDaemon 82 } // namespace OHOS 83 #endif // STORAGE_STATISTICS_FILE_H