diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 72010a892e74f6e647c1b62586948d54a9944a19..cb619e84d141c9c0b3155d0740fd98e0fc433fbc 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -746,7 +746,7 @@ void BackupExtExtension::DoPacket(const map &srcFiles, TarMap &t auto startTime = std::chrono::system_clock::now(); int fdNum = 0; auto reportCb = ReportErrFileByProc(wptr {this}, curScenario_); - uint32_t totalTarUs = 0; + uint64_t totalTarUs = 0; for (const auto &small : srcFiles) { totalSize += small.second; fileCount += 1; @@ -784,7 +784,7 @@ void BackupExtExtension::DoPacket(const map &srcFiles, TarMap &t packFiles.clear(); RefreshTimeInfo(startTime, fdNum); } - appStatistic_->tarSpend_ = totalTarUs / MS_TO_US; + appStatistic_->tarSpend_ = static_cast(totalTarUs / MS_TO_US); } int BackupExtExtension::DoBackup(TarMap &bigFileInfo, TarMap &fileBackupedInfo, map &smallFiles, @@ -2044,46 +2044,6 @@ void BackupExtExtension::FillFileInfos(UniqueFd incrementalFd, allFiles.size(), smallFiles.size(), bigFiles.size()); } -ErrCode BackupExtExtension::HandleIncrementalBackup(int incrementalFd, int manifestFd) -{ - HILOGI("Start HandleIncrementalBackup. incrementalFd:%{public}d, manifestFd:%{public}d", incrementalFd, manifestFd); - UniqueFd incrementalFdUnique(dup(incrementalFd)); - UniqueFd manifestFdUnique(dup(manifestFd)); - ErrCode ret = HandleIncrementalBackup(std::move(incrementalFdUnique), std::move(manifestFdUnique)); - close(incrementalFd); - close(manifestFd); - return ret; -} - -ErrCode BackupExtExtension::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - try { - HILOGI("Start HandleIncrementalBackup"); - if (!IfAllowToBackupRestore()) { - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE, "Application does not allow backup or restore") - .GetCode(); - } - AsyncTaskDoIncrementalBackup(move(incrementalFd), move(manifestFd)); - return ERR_OK; - } catch (...) { - HILOGE("Failed to handle incremental backup"); - return BError(BError::Codes::EXT_INVAL_ARG).GetCode(); - } -} - -ErrCode BackupExtExtension::IncrementalOnBackup(bool isClearData) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - SetClearDataFlag(isClearData); - if (!IfAllowToBackupRestore()) { - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE, "Application does not allow backup or restore") - .GetCode(); - } - AsyncTaskOnIncrementalBackup(); - return ERR_OK; -} - static void WriteFile(const string &filename, const vector &srcFiles) { fstream f; @@ -2177,8 +2137,7 @@ ErrCode BackupExtExtension::IncrementalBigFileReady(TarMap &pkgInfo, int manifestFdval = open(file.data(), O_RDONLY); ret = proxy->AppIncrementalFileReady(item.first, fdval, manifestFdval, errCode); if (SUCCEEDED(ret)) { - HILOGI("IncrementalBigFileReady: The application is packaged successfully, package name is %{public}s", - item.first.c_str()); + HILOGI("IncreBigFileReady: The app is packaged success, package name is %{public}s", item.first.c_str()); RemoveFile(file); } else { HILOGE("IncrementalBigFileReady interface fails to be invoked: %{public}d", ret); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index b771262fe9607f5be56045047506b76b50142a1e..e1e38e15300475b01f40623027711122db06b1b1 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -62,6 +62,46 @@ namespace OHOS::FileManagement::Backup { const uint32_t MAX_FD_GROUP_USE_TIME = 1000; // 每组打开最大时间1000ms +ErrCode BackupExtExtension::HandleIncrementalBackup(int incrementalFd, int manifestFd) +{ + HILOGI("Start HandleIncrementalBackup. incrementalFd:%{public}d, manifestFd:%{public}d", incrementalFd, manifestFd); + UniqueFd incrementalFdUnique(dup(incrementalFd)); + UniqueFd manifestFdUnique(dup(manifestFd)); + ErrCode ret = HandleIncrementalBackup(std::move(incrementalFdUnique), std::move(manifestFdUnique)); + close(incrementalFd); + close(manifestFd); + return ret; +} + +ErrCode BackupExtExtension::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGI("Start HandleIncrementalBackup"); + if (!IfAllowToBackupRestore()) { + return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE, "Application does not allow backup or restore") + .GetCode(); + } + AsyncTaskDoIncrementalBackup(move(incrementalFd), move(manifestFd)); + return ERR_OK; + } catch (...) { + HILOGE("Failed to handle incremental backup"); + return BError(BError::Codes::EXT_INVAL_ARG).GetCode(); + } +} + +ErrCode BackupExtExtension::IncrementalOnBackup(bool isClearData) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + SetClearDataFlag(isClearData); + if (!IfAllowToBackupRestore()) { + return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE, "Application does not allow backup or restore") + .GetCode(); + } + AsyncTaskOnIncrementalBackup(); + return ERR_OK; +} + void BackupExtExtension::WaitToSendFd(std::chrono::system_clock::time_point &startTime, int &fdSendNum) { HILOGD("WaitToSendFd Begin"); @@ -230,6 +270,7 @@ std::function BackupExtExtension::OnRestoreCallback( } else { std::string errInfo; BJsonUtil::BuildExtensionErrInfo(errInfo, errCode, errMsg); + extensionPtr->ReportAppStatistic("OnRestoreCallback", errCode); extensionPtr->AppResultReport(errInfo, BackupRestoreScenario::FULL_RESTORE, errCode); } extensionPtr->DoClear(); @@ -269,6 +310,7 @@ std::function BackupExtExtension::OnRestoreExCallbac if (errCode == ERR_OK) { if (restoreRetInfo.size()) { HILOGI("Will notify restore result report"); + extensionPtr->ReportAppStatistic("OnRestoreExCallback1", errCode); extensionPtr->AppResultReport(restoreRetInfo, BackupRestoreScenario::FULL_RESTORE); } return; @@ -279,6 +321,7 @@ std::function BackupExtExtension::OnRestoreExCallbac } else { std::string errInfo; BJsonUtil::BuildExtensionErrInfo(errInfo, errCode, restoreRetInfo); + extensionPtr->ReportAppStatistic("OnRestoreExCallback2", errCode); extensionPtr->AppResultReport(errInfo, BackupRestoreScenario::FULL_RESTORE, errCode); extensionPtr->DoClear(); } @@ -333,7 +376,7 @@ std::function BackupExtExtension::IncreOnRestoreExCa extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); if (errCode == ERR_OK) { if (restoreRetInfo.size()) { - extensionPtr->ReportAppStatistic("IncreOnRestoreExCallback", errCode); + extensionPtr->ReportAppStatistic("IncreOnRestoreExCallback1", errCode); extensionPtr->AppResultReport(restoreRetInfo, BackupRestoreScenario::INCREMENTAL_RESTORE); } return; @@ -344,7 +387,7 @@ std::function BackupExtExtension::IncreOnRestoreExCa } else { std::string errInfo; BJsonUtil::BuildExtensionErrInfo(errInfo, errCode, restoreRetInfo); - extensionPtr->ReportAppStatistic("IncreOnRestoreExCallback", errCode); + extensionPtr->ReportAppStatistic("IncreOnRestoreExCallback2", errCode); extensionPtr->AppResultReport(errInfo, BackupRestoreScenario::INCREMENTAL_RESTORE, errCode); extensionPtr->DoClear(); } @@ -743,7 +786,7 @@ void BackupExtExtension::StartOnProcessTimeOutTimer(wptr obj } if (extPtr->onProcessTimeoutCnt_.load() >= BConstants::APP_ON_PROCESS_TIMEOUT_MAX_COUNT || extPtr->isFirstCallOnProcess_.load()) { - HILOGE("The extension invokes the onProcess for more than three times or the first invoking of the" + HILOGE("The extension invokes the onProcess for more than three times or the first invoking of the " "onProcess times out, timeoutCnt:%{public}d", extPtr->onProcessTimeoutCnt_.load()); std::unique_lock lock(extPtr->onProcessLock_); extPtr->stopCallJsOnProcess_.store(true); diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 193698546fcc3ca8a116db80250d5a13f7c3ee8e..6f92ac6ae5190ce14d45b00ac6ab5d0499e35e2e 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -739,7 +739,6 @@ private: } } } - private: static sptr instance_; static std::mutex instanceLock_; @@ -775,7 +774,8 @@ private: std::atomic isScannedEnd_ {false}; std::atomic onScanning_ {false}; std::shared_ptr totalStatistic_ = nullptr; - std::shared_ptr saStatistic_ = nullptr; + std::shared_mutex statMapMutex_; + std::map> saStatisticMap_; public: std::map> backupExtMutexMap_; std::map failedBundles_; diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index dfe4d5d5328efb00f1a30cd5ed9cace33662667e..fd3842601e5091a03e7fdb8c5e6e87e9a976e52c 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -473,7 +473,7 @@ ErrCode Service::InitRestoreSession(const sptr &remote) ErrCode ret = VerifyCaller(); if (ret != ERR_OK) { HILOGE("Init restore session failed, verify caller failed"); - totalStatistic_->Report("InitRestoreSession", ret, MODULE_INIT); + totalStatistic_->Report("InitRestoreSession", MODULE_INIT, ret); return ret; } ret = session_->Active({ @@ -491,7 +491,7 @@ ErrCode Service::InitRestoreSession(const sptr &remote) ClearFileReadyRadarReport(); return ret; } - totalStatistic_->Report("InitRestoreSession", ret, MODULE_INIT); + totalStatistic_->Report("InitRestoreSession", MODULE_INIT, ret); if (ret == BError(BError::Codes::SA_SESSION_CONFLICT)) { HILOGE("Active restore session error, Already have a session"); return ret; @@ -508,7 +508,7 @@ ErrCode Service::InitBackupSession(const sptr &remote) ErrCode ret = VerifyCaller(); if (ret != ERR_OK) { HILOGE("Init full backup session fail, verify caller failed"); - totalStatistic_->Report("InitBackupSession", ret, MODULE_INIT); + totalStatistic_->Report("InitBackupSession", MODULE_INIT, ret); return ret; } int32_t oldSize = StorageMgrAdapter::UpdateMemPara(BConstants::BACKUP_VFS_CACHE_PRESSURE); @@ -529,7 +529,7 @@ ErrCode Service::InitBackupSession(const sptr &remote) ClearFileReadyRadarReport(); return ret; } - totalStatistic_->Report("InitBackupSession", ret, MODULE_INIT); + totalStatistic_->Report("InitBackupSession", MODULE_INIT, ret); if (ret == BError(BError::Codes::SA_SESSION_CONFLICT)) { HILOGE("Active backup session error, Already have a session"); return ret; @@ -625,7 +625,6 @@ vector Service::GetRestoreBundleNames(UniqueFd fd, }; restoreBundleInfos.emplace_back(info); } - HILOGI("restoreBundleInfos size is:%{public}zu", restoreInfos.size()); return restoreBundleInfos; } @@ -990,10 +989,12 @@ ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRe } SendEndAppGalleryNotify(callerName); if (sennario == BackupRestoreScenario::FULL_RESTORE) { + UpdateHandleCnt(errCode); HandleCurBundleEndWork(callerName, sennario); session_->GetServiceReverseProxy()->RestoreOnResultReport(restoreRetInfo, callerName, errCode); OnAllBundlesFinished(BError(BError::Codes::OK)); } else if (sennario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + UpdateHandleCnt(errCode); HandleCurBundleEndWork(callerName, sennario); session_->GetServiceReverseProxy()->IncrementalRestoreOnResultReport(restoreRetInfo, callerName, errCode); OnAllBundlesFinished(BError(BError::Codes::OK)); @@ -1818,9 +1819,11 @@ ErrCode Service::BackupSA(std::string bundleName) { HILOGI("BackupSA begin %{public}s", bundleName.c_str()); if (totalStatistic_ != nullptr) { - saStatistic_ = std::make_shared(bundleName, totalStatistic_->GetUniqId(), - totalStatistic_->GetBizScene()); - saStatistic_->doBackupSpend_.Start(); + std::unique_lock mapLock(statMapMutex_); + std::shared_ptr saStatistic = std::make_shared(bundleName, + totalStatistic_->GetUniqId(), totalStatistic_->GetBizScene()); + saStatistic->doBackupSpend_.Start(); + saStatisticMap_[bundleName] = saStatistic; } IServiceReverseType::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetSAExtConnection(bundleName); @@ -1918,6 +1921,7 @@ ErrCode Service::SADone(ErrCode errCode, std::string bundleName) void Service::NotifyCallerCurAppDone(ErrCode errCode, const std::string &callerName) { + UpdateHandleCnt(errCode); IServiceReverseType::Scenario scenario = session_->GetScenario(); if (scenario == IServiceReverseType::Scenario::BACKUP) { HILOGI("will notify clone data, scenario is Backup"); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 4c5db0ee539bbae2b2bb0507591003503c17e105..738f4182171b69aeb81ce08200b9c0fa4ea99627 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -307,7 +307,7 @@ ErrCode Service::InitIncrementalBackupSession(const sptr& remot ErrCode errCode = VerifyCaller(); if (errCode != ERR_OK) { HILOGE("Init incremental backup session fail, Verify caller failed, errCode:%{public}d", errCode); - totalStatistic_->Report("InitIncrementalBackupSession", errCode, MODULE_INIT); + totalStatistic_->Report("InitIncrementalBackupSession", MODULE_INIT, errCode); return errCode; } if (session_ == nullptr) { @@ -328,7 +328,7 @@ ErrCode Service::InitIncrementalBackupSession(const sptr& remot ClearFileReadyRadarReport(); return errCode; } - totalStatistic_->Report("InitIncrementalBackupSession", errCode, MODULE_INIT); + totalStatistic_->Report("InitIncrementalBackupSession", MODULE_INIT, errCode); if (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) { HILOGE("Active restore session error, Already have a session"); return errCode; @@ -355,7 +355,7 @@ ErrCode Service::InitIncrementalBackupSession(const sptr& remot ErrCode errCode = VerifyCaller(); if (errCode != ERR_OK) { HILOGE("Init incremental backup session fail, Verify caller failed, errCode:%{public}d", errCode); - totalStatistic_->Report("InitIncrementalBackupSessionWithErrMsg", errCode, MODULE_INIT); + totalStatistic_->Report("InitIncrementalBackupSessionWithErrMsg", MODULE_INIT, errCode); return errCode; } if (session_ == nullptr) { @@ -376,7 +376,7 @@ ErrCode Service::InitIncrementalBackupSession(const sptr& remot ClearFileReadyRadarReport(); return errCode; } - totalStatistic_->Report("InitIncrementalBackupSessionWithErrMsg", errCode, MODULE_INIT); + totalStatistic_->Report("InitIncrementalBackupSessionWithErrMsg", MODULE_INIT, errCode); if (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) { errMsg = BJsonUtil::BuildInitSessionErrInfo(session_->GetSessionUserId(), session_->GetSessionCallerName(), @@ -563,9 +563,11 @@ ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd { std::string bundleName = fileInfo.owner; if (totalStatistic_ != nullptr) { - saStatistic_ = std::make_shared(bundleName, totalStatistic_->GetUniqId(), - totalStatistic_->GetBizScene()); - saStatistic_->doRestoreStart_ = TimeUtils::GetTimeMS(); + std::unique_lock mapLock(statMapMutex_); + std::shared_ptr saStatistic = std::make_shared(bundleName, + totalStatistic_->GetUniqId(), totalStatistic_->GetBizScene()); + saStatistic->doRestoreStart_ = TimeUtils::GetTimeMS(); + saStatisticMap_[bundleName] = saStatistic; } ErrCode errCode = VerifyCaller(); if (errCode != ERR_OK) { @@ -855,9 +857,11 @@ ErrCode Service::IncrementalBackupSA(std::string bundleName) { HILOGI("IncrementalBackupSA begin %{public}s", bundleName.c_str()); if (totalStatistic_ != nullptr) { - saStatistic_ = std::make_shared(bundleName, totalStatistic_->GetUniqId(), - totalStatistic_->GetBizScene()); - saStatistic_->doBackupSpend_.Start(); + std::unique_lock mapLock(statMapMutex_); + std::shared_ptr saStatistic = std::make_shared(bundleName, + totalStatistic_->GetUniqId(), totalStatistic_->GetBizScene()); + saStatistic->doBackupSpend_.Start(); + saStatisticMap_[bundleName] = saStatistic; } IServiceReverseType::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetSAExtConnection(bundleName); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 33ad9905adf9dc5de97c2f847eed04556359d5dc..20ffa365a4ce0b0bfd8cc2d49f48529004931299 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -630,13 +630,20 @@ void Service::SaStatReport(const string &bundleName, const string &func, RadarEr err.errMsg_.c_str()); return; } - if (saStatistic_ == nullptr) { - saStatistic_ = std::make_shared(bundleName, totalStatistic_->GetUniqId(), - totalStatistic_->GetBizScene()); + + std::shared_ptr saStatistic = nullptr; + { + std::shared_lock mapLock(statMapMutex_); + if (saStatisticMap_.count(bundleName) > 0) { + saStatistic = saStatisticMap_[bundleName]; + saStatistic->doBackupSpend_.End(); + saStatistic->doRestoreSpend_ = TimeUtils::GetSpendMS(saStatistic->doRestoreStart_); + } else { + saStatistic = std::make_shared(bundleName, totalStatistic_->GetUniqId(), + totalStatistic_->GetBizScene()); + } } - saStatistic_->doBackupSpend_.End(); - saStatistic_->doRestoreSpend_ = TimeUtils::GetSpendMS(saStatistic_->doRestoreStart_); - saStatistic_->ReportSA(func, err); + saStatistic->ReportSA(func, err); } void Service::ExtConnectDied(const string &callName) @@ -911,7 +918,7 @@ ErrCode Service::InitRestoreSession(const sptr& remote, std::st ErrCode ret = VerifyCaller(); if (ret != ERR_OK) { HILOGE("Init restore session failed, verify caller failed"); - totalStatistic_->Report("InitRestoreSession", ret, MODULE_INIT); + totalStatistic_->Report("InitRestoreSession", MODULE_INIT, ret); return ret; } ret = session_->Active({ @@ -929,7 +936,7 @@ ErrCode Service::InitRestoreSession(const sptr& remote, std::st ClearFileReadyRadarReport(); return ret; } - totalStatistic_->Report("InitRestoreSession", ret, MODULE_INIT); + totalStatistic_->Report("InitRestoreSession", MODULE_INIT, ret); if (ret == BError(BError::Codes::SA_SESSION_CONFLICT)) { errMsg = BJsonUtil::BuildInitSessionErrInfo(session_->GetSessionUserId(), session_->GetSessionCallerName(), @@ -959,7 +966,7 @@ ErrCode Service::InitBackupSession(const sptr& remote, std::str ErrCode ret = VerifyCaller(); if (ret != ERR_OK) { HILOGE("Init full backup session fail, verify caller failed"); - totalStatistic_->Report("InitBackupSessionWithErrMsg", ret, MODULE_INIT); + totalStatistic_->Report("InitBackupSessionWithErrMsg", MODULE_INIT, ret); return ret; } int32_t oldSize = StorageMgrAdapter::UpdateMemPara(BConstants::BACKUP_VFS_CACHE_PRESSURE); @@ -980,7 +987,7 @@ ErrCode Service::InitBackupSession(const sptr& remote, std::str ClearFileReadyRadarReport(); return ret; } - totalStatistic_->Report("InitBackupSessionWithErrMsg", ret, MODULE_INIT); + totalStatistic_->Report("InitBackupSessionWithErrMsg", MODULE_INIT, ret); if (ret == BError(BError::Codes::SA_SESSION_CONFLICT)) { errMsg = BJsonUtil::BuildInitSessionErrInfo(session_->GetSessionUserId(), session_->GetSessionCallerName(), diff --git a/tests/unittests/backup_utils/b_radar/b_radar_test.cpp b/tests/unittests/backup_utils/b_radar/b_radar_test.cpp index 173a0d9b4481d3605afa4f0354609b72ce9a21ad..17947b793d91efe3914232bf21f19d19fe587c2f 100644 --- a/tests/unittests/backup_utils/b_radar/b_radar_test.cpp +++ b/tests/unittests/backup_utils/b_radar/b_radar_test.cpp @@ -79,6 +79,13 @@ HWTEST_F(BRadarTest, RadarErrorCode_0100, testing::ext::TestSize.Level1) RadarError err2(MODULE_ABILITY_MGR_SVC, BError(BError::Codes::OK)); EXPECT_EQ(err2.GenCode(), 0); EXPECT_EQ(err2.moduleId_, MODULE_ABILITY_MGR_SVC); + RadarError err3(MODULE_INIT, 139000041); + EXPECT_EQ(err3.error_, 13941); + RadarError err4(MODULE_INIT, 1390000043); + EXPECT_EQ(err4.error_, 13943); + EXPECT_EQ(0, err4.TransferErrCode(0)); + EXPECT_EQ(1, err4.TransferErrCode(-1)); + EXPECT_EQ(30099, err4.TransferErrCode(300000099)); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BRadarTest-an exception occurred."; diff --git a/utils/include/b_radar/radar_app_statistic.h b/utils/include/b_radar/radar_app_statistic.h index 8bd071ada1dcd5fd7e23569ad11c554171de856a..9a84969ffdbf59c6295a21ee77f16d526dba4b61 100644 --- a/utils/include/b_radar/radar_app_statistic.h +++ b/utils/include/b_radar/radar_app_statistic.h @@ -43,7 +43,7 @@ enum FileType : uint8_t { }; const std::unordered_map FileTypeDef = { - {"txt", TXT}, {"log", TXT}, {"json", TXT}, {"xml", TXT}, + {"txt", TXT}, {"log", TXT}, {"json", TXT}, {"xml", TXT}, {"db", TXT}, {"db-compare", TXT}, {"jpg", PIC}, {"jpeg", PIC}, {"png", PIC}, {"bmp", PIC}, {"gif", PIC}, {"svg", PIC}, {"webp", PIC}, {"tif", PIC}, {"raw", PIC}, {"wav", AUDIO}, {"flac", AUDIO}, {"wma", AUDIO}, {"acc", AUDIO}, {"mp3", AUDIO}, {"ogg", AUDIO}, {"opus", AUDIO}, @@ -124,9 +124,9 @@ public: Duration onBackupexSpend_ = {0, 0}; Duration scanFileSpend_ = {0, 0}; int64_t sendRateZeroStart_ = 0; - uint32_t sendRateZeroSpendUS_ = 0; + uint64_t sendRateZeroSpendUS_ = 0; uint32_t tarSpend_ = 0; - uint32_t hashSpendUS_ = 0; + uint64_t hashSpendUS_ = 0; Duration doBackupSpend_ = {0, 0}; Duration onRestoreSpend_ = {0, 0}; diff --git a/utils/include/b_radar/radar_const.h b/utils/include/b_radar/radar_const.h index 4d6767bafb16e09556f8c0bece30812d31f6d293..f4c730c443c80d14fe71f5f30ce16d1bc01284ce 100644 --- a/utils/include/b_radar/radar_const.h +++ b/utils/include/b_radar/radar_const.h @@ -87,7 +87,11 @@ struct RadarError { RadarError(BError errCode) { UpdateByBError(errCode); } RadarError(uint32_t moduleId, BError errCode) : moduleId_(moduleId) { UpdateByBError(errCode); } RadarError(uint32_t moduleId) : moduleId_(moduleId) {} - RadarError(uint32_t moduleId, uint16_t error) : moduleId_(moduleId), error_(error) {} + RadarError(uint32_t moduleId, uint32_t error) : moduleId_(moduleId) + { + error_ = TransferErrCode(error); + } + int32_t GenCode() { if (error_ == 0) { @@ -100,15 +104,22 @@ struct RadarError { { int32_t code = errCode.GetCode(); errMsg_ = errCode.ToString(); + error_ = TransferErrCode(code); + } + + int16_t TransferErrCode(int32_t code) + { if (code == 0) { - error_ = 0; - return; + return 0; + } + if (code < 0) { + code = -code; } int32_t errBase = code / DIVIDE_BASE; while (errBase > TRANSFER_BOUND) { errBase /= ADDITION_DIVIDE_BASE; } - error_ = static_cast(errBase + code % MOD_BASE); + return static_cast(errBase + code % MOD_BASE); } uint32_t moduleId_ = MODULE_UNKNOWN; diff --git a/utils/include/b_radar/radar_total_statistic.h b/utils/include/b_radar/radar_total_statistic.h index 372868c0c9e4beb411efe01a33128fcafca17d92..22d4824d7f8e241b1a3d361cfe6de6065cdfcdfb 100644 --- a/utils/include/b_radar/radar_total_statistic.h +++ b/utils/include/b_radar/radar_total_statistic.h @@ -17,6 +17,7 @@ #define OHOS_FILEMGMT_BACKUP_RADAR_TOTAL_STATISTIC_H #include +#include #include "radar_const.h" #include "b_error/b_error.h" @@ -37,7 +38,7 @@ public: ~RadarTotalStatistic() = default; void Report(const std::string &func, int32_t error, std::string errMsg = ""); - void Report(const std::string &func, uint32_t moduleId, uint16_t moduleErr); + void Report(const std::string &func, uint32_t moduleId, uint32_t moduleErr); void Report(const std::string &func, BError errCode, uint32_t moduleId = MODULE_UNKNOWN); BizScene GetBizScene() { return bizScene_; } int64_t GetUniqId() { return uniqId_; } @@ -47,8 +48,9 @@ private: std::string hostPkg_ = ""; Mode mode_ = Mode::FULL; int64_t uniqId_ = 0; - std::atomic lastSuccCnt_ = 0; - std::atomic lastFailCnt_ = 0; + std::mutex lastCntMutex_; + uint32_t lastSuccCnt_ = 0; + uint32_t lastFailCnt_ = 0; }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_RADAR_TOTAL_STATISTIC_H diff --git a/utils/include/b_utils/b_time.h b/utils/include/b_utils/b_time.h index e5726f79774038af59ddfde1efda84261e75680a..8a995bdf47c9772b84c0dc6ee35d0e1afe5acd8d 100644 --- a/utils/include/b_utils/b_time.h +++ b/utils/include/b_utils/b_time.h @@ -29,7 +29,7 @@ public: static int64_t GetTimeUS(); static uint32_t GetSpendSecond(int64_t startSecond); static uint32_t GetSpendMS(int64_t startMS); - static uint32_t GetSpendUS(int64_t startUS); + static uint64_t GetSpendUS(int64_t startUS); static std::string GetCurrentTime(); }; } // namespace OHOS::FileManagement::TimeUtils diff --git a/utils/src/b_radar/radar_app_statistic.cpp b/utils/src/b_radar/radar_app_statistic.cpp index 4d73a0ce8fe91b11479f33602ef517f019012ee6..9d37a82db460fa80e4b86d51a074ccaf1154e398 100644 --- a/utils/src/b_radar/radar_app_statistic.cpp +++ b/utils/src/b_radar/radar_app_statistic.cpp @@ -79,11 +79,11 @@ void RadarAppStatistic::ReportBackup(const std::string &func, int32_t errorCode, DOMAIN, BACKUP_RESTORE_APP_STATISTIC, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + APP_CALLER, appCaller_, ORG_PKG, DOMAIN_NAME, FUNC, func, CONCURRENT_ID, uniqId_, BIZ_SCENE, static_cast(BizScene::BACKUP), - APP_CALLER, appCaller_, FILE_SIZE_DIST, fileSizeDist_.ToJsonString(), FILE_TYPE_DIST, fileTypeDist_.ToJsonString(), SMALL_FILE_COUNT, smallFileCount_, @@ -99,9 +99,9 @@ void RadarAppStatistic::ReportBackup(const std::string &func, int32_t errorCode, ON_BACKUP_SPEND, onBackupSpend_.GetSpan(), ON_BACKUPEX_SPEND, onBackupexSpend_.GetSpan(), TAR_SPEND, tarSpend_, - HASH_SPEND, hashSpendUS_ / MS_TO_US, + HASH_SPEND, static_cast(hashSpendUS_ / MS_TO_US), SCAN_FILE_SPEND, scanFileSpend_.GetSpan(), - SEND_RATE_ZERO_SPAN, sendRateZeroSpendUS_ / MS_TO_US, + SEND_RATE_ZERO_SPAN, static_cast(sendRateZeroSpendUS_ / MS_TO_US), DO_BACKUP_SPEND, doBackupSpend_.GetSpan(), ERROR_MSG, errMsg, ERROR_CODE, errorCode, @@ -121,11 +121,11 @@ void RadarAppStatistic::ReportRestore(const std::string &func, int32_t errorCode DOMAIN, BACKUP_RESTORE_APP_STATISTIC, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + APP_CALLER, appCaller_, ORG_PKG, DOMAIN_NAME, FUNC, func, CONCURRENT_ID, uniqId_, BIZ_SCENE, static_cast(BizScene::RESTORE), - APP_CALLER, appCaller_, BIG_FILE_COUNT, bigFileCount_, BIG_FILE_SIZE, bigFileSize_, TAR_FILE_COUNT, tarFileCount_, @@ -167,11 +167,11 @@ void RadarAppStatistic::ReportError(const std::string &func, RadarError error) DOMAIN, BACKUP_RESTORE_APP_STATISTIC, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + APP_CALLER, appCaller_, ORG_PKG, DOMAIN_NAME, FUNC, func, CONCURRENT_ID, uniqId_, BIZ_SCENE, static_cast(bizScene_), - APP_CALLER, appCaller_, ERROR_MSG, error.errMsg_, ERROR_CODE, error.GenCode(), BIZ_STAGE, DEFAULT_STAGE, @@ -184,11 +184,11 @@ void RadarAppStatistic::ReportSA(const std::string &func, RadarError error) DOMAIN, BACKUP_RESTORE_APP_STATISTIC, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + APP_CALLER, appCaller_, ORG_PKG, DOMAIN_NAME, FUNC, func, CONCURRENT_ID, uniqId_, BIZ_SCENE, static_cast(bizScene_), - APP_CALLER, appCaller_, DO_BACKUP_SPEND, doBackupSpend_.GetSpan(), DO_RESTORE_SPEND, doRestoreSpend_, ERROR_MSG, error.errMsg_, diff --git a/utils/src/b_radar/radar_total_statistic.cpp b/utils/src/b_radar/radar_total_statistic.cpp index 1fbd74c91a95bb38c5712320359c9aabf370b375..ca143af9a9b4c856803d02048bfab0a032a3b837 100644 --- a/utils/src/b_radar/radar_total_statistic.cpp +++ b/utils/src/b_radar/radar_total_statistic.cpp @@ -28,31 +28,32 @@ RadarTotalStatistic::RadarTotalStatistic(BizScene bizScene, std::string callerNa void RadarTotalStatistic::Report(const std::string &func, int32_t error, std::string errMsg) { + std::lock_guard lastCntLock(lastCntMutex_); uint32_t succCount = succBundleCount_.load(); uint32_t failCount = failBundleCount_.load(); HiSysEventWrite( DOMAIN, BACKUP_RESTORE_STATISTIC, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + GET_BUNDLE_INFO_SPEND, getBundleInfoSpend_.GetSpan(), + TOTAL_SPEND, totalSpendTime_.GetSpan(), + SUCC_BUNDLE_CNT, succCount - lastSuccCnt_, + FAIL_BUNDLE_CNT, failCount - lastFailCnt_, ORG_PKG, DOMAIN_NAME, FUNC, func, CONCURRENT_ID, uniqId_, BIZ_SCENE, static_cast(bizScene_), HOST_PKG, hostPkg_, MODE, static_cast(mode_), - FAIL_BUNDLE_CNT, failCount - lastFailCnt_.load(), - SUCC_BUNDLE_CNT, succCount - lastSuccCnt_.load(), - GET_BUNDLE_INFO_SPEND, getBundleInfoSpend_.GetSpan(), - TOTAL_SPEND, totalSpendTime_.GetSpan(), ERROR_MSG, errMsg, ERROR_CODE, error, BIZ_STAGE, DEFAULT_STAGE, STAGE_RES, error == 0 ? STAGE_RES_SUCCESS : STAGE_RES_FAIL); - lastSuccCnt_.store(succCount); - lastFailCnt_.store(failCount); + lastSuccCnt_ = succCount; + lastFailCnt_ = failCount; } -void RadarTotalStatistic::Report(const std::string &func, uint32_t moduleId, uint16_t moduleErr) +void RadarTotalStatistic::Report(const std::string &func, uint32_t moduleId, uint32_t moduleErr) { RadarError err(moduleId, moduleErr); Report(func, err.GenCode()); diff --git a/utils/src/b_utils/b_time.cpp b/utils/src/b_utils/b_time.cpp index fcdbbb1bb9a9699b4a7bc3b3f90bf922d918f80c..adaa98796c0fbfbc230de989c648aea3291191da 100644 --- a/utils/src/b_utils/b_time.cpp +++ b/utils/src/b_utils/b_time.cpp @@ -66,7 +66,7 @@ uint32_t TimeUtils::GetSpendMS(int64_t startTime) return static_cast(endTime - startTime); } -uint32_t TimeUtils::GetSpendUS(int64_t startTime) +uint64_t TimeUtils::GetSpendUS(int64_t startTime) { if (startTime == 0) { return 0; @@ -75,7 +75,7 @@ uint32_t TimeUtils::GetSpendUS(int64_t startTime) if (endTime < startTime) { return 0; } - return static_cast(endTime - startTime); + return endTime - startTime; } std::string TimeUtils::GetCurrentTime()