diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index d9789d3f44560ea241c19d5c0cdfc7b15c1c6aae..f29b4f8b184fad813688be5ae02c861fde1e0131 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1150,6 +1150,17 @@ void BackupExtExtension::HandleSpecialVersionRestore() } } +void RecordDoRestoreRes(const std::string &bundleName, const std::string &func, int32_t ms, int32_t fileNum, + int32_t fileSize) +{ + std::stringstream ss; + ss << "\"file_count\": \"" << fileNum << "\", \"file_size\": \"" << fileSize + << "\", \"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordRestoreFuncResWithStatus(bundleName, AppRadar::GetInstance().GetUserId(), + func, BizStageRestore::BIZ_STAGE_DO_RESTORE, + ss.str(), BError::Codes::OK); +} + void BackupExtExtension::AsyncTaskRestore(std::set fileSet, const std::vector extManageInfo) { @@ -1159,11 +1170,13 @@ void BackupExtExtension::AsyncTaskRestore(std::set fileSet, BExcepUltils::BAssert(ptr->extension_, BError::Codes::EXT_INVAL_ARG, "Extension handle have been released"); try { int ret = ERR_OK; + auto startTime = std::chrono::system_clock::now(); if (ptr->extension_->SpecialVersionForCloneAndCloud()) { ptr->HandleSpecialVersionRestore(); return; } // 解压 + int32_t fileSize; for (auto item : fileSet) { // 处理要解压的tar文件 off_t tarFileSize = 0; if (ExtractFileExt(item) == "tar" && !IsUserTar(item, extManageInfo, tarFileSize)) { @@ -1176,6 +1189,12 @@ void BackupExtExtension::AsyncTaskRestore(std::set fileSet, ptr->extension_->UseFullBackupOnly() && !ptr->extension_->SpecialVersionForCloneAndCloud(); ptr->RestoreBigFiles(appendTargetPath); ptr->DeleteBackupTars(); + + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime-startTime).count(); + RecordDoRestoreRes("bundlename", "AsyncTaskRestore", static_cast(ms), + static_cast(fileSet.size()), static_cast(fileSize)); + if (ret == ERR_OK) { ptr->AsyncTaskRestoreForUpgrade(); } else { @@ -1215,6 +1234,9 @@ void BackupExtExtension::AsyncTaskIncrementalRestore() ptr->CheckTmpDirFileInfos(); } // 解压 + auto startTime = std::chrono::system_clock::now(); + int32_t fileSize; + int32_t fileNum; int ret = ptr->DoIncrementalRestore(); // 恢复用户tar包以及大文件 // 目的地址是否需要拼接path(临时目录),FullBackupOnly为true并且非特殊场景 @@ -1224,6 +1246,12 @@ void BackupExtExtension::AsyncTaskIncrementalRestore() // delete 1.tar/manage.json ptr->DeleteBackupIncrementalTars(); + + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime-startTime).count(); + RecordDoRestoreRes("bundlename", "AsyncTaskIncrementalRestore", static_cast(ms), + static_cast(fileNum), static_cast(fileSize)); + if (ptr != nullptr && ptr->isDebug_) { ptr->CheckRestoreFileInfos(); } @@ -1317,6 +1345,7 @@ void BackupExtExtension::AsyncTaskRestoreForUpgrade() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::FULL_RESTORE); auto callBackup = ptr->OnRestoreCallback(obj); auto callBackupEx = ptr->OnRestoreExCallback(obj); + g_startTimePoint = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx); if (err != ERR_OK) { ptr->AppDone(BError::GetCodeByErrno(err)); @@ -1367,6 +1396,7 @@ void BackupExtExtension::AsyncTaskIncrementalRestoreForUpgrade() ptr->StartOnProcessTaskThread(obj, BackupRestoreScenario::INCREMENTAL_RESTORE); auto callBackup = ptr->IncreOnRestoreCallback(obj); auto callBackupEx = ptr->IncreOnRestoreExCallback(obj); + g_startTimePoint = std::chrono::system_clock::now(); ErrCode err = ptr->extension_->OnRestore(callBackup, callBackupEx); if (err != ERR_OK) { HILOGE("OnRestore done, err = %{pubilc}d", err); diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index ae77b3e75a4f85071c412f921d32d4eadc5f4c1e..9136268ec40460ccc825c2d6f14fc8e62323ba41 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -47,6 +47,7 @@ #include "b_json/b_json_cached_entity.h" #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" +#include "b_radar/b_radar.h" #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" @@ -248,6 +249,15 @@ std::function BackupExtExtension::OnRestoreCallback( return; } HILOGI("Current bundle will execute app done"); + if (g_startTimePoint != nullptr && errCode == ERR_OK) { + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime - g_startTimePoint).count(); + std::stringstream ss; + ss << "\"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), + "BackupExtExtension::OnRestoreCallback", ss.str(), ERR_OK); + g_startTimePoint = nullptr; + } extensionPtr->FinishOnProcessTask(); if (errMsg.empty()) { extensionPtr->AppDone(errCode); @@ -273,6 +283,15 @@ std::function BackupExtExtension::OnRestoreExCallbac HILOGE("Extension handle have been released"); return; } + if (g_startTimePoint != nullptr && errCode == ERR_OK && !restoreRetInfo.empty()) { + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime - g_startTimePoint).count(); + std::stringstream ss; + ss << "\"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), + "OnRestoreExCallback", ss.str(), ERR_OK); + g_startTimePoint = nullptr; + } extensionPtr->FinishOnProcessTask(); extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); if (errCode == ERR_OK) { @@ -323,6 +342,15 @@ std::function BackupExtExtension::IncreOnRestoreExCa HILOGE("Extension handle have been released"); return; } + if (g_startTimePoint != nullptr && errCode == ERR_OK && !restoreRetInfo.empty()) { + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime - g_startTimePoint).count(); + std::stringstream ss; + ss << "\"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), + "IncreOnRestoreExCallback", ss.str(), ERR_OK); + g_startTimePoint = nullptr; + } extensionPtr->FinishOnProcessTask(); extensionPtr->extension_->InvokeAppExtMethod(errCode, restoreRetInfo); if (errCode == ERR_OK) { @@ -352,6 +380,15 @@ std::function BackupExtExtension::IncreOnRestoreCall return; } HILOGI("Current bundle will execute app done"); + if (g_startTimePoint != nullptr && errCode == ERR_OK) { + auto endTime = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(endTime - g_startTimePoint).count(); + std::stringstream ss; + ss << "\"spend_time\": \"" << ms << "ms\""; + AppRadar::GetInstance().RecordOnRestoreRes("bundlename", AppRadar::GetInstance().GetUserId(), + "IncreOnRestoreCallback", ss.str(), ERR_OK); + g_startTimePoint = nullptr; + } extensionPtr->FinishOnProcessTask(); if (errMsg.empty()) { extensionPtr->AppIncrementalDone(errCode); diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 000241ad00fa33ddcf07acdfb1e09ba657c34a52..b2a7041f53c0b10b3126cab910778403f6f3b3f2 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -16,6 +16,7 @@ #include "b_incremental_restore_session.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -54,6 +55,9 @@ unique_ptr BIncrementalRestoreSession::Init(Callback int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacks))); if (res != 0) { HILOGE("Failed to Restore because of %{public}d", res); + AppRadar::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), + "BIncrementalRestoreSession::Init", + BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index 84f75d66efc567dbca2fd01b5de3c13ab20f57d3..f6008298e0853f4e36e6fdbbdcd44037a55e0ae7 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -16,6 +16,7 @@ #include "b_incremental_session_restore_async.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" @@ -62,6 +63,9 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); if (res != 0) { HILOGE("Failed to Restore because of %{public}d", res); + AppRadar::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), + "BIncrementalSessionRestoreAsync::Init", + BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index 250d68bc7f24b8124536264115c5d79964f7599a..ec2c95bb7a60fbb013c7cbed0bc0d7084727e7c8 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -16,6 +16,7 @@ #include "b_session_restore.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "filemgmt_libhilog.h" #include "service_proxy.h" #include "service_reverse.h" @@ -54,6 +55,8 @@ unique_ptr BSessionRestore::Init(Callbacks callbacks) int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacks)); if (res != 0) { HILOGE("Failed to Restore because of %{public}d", res); + AppRadar::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), "BSessionRestore::Init", + BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index 10c388fb58b468f1ea7bf402fa39527ec0d55a50..0ab2458b18b7b62d346ad37d1a1fadf615449a95 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -16,6 +16,7 @@ #include "b_session_restore_async.h" #include "b_error/b_error.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_session_restore.h" #include "filemgmt_libhilog.h" @@ -62,6 +63,9 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) int32_t res = proxy->InitRestoreSession(sptr(new ServiceReverse(callbacksTmp))); if (res != 0) { HILOGE("Failed to Restore because of %{public}d", res); + AppRadar::GetInstance().RecordRestoreFuncRes(AppRadar::GetInstance().GetUserId(), + "BSessionRestoreAsync::Init", + BizStageRestore::BIZ_STAGE_CREATE_SESSION_RESTORE, res); return nullptr; } diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 1870448e36d8b64b0980ce2579ddc4eb933a1af9..1b84c2e800529e6c78ae84d0bca3e63092209b4f 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -445,6 +445,9 @@ sptr ServiceProxy::GetInstance() loadCallback->proxyConVar_.wait_for(lock, std::chrono::milliseconds(BConstants::BACKUP_LOADSA_TIMEOUT_MS), [loadCallback]() { return loadCallback->isLoadSuccess_.load(); }); if (!waitStatus) { + AppRadar::GetInstance().RecordBackupSARes(AppRadar::GetInstance().GetUserId(), "ServiceProxy::GetInstance", + BError::Codes::EXT_BROKEN_IPC, + "\"reason\": \"Load backup sa timeout\""); HILOGE("Load backup sa timeout"); return nullptr; } @@ -499,6 +502,10 @@ void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t sys { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); + std::stringstream ss; + ss << "\"reason\": \"Load backup sa failed\", \"system_ability_id\": \"" << systemAbilityId << "\""; + AppRadar::GetInstance().RecordBackupSARes(AppRadar::GetInstance().GetUserId(), "ServiceProxy::GetInstance", + BError::Codes::EXT_BROKEN_IPC, ss.str()); unique_lock lock(proxyMutex_); serviceProxy_ = nullptr; isLoadSuccess_.store(false); diff --git a/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp b/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp index f49ed5bd306f00f7e545f4441814dc09b4cc5a30..287f352e13079ba43d57e8f952afd3d85326d096 100644 --- a/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp +++ b/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp @@ -85,6 +85,34 @@ DisposeErr AppGalleryDisposeProxy::EndRestore(const std::string &bundleName) return DoDispose(bundleName, DisposeOperation::END_RESTORE); } +void RecordDoDisposeRes(const std::string &bundleName, DisposeOperation disposeOperation, int32_t err) +{ + switch (disposeOperation) { + case DisposeOperation::START_BACKUP: + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("AppGalleryDisposeProxy::StartBackup", + bundleName, AppRadar::GetInstance().GetUserId(), + BizStage::BIZ_STAGE_APPLICATION, err); + break; + case DisposeOperation::END_BACKUP: + AppRadar::GetInstance().RecordBackUpFuncResWithBundle("AppGalleryDisposeProxy::EndBackup", + bundleName, AppRadar::GetInstance().GetUserId(), + BizStage::BIZ_STAGE_APPLICATION, err); + break; + case DisposeOperation::START_RESTORE: + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, AppRadar::GetInstance().GetUserId(), + "AppGalleryDisposeProxy::StartRestore", + BizStageRestore::BIZ_STAGE_STATUS_CLEAR, err); + break; + case DisposeOperation::END_RESTORE: + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, AppRadar::GetInstance().GetUserId(), + "AppGalleryDisposeProxy::EndRestore", + BizStageRestore::BIZ_STAGE_STATUS_CLEAR, err); + break; + default: + break; + } +} + DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, DisposeOperation disposeOperation) { HILOGI("DoDispose, app %{public}s, operation %{public}d", bundleName.c_str(), disposeOperation); @@ -113,6 +141,7 @@ DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, Disp MessageOption option(MessageOption::TF_ASYNC); int32_t ret = appRemoteObj_->SendRequest(static_cast(disposeOperation), data, reply, option); if (ret != ERR_NONE) { + RecordDoDisposeRes(bundleName, disposeOperation, ret); HILOGI("SendRequest error, code=%{public}d, bundleName=%{public}s", ret, bundleName.c_str()); return DisposeErr::REQUEST_FAIL; } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 6e834db31c8d0902b8dde96de5581cd09fae1d42..0dc0632af28be8afc8d20ee4463f9df4dbacd3f1 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -47,6 +47,7 @@ #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" #include "b_process/b_multiuser.h" +#include "b_radar/b_radar.h" #include "b_resources/b_constants.h" #include "b_sa/b_sa_utils.h" #include "bundle_mgr_client.h" @@ -446,6 +447,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vectorDecreaseSessionCnt(); return e.GetCode(); @@ -511,6 +515,9 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, return BError(BError::Codes::OK); } catch (const BError &e) { HILOGE("Catch exception"); + AppRadar::GetInstance().RecordRestoreFuncResWithBundle("bundlename", GetUserIdDefault(), + "Service::AppendBundlesRestoreSession", + BizStageRestore::BIZ_STAGE_APPEND_BUNDLES, e.GetCode()); HandleExceptionOnAppendBundles(session_, bundleNames, {}); session_->DecreaseSessionCnt(); return e.GetCode(); @@ -975,11 +982,17 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) auto backUpConnection = session_->GetExtConnection(bundleName); if (backUpConnection == nullptr) { HILOGE("GetFileHandle error, backUpConnection is empty"); + AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), + static_cast(BError::Codes::SA_INVAL_ARG), + "{\"reason\":\"backUpConnection is empty\"}"); return BError(BError::Codes::SA_INVAL_ARG); } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { HILOGE("GetFileHandle error, Extension backup Proxy is empty"); + AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), + static_cast(BError::Codes::SA_INVAL_ARG), + "{\"reason\":\"Extension backup Proxy is empty\"}"); return BError(BError::Codes::SA_INVAL_ARG); } int32_t errCode = 0; @@ -990,6 +1003,9 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) } return BError(BError::Codes::OK); } catch (const BError &e) { + AppRadar::GetInstance().RecordGetFileHandleRes(bundleName, GetUserIdDefault(), + static_cast(e.GetCode()), + "{\"reason\":\"catch error\"}"); return e.GetCode(); } catch (const exception &e) { HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); @@ -1002,6 +1018,14 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) void Service::OnBackupExtensionDied(const string &&bundleName) { + IServiceReverse::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), "OnBackupExtensionDied", + BizStageRestore::BIZ_STAGE_BACKUP_EXTENSION, + BError::Codes::EXT_ABILITY_DIED); + } HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { string callName = move(bundleName); @@ -1136,6 +1160,13 @@ void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) try { HILOGE("begin %{public}s", bundleName.data()); IServiceReverse::Scenario scenario = session_->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), "Service::ExtConnectFailed", + BizStageRestore::BIZ_STAGE_CONNECT_BACKUP_EXTENSION, + ret); + } if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleStarted(ret, bundleName); } else if (scenario == IServiceReverse::Scenario::RESTORE && @@ -1425,6 +1456,18 @@ void Service::UnloadService() void Service::SessionDeactive() { + IServiceReverse::Scenario scenario = sessionPtr->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + AppRadar::GetInstance().RecordBackUpFuncResWithoutBundle("SessionDeactive", AppRadar::GetInstance().GetUserId(), + BizStage::BIZ_STAGE_CLIENT_STATUS, + static_cast(BError::Codes::SA_BROKEN_IPC), + "cloud_clone"); + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + AppRadar::GetInstance().RecordRestoreFuncResWithResult(AppRadar::GetInstance().GetUserId(), "SessionDeactive", + BizStageRestore::BIZ_STAGE_CLIENT_STATUS, + static_cast(BError::Codes::SA_BROKEN_IPC), + "cloud_clone"); + } HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); @@ -1828,6 +1871,15 @@ std::function Service::TimeOutCallback(wptr ptr, std::string bu HILOGE("SessionPtr is nullptr."); return; } + IServiceReverse::Scenario scenario = sessionPtr->GetScenario(); + if (scenario == IServiceReverse::Scenario::BACKUP) { + + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + int32_t errCode = static_cast(BError::Codes::EXT_ABILITY_TIMEOUT); + AppRadar::GetInstance().RecordRestoreFuncResWithBundle(bundleName, GetUserIdDefault(), "TimeOutCallback", + BizStageRestore::BIZ_STAGE_EXEC_ON_RESTORE, + errCode); + } try { if (SAUtils::IsSABundleName(bundleName)) { auto sessionConnection = sessionPtr->GetSAExtConnection(bundleName); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 1ff282364003bb5634aeb68643db99d54c8dcc05..eff43dff316d524942becaf571877374e0f50cb9 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -74,6 +74,7 @@ ohos_shared_library("backup_utils") { "src/b_process/b_guard_cwd.cpp", "src/b_process/b_guard_signal.cpp", "src/b_process/b_process.cpp", + "src/b_radar/b_radar.cpp", "src/b_sa/b_sa_utils.cpp", "src/b_tarball/b_tarball_cmdline.cpp", "src/b_tarball/b_tarball_factory.cpp", @@ -90,6 +91,7 @@ ohos_shared_library("backup_utils") { "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", "hilog:libhilog", + "hisysevent:libhisysevent", "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h new file mode 100644 index 0000000000000000000000000000000000000000..e49111ac32b67d2fd2bdb6f354d16c65e942414f --- /dev/null +++ b/utils/include/b_radar/b_radar.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_B_RADAR_H +#define OHOS_FILEMGMT_BACKUP_B_RADAR_H +#include +#include + +namespace { + std::chrono::time_point g_onBackUpStart; + std::chrono::time_point g_onRestoreStart; +} // namespace + +namespace OHOS::FileManagement::Backup { +enum class BizScene : int32_t { + BACKUP = 1, + RESTORE = 2 +}; + +enum class BizStage : int32_t { + BIZ_STAGE_GET_LOCAL_CAPABILITIES = 1, + BIZ_STAGE_GET_BACKUP_INFO, + BIZ_STAGE_CREATE_SESSION_BACKUP, + BIZ_STAGE_BACKUP_SA, + BIZ_STAGE_APPEND_BUNDLES, + BIZ_STAGE_BACKUP_EXTENSION, + BIZ_STAGE_APPLICATION, + BIZ_STAGE_EXTENSION_STATUS, + BIZ_STAGE_ON_BACKUP, + BIZ_STAGE_DO_BACKUP, + BIZ_STAGE_DATA_CONSISTENCY, + BIZ_STAGE_STATUS_CLEAR, + BIZ_STAGE_CLIENT_STATUS, + BIZ_STAGE_PERMISSION_CHECK +}; + +enum class BizStageRestore : int32_t { + BIZ_STAGE_GET_LOCAL_CAPABILITIES = 1, + BIZ_STAGE_CREATE_SESSION_RESTORE, + BIZ_STAGE_BACKUP_SA, + BIZ_STAGE_APPEND_BUNDLES, + BIZ_STAGE_CONNECT_BACKUP_EXTENSION, + BIZ_STAGE_APPLICATION, + BIZ_STAGE_EXTENSION_STATUS, + BIZ_STAGE_GET_FILE_HANDLE, + BIZ_STAGE_DO_RESTORE, + BIZ_STAGE_DATA_CONSISTENCY, + BIZ_STAGE_EXEC_ON_RESTORE, + BIZ_STAGE_STATUS_CLEAR, + BIZ_STAGE_CLIENT_STATUS, + BIZ_STAGE_PERMISSION_CHECK +}; + +class AppRadar { +public: + static AppRadar &GetInstance() + { + static AppRadar instance; + return instance; + } + +public: + int32_t GetUserId(); + void RecordBackUpFuncResWithBundle(const std::string &func, const std::string &bundleName, int32_t userId, + enum BizStage bizStage, int32_t resultCode, + const std::string &resultInfo = "{\"reason\":\"failed\"}"); + void RecordBackUpFuncResWithoutBundle(const std::string &func, int32_t userId, + enum BizStage bizStage, int32_t resultCode, + const std::string &resultInfo = "{\"reason\":\"failed\"}"); + void RecordDoBackUpRes(const std::string &func, int32_t userId, int32_t resultCode, int32_t exportDuration); + void RecordRestoreFuncRes(int32_t userId, const std::string &func, enum BizStageRestore bizStage, + int32_t resultCode); + void RecordRestoreFuncResWithBundle(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, int32_t resultCode); + void RecordRestoreFuncResWithResult(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, int32_t resultCode, + const std::string &resultInfo); + void RecordRestoreFuncResWithStatus(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, const std::string &execStatus, + int32_t resultCode); + void RecordGetFileHandleRes(const std::string &bundleName, int32_t userId, int32_t resultCode, + const std::string &resultInfo); + void RecordOnRestoreRes(const std::string &bundleName, int32_t userId, const std::string &func, + const std::string &execStatus, int32_t resultCode); + void RecordBackupSARes(int32_t userId, const std::string &func, int32_t resultCode, const std::string &resultInfo); +private: + AppRadar() = default; + ~AppRadar() = default; + AppRadar(const AppRadar &) = delete; + AppRadar &operator=(const AppRadar &) = delete; + AppRadar(AppRadar &&) = delete; + AppRadar &operator=(AppRadar &&) = delete; +}; +} // namespace OHOS::FileManagement::AppRadar +#endif // OHOS_FILEMGMT_BACKUP_B_RADAR_H diff --git a/utils/src/b_radar/b_radar.cpp b/utils/src/b_radar/b_radar.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9f9777dc5dbcdd0616e9b7b528081d611a895d9 --- /dev/null +++ b/utils/src/b_radar/b_radar.cpp @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "b_radar/b_radar.h" + +#include +#include +#include + +#include "b_process/b_multiuser.h" +#include "b_resources/b_constants.h" +#include "hisysevent.h" + +namespace { +constexpr uint8_t INDEX = 3; +constexpr int32_t MS_1000 = 1000; +const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS"; +} +namespace OHOS::FileManagement::Backup { +static std::string GetCurrentTime() +{ + auto now = std::chrono::system_clock::now(); + auto time = std::chrono::system_clock::to_time_t(now); + auto ms = std::chrono::duration_cast(now.time_since_epoch()); + std::stringstream strTime; + strTime << (std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S:")) << (std::setfill('0')) + << (std::setw(INDEX)) << (ms.count() % MS_1000); + return strTime.str(); +} + +int32_t AppRadar::GetUserId() +{ + auto multiuser = BMultiuser::ParseUid(getuid()); + if ((multiuser.userId == BConstants::SYSTEM_UID) || (multiuser.userId == BConstants::XTS_UID)) { + return BConstants::DEFAULT_USER_ID; + } + return multiuser.userId; +} + +void RecordFuncResWithResult(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizScene bizScene, int32_t bizStage, int32_t resultCode, + const std::string &resultInfo) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(bizScene), + "BIZ_STAGE", bizStage, + "RESULT_CODE", resultCode, + "RESULT_INFO", resultInfo); +} + +void AppRadar::RecordBackUpFuncResWithBundle(const std::string &func, const std::string &bundleName, + int32_t userId, enum BizStage bizStage, int32_t resultCode, + const std::string &resultInfo) +{ + RecordFuncResWithResult(bundleName, userId, func, BizScene::BACKUP, static_cast(bizStage), resultCode, + resultInfo); +} + +void AppRadar::RecordBackUpFuncResWithoutBundle(const std::string &func, int32_t userId, enum BizStage bizStage, + int32_t resultCode, const std::string &resultInfo) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::BACKUP), + "BIZ_STAGE", static_cast(bizStage), + "RESULT_CODE", resultCode, + "RESULT_INFO", resultInfo); +} + +void AppRadar::RecordDoBackUpRes(const std::string &func, int32_t userId, int32_t pid, int32_t resultCode, + int32_t exportDuration) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::BACKUP), + "BIZ_STAGE", static_cast(BizStage::BIZ_STAGE_DO_BACKUP), + "EXEC_STATUS", "{\"spend_time\":" + std::to_string(exportDuration) + "ms\"}", + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordRestoreFuncRes(int32_t userId, const std::string &func, enum BizStageRestore bizStage, + int32_t resultCode) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(bizScene), + "BIZ_STAGE", bizStage, + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordRestoreFuncResWithBundle(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, int32_t resultCode) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(bizScene), + "BIZ_STAGE", bizStage, + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordRestoreFuncResWithResult(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, int32_t resultCode, + const std::string &resultInfo) +{ + RecordFuncResWithResult(bundleName, userId, func, BizScene::RESTORE, static_cast(bizStage), resultCode, + resultInfo); +} + +void AppRadar::RecordRestoreFuncResWithStatus(const std::string &bundleName, int32_t userId, const std::string &func, + enum BizStageRestore bizStage, const std::string &execStatus, + int32_t resultCode) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(bizStage), + "EXEC_STATUS", execStatus, + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordGetFileHandleRes(const std::string &bundleName, int32_t userId, int32_t resultCode, + const std::string &resultInfo) +{ + RecordFuncResWithResult(bundleName, userId, BizScene::RESTORE, BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE, + resultCode, resultInfo); +} + +void AppRadar::RecordOnRestoreRes(const std::string &bundleName, int32_t userId, const std::string &func, + const std::string &execStatus, int32_t resultCode) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "BUNDLE_NAME", bundleName, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(BizStageRestore::BIZ_STAGE_EXEC_ON_RESTORE), + "EXEC_STATUS", execStatus, + "RESULT_CODE", resultCode); +} + +void AppRadar::RecordBackupSARes(int32_t userId, const std::string &func, int32_t resultCode, + const std::string &resultInfo) +{ + HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, + FILE_BACKUP_EVENTS, + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "USER_ID", userId, + "PID", getpid(), + "FUNC", func, + "TIME", GetCurrentTime(), + "BIZ_SCENE", static_cast(BizScene::RESTORE), + "BIZ_STAGE", static_cast(BizStageRestore::BIZ_STAGE_BACKUP_SA), + "RESULT_CODE", resultCode, + "RESULT_INFO", resultInfo); +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file