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 OHOS_FILEMGMT_BACKUP_RADAR_TOTAL_STATISTIC_H 17 #define OHOS_FILEMGMT_BACKUP_RADAR_TOTAL_STATISTIC_H 18 19 #include <atomic> 20 #include <mutex> 21 #include "radar_const.h" 22 #include "b_error/b_error.h" 23 24 namespace OHOS::FileManagement::Backup { 25 26 class RadarTotalStatistic { 27 public: 28 std::atomic<uint32_t> succBundleCount_ = 0; 29 std::atomic<uint32_t> failBundleCount_ = 0; 30 Duration getBundleInfoSpend_ = {0, 0}; 31 Duration totalSpendTime_ = {0, 0}; 32 33 RadarTotalStatistic(BizScene bizScene, std::string caller, Mode mode = Mode::FULL); 34 RadarTotalStatistic(const RadarTotalStatistic &) = delete; 35 RadarTotalStatistic &operator=(const RadarTotalStatistic &) = delete; 36 RadarTotalStatistic(RadarTotalStatistic &&) = delete; 37 RadarTotalStatistic &operator=(RadarTotalStatistic &&) = delete; 38 ~RadarTotalStatistic() = default; 39 40 void Report(const std::string &func, int32_t error, std::string errMsg = ""); 41 void Report(const std::string &func, uint32_t moduleId, uint32_t moduleErr); 42 void Report(const std::string &func, BError errCode, uint32_t moduleId = MODULE_UNKNOWN); GetBizScene()43 BizScene GetBizScene() { return bizScene_; } GetUniqId()44 int64_t GetUniqId() { return uniqId_; } 45 46 private: 47 BizScene bizScene_ = BizScene::UNKNOWN; 48 std::string hostPkg_ = ""; 49 Mode mode_ = Mode::FULL; 50 int64_t uniqId_ = 0; 51 std::mutex lastCntMutex_; 52 uint32_t lastSuccCnt_ = 0; 53 uint32_t lastFailCnt_ = 0; 54 }; 55 } // namespace OHOS::FileManagement::Backup 56 #endif // OHOS_FILEMGMT_BACKUP_RADAR_TOTAL_STATISTIC_H 57