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 #include "b_radar/radar_total_statistic.h"
17 #include "b_radar/radar_const_inner.h"
18 #include "b_utils/b_time.h"
19 #include "filemgmt_libhilog.h"
20 #include "hisysevent.h"
21
22 namespace OHOS::FileManagement::Backup {
23
RadarTotalStatistic(BizScene bizScene,std::string callerName,Mode mode)24 RadarTotalStatistic::RadarTotalStatistic(BizScene bizScene, std::string callerName, Mode mode)
25 : bizScene_(bizScene), hostPkg_(callerName), mode_(mode)
26 {
27 uniqId_ = TimeUtils::GetTimeUS();
28 }
29
Report(const std::string & func,int32_t error,std::string errMsg)30 void RadarTotalStatistic::Report(const std::string &func, int32_t error, std::string errMsg)
31 {
32 std::lock_guard<std::mutex> lastCntLock(lastCntMutex_);
33 uint32_t succCount = succBundleCount_.load();
34 uint32_t failCount = failBundleCount_.load();
35 HiSysEventWrite(
36 DOMAIN,
37 BACKUP_RESTORE_STATISTIC,
38 OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
39 GET_BUNDLE_INFO_SPEND, getBundleInfoSpend_.GetSpan(),
40 TOTAL_SPEND, totalSpendTime_.GetSpan(),
41 SUCC_BUNDLE_CNT, succCount - lastSuccCnt_,
42 FAIL_BUNDLE_CNT, failCount - lastFailCnt_,
43 ORG_PKG, DOMAIN_NAME,
44 FUNC, func,
45 CONCURRENT_ID, uniqId_,
46 BIZ_SCENE, static_cast<int32_t>(bizScene_),
47 HOST_PKG, hostPkg_,
48 MODE, static_cast<uint32_t>(mode_),
49 ERROR_MSG, errMsg,
50 ERROR_CODE, error,
51 BIZ_STAGE, DEFAULT_STAGE,
52 STAGE_RES, error == 0 ? STAGE_RES_SUCCESS : STAGE_RES_FAIL);
53 lastSuccCnt_ = succCount;
54 lastFailCnt_ = failCount;
55 }
56
Report(const std::string & func,uint32_t moduleId,uint32_t moduleErr)57 void RadarTotalStatistic::Report(const std::string &func, uint32_t moduleId, uint32_t moduleErr)
58 {
59 RadarError err(moduleId, moduleErr);
60 Report(func, err.GenCode());
61 }
62
Report(const std::string & func,BError errCode,uint32_t moduleId)63 void RadarTotalStatistic::Report(const std::string &func, BError errCode, uint32_t moduleId)
64 {
65 RadarError err(moduleId, errCode);
66 Report(func, err.GenCode(), err.errMsg_);
67 }
68 } // namespace OHOS::FileManagement::Backup