diff --git a/frameworks/native/backup_ext/BUILD.gn b/frameworks/native/backup_ext/BUILD.gn index 379f3c72b0d248cd51269d8ceba195bc1f740d83..eb044ee941024402744b702b845a89ec4965dbec 100644 --- a/frameworks/native/backup_ext/BUILD.gn +++ b/frameworks/native/backup_ext/BUILD.gn @@ -65,6 +65,7 @@ ohos_shared_library("backup_extension_ability_native") { "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", "ipc:ipc_core", "napi:ace_napi", ] diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 0c0c719619388623e3de925338e07b9e868a340a..37431c3835864af88a7c2656f82d99e5174f0b30 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -41,18 +41,19 @@ #include "b_resources/b_constants.h" #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" +#include "hitrace_meter.h" #include "service_proxy.h" #include "tar_file.h" #include "untar_file.h" namespace OHOS::FileManagement::Backup { const string DEFAULT_TAR_PKG = "1.tar"; -const string INDEX_FILE_BACKUP = string(BConstants::PATH_BUNDLE_BACKUP_HOME). - append(BConstants::SA_BUNDLE_BACKUP_BACKUP). - append(BConstants::EXT_BACKUP_MANAGE); -const string INDEX_FILE_RESTORE = string(BConstants::PATH_BUNDLE_BACKUP_HOME). - append(BConstants::SA_BUNDLE_BACKUP_RESTORE). - append(BConstants::EXT_BACKUP_MANAGE); +const string INDEX_FILE_BACKUP = string(BConstants::PATH_BUNDLE_BACKUP_HOME) + .append(BConstants::SA_BUNDLE_BACKUP_BACKUP) + .append(BConstants::EXT_BACKUP_MANAGE); +const string INDEX_FILE_RESTORE = string(BConstants::PATH_BUNDLE_BACKUP_HOME) + .append(BConstants::SA_BUNDLE_BACKUP_RESTORE) + .append(BConstants::EXT_BACKUP_MANAGE); using namespace std; void BackupExtExtension::VerifyCaller() @@ -70,7 +71,7 @@ void BackupExtExtension::VerifyCaller() } } -static bool CheckAndCreateDirectory(const string& filePath) +static bool CheckAndCreateDirectory(const string &filePath) { size_t pos = filePath.rfind('/'); if (pos == string::npos) { @@ -88,6 +89,7 @@ static bool CheckAndCreateDirectory(const string& filePath) static UniqueFd GetFileHandleForSpecialCloneCloud(const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGE("GetFileHandleForSpecialCloneCloud: fileName is %{public}s", fileName.data()); string filePath = fileName; if (fileName.front() != BConstants::FILE_SEPARATOR_CHAR) { @@ -111,6 +113,7 @@ static UniqueFd GetFileHandleForSpecialCloneCloud(const string &fileName) UniqueFd BackupExtExtension::GetFileHandle(const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { if (extension_->GetExtensionAction() != BConstants::ExtensionAction::RESTORE) { HILOGI("Failed to get file handle, because action is %{public}d invalid", extension_->GetExtensionAction()); @@ -143,11 +146,13 @@ UniqueFd BackupExtExtension::GetFileHandle(const string &fileName) ErrCode BackupExtExtension::GetIncrementalFileHandle(const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); return ERR_OK; } ErrCode BackupExtExtension::HandleClear() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("begin clear"); if (extension_->GetExtensionAction() == BConstants::ExtensionAction::INVALID) { throw BError(BError::Codes::EXT_INVAL_ARG, "Action is invalid"); @@ -159,6 +164,7 @@ ErrCode BackupExtExtension::HandleClear() static ErrCode IndexFileReady(const TarMap &pkgInfo, sptr proxy) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); BJsonCachedEntity cachedEntity( UniqueFd(open(INDEX_FILE_BACKUP.data(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR))); auto cache = cachedEntity.Structuralize(); @@ -181,6 +187,7 @@ static ErrCode IndexFileReady(const TarMap &pkgInfo, sptr proxy) static ErrCode BigFileReady(sptr proxy) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); BJsonCachedEntity cachedEntity(UniqueFd(open(INDEX_FILE_BACKUP.data(), O_RDONLY))); auto cache = cachedEntity.Structuralize(); auto pkgInfo = cache.GetExtManageInfo(); @@ -212,6 +219,7 @@ static ErrCode BigFileReady(sptr proxy) static bool IsAllFileReceived(vector tars, bool isSpeicalVersion) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); // 是否已收到索引文件 if (isSpeicalVersion) { HILOGI("Check if manage.json is received for SpeicalVersion."); @@ -246,6 +254,7 @@ static bool IsAllFileReceived(vector tars, bool isSpeicalVersion) ErrCode BackupExtExtension::PublishFile(const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGE("begin publish file. fileName is %{public}s", fileName.data()); try { if (extension_->GetExtensionAction() != BConstants::ExtensionAction::RESTORE) { @@ -290,11 +299,13 @@ ErrCode BackupExtExtension::PublishFile(const string &fileName) ErrCode BackupExtExtension::PublishIncrementalFile(const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); return ERR_OK; } ErrCode BackupExtExtension::HandleBackup() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); string usrConfig = extension_->GetUsrConfig(); BJsonCachedEntity cachedEntity(usrConfig); auto cache = cachedEntity.Structuralize(); @@ -309,6 +320,7 @@ ErrCode BackupExtExtension::HandleBackup() static bool IsUserTar(const string &tarFile, const string &indexFile) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); if (tarFile.empty()) { return false; } @@ -316,8 +328,7 @@ static bool IsUserTar(const string &tarFile, const string &indexFile) BJsonCachedEntity cachedEntity(UniqueFd(open(filePath.data(), O_RDONLY))); auto cache = cachedEntity.Structuralize(); auto info = cache.GetExtManageInfo(); - auto iter = find_if(info.begin(), info.end(), - [&tarFile](const auto& item) { return item.hashName == tarFile; }); + auto iter = find_if(info.begin(), info.end(), [&tarFile](const auto &item) { return item.hashName == tarFile; }); if (iter != info.end()) { HILOGI("tarFile:%{public}s isUserTar:%{public}d", tarFile.data(), iter->isUserTar); return iter->isUserTar; @@ -328,6 +339,7 @@ static bool IsUserTar(const string &tarFile, const string &indexFile) static pair> GetFileInfos(const vector &includes, const vector &excludes) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto [errCode, files, smallFiles] = BDir::GetBigFiles(includes, excludes); if (errCode != 0) { return {}; @@ -363,6 +375,7 @@ static pair> GetFileInfos(const vector &includes, int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Do backup"); if (extension_->GetExtensionAction() != BConstants::ExtensionAction::BACKUP) { return EPERM; @@ -405,6 +418,7 @@ int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) int BackupExtExtension::DoRestore(const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Do restore"); if (extension_->GetExtensionAction() != BConstants::ExtensionAction::RESTORE) { return EPERM; @@ -427,6 +441,7 @@ int BackupExtExtension::DoRestore(const string &fileName) void BackupExtExtension::AsyncTaskBackup(const string config) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto task = [obj {wptr(this)}, config]() { auto ptr = obj.promote(); BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, @@ -465,7 +480,8 @@ void BackupExtExtension::AsyncTaskBackup(const string config) static void RestoreBigFilesForSpecialCloneCloud(ExtManageInfo item) { - struct stat& sta = item.sta; + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + struct stat &sta = item.sta; string fileName = item.hashName; if (chmod(fileName.c_str(), sta.st_mode) != 0) { HILOGE("Failed to chmod filePath, err = %{public}d", errno); @@ -480,6 +496,7 @@ static void RestoreBigFilesForSpecialCloneCloud(ExtManageInfo item) static ErrCode RestoreTarForSpeicalCloneCloud(ExtManageInfo item) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); string tarName = item.hashName; if (item.fileName.empty()) { HILOGE("Invalid untar path info for tar %{public}s", tarName.c_str()); @@ -499,6 +516,7 @@ static ErrCode RestoreTarForSpeicalCloneCloud(ExtManageInfo item) static ErrCode RestoreFilesForSpecialCloneCloud() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); // 获取索引文件内容 string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); BJsonCachedEntity cachedEntity(UniqueFd(open(INDEX_FILE_RESTORE.data(), O_RDONLY))); @@ -527,8 +545,7 @@ static ErrCode RestoreFilesForSpecialCloneCloud() return ERR_OK; } -static bool RestoreBigFilePrecheck(string& fileName, const string& path, - const string& hashName, const string& filePath) +static bool RestoreBigFilePrecheck(string &fileName, const string &path, const string &hashName, const string &filePath) { if (filePath.empty()) { HILOGE("file path is empty. %{public}s", filePath.c_str()); @@ -549,8 +566,10 @@ static bool RestoreBigFilePrecheck(string& fileName, const string& path, return true; } -static void RestoreBigFileAfter(const string& fileName, const string& filePath, const struct stat& sta, - const set& lks) +static void RestoreBigFileAfter(const string &fileName, + const string &filePath, + const struct stat &sta, + const set &lks) { if (chmod(filePath.c_str(), sta.st_mode) != 0) { HILOGE("Failed to chmod filePath, err = %{public}d", errno); @@ -590,6 +609,7 @@ static void RestoreBigFileAfter(const string& fileName, const string& filePath, static void RestoreBigFiles(bool appendTargetPath) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); // 获取索引文件内容 string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); BJsonCachedEntity cachedEntity(UniqueFd(open(INDEX_FILE_RESTORE.data(), O_RDONLY))); @@ -612,13 +632,14 @@ static void RestoreBigFiles(bool appendTargetPath) HILOGE("failed to copy the file. err = %{public}d", errno); continue; } - + RestoreBigFileAfter(fileName, filePath, item.sta, cache.GetHardLinkInfo(item.hashName)); } } static void DeleteBackupTars() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); // The directory include tars and manage.json which would be deleted BJsonCachedEntity cachedEntity(UniqueFd(open(INDEX_FILE_RESTORE.data(), O_RDONLY))); auto cache = cachedEntity.Structuralize(); @@ -640,6 +661,7 @@ static void DeleteBackupTars() void BackupExtExtension::AsyncTaskRestore() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto task = [obj {wptr(this)}, tars {tars_}]() { auto ptr = obj.promote(); BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have already released"); @@ -663,15 +685,14 @@ void BackupExtExtension::AsyncTaskRestore() } // 恢复用户tar包以及大文件 // 目的地址是否需要拼接path(临时目录),FullBackupOnly为true并且非特殊场景 - bool appendTargetPath = ptr->extension_->UseFullBackupOnly() && - !ptr->extension_->SpeicalVersionForCloneAndCloud(); + bool appendTargetPath = + ptr->extension_->UseFullBackupOnly() && !ptr->extension_->SpeicalVersionForCloneAndCloud(); RestoreBigFiles(appendTargetPath); // delete 1.tar/manage.json DeleteBackupTars(); if (ret == ERR_OK) { - HILOGI("after extra, do restore."); ptr->AsyncTaskRestoreForUpgrade(); } else { ptr->AppDone(ret); @@ -702,6 +723,7 @@ void BackupExtExtension::AsyncTaskRestore() void BackupExtExtension::AsyncTaskRestoreForUpgrade() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto task = [obj {wptr(this)}]() { auto ptr = obj.promote(); try { @@ -751,6 +773,7 @@ void BackupExtExtension::ExtClear() void BackupExtExtension::DoClear() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { string backupCache = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); string restoreCache = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); @@ -776,6 +799,7 @@ void BackupExtExtension::DoClear() void BackupExtExtension::AppDone(ErrCode errCode) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto proxy = ServiceProxy::GetInstance(); BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); auto ret = proxy->AppDone(errCode); @@ -786,6 +810,7 @@ void BackupExtExtension::AppDone(ErrCode errCode) void BackupExtExtension::AsyncTaskOnBackup() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto task = [obj {wptr(this)}]() { auto ptr = obj.promote(); try { @@ -827,6 +852,7 @@ void BackupExtExtension::AsyncTaskOnBackup() ErrCode BackupExtExtension::HandleRestore() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); VerifyCaller(); if (extension_->GetExtensionAction() != BConstants::ExtensionAction::RESTORE) { HILOGI("Failed to get file handle, because action is %{public}d invalid", extension_->GetExtensionAction()); @@ -850,11 +876,13 @@ ErrCode BackupExtExtension::HandleRestore() ErrCode BackupExtExtension::HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); return 0; } tuple BackupExtExtension::GetIncrementalBackupFileHandle() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); return {UniqueFd(-1), UniqueFd(-1)}; } } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 43e01a9942b6e5af5805dc557c778526d84d667f..f771764d627f3ac0a9ca51648444bc368fdf89d8 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -23,12 +23,14 @@ #include "b_resources/b_constants.h" #include "filemgmt_libhilog.h" #include "svc_death_recipient.h" +#include "hitrace_meter.h" namespace OHOS::FileManagement::Backup { using namespace std; ErrCode ServiceProxy::InitRestoreSession(sptr remote) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -56,6 +58,7 @@ ErrCode ServiceProxy::InitRestoreSession(sptr remote) ErrCode ServiceProxy::InitBackupSession(sptr remote) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -83,6 +86,7 @@ ErrCode ServiceProxy::InitBackupSession(sptr remote) ErrCode ServiceProxy::Start() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -103,6 +107,7 @@ ErrCode ServiceProxy::Start() UniqueFd ServiceProxy::GetLocalCapabilities() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -126,6 +131,7 @@ UniqueFd ServiceProxy::GetLocalCapabilities() ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -151,6 +157,7 @@ ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo) ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -178,6 +185,7 @@ ErrCode ServiceProxy::AppFileReady(const string &fileName, UniqueFd fd) ErrCode ServiceProxy::AppDone(ErrCode errCode) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -202,6 +210,7 @@ ErrCode ServiceProxy::AppDone(ErrCode errCode) ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -233,6 +242,7 @@ ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, RestoreTypeEnum restoreType, int32_t userId) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -267,6 +277,7 @@ ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundleNames) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -292,6 +303,7 @@ ErrCode ServiceProxy::AppendBundlesBackupSession(const vector &bundl ErrCode ServiceProxy::Finish() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -312,6 +324,7 @@ ErrCode ServiceProxy::Finish() sptr ServiceProxy::GetInstance() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); unique_lock lock(proxyMutex_); if (serviceProxy_ != nullptr) { return serviceProxy_; @@ -346,6 +359,7 @@ sptr ServiceProxy::GetInstance() void ServiceProxy::InvaildInstance() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("invalid instance"); unique_lock lock(proxyMutex_); serviceProxy_ = nullptr; @@ -354,6 +368,7 @@ void ServiceProxy::InvaildInstance() void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const OHOS::sptr &remoteObject) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Load backup sa success, systemAbilityId: %{private}d, remoteObject result:%{private}s", systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); if (systemAbilityId != FILEMANAGEMENT_BACKUP_SERVICE_SA_ID || remoteObject == nullptr) { @@ -384,6 +399,7 @@ void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGE("Load backup sa failed, systemAbilityId:%{private}d", systemAbilityId); unique_lock lock(proxyMutex_); serviceProxy_ = nullptr; diff --git a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn index 15a5bf02a2b004acdf97ca07d6b3d0f7cdeb3b84..f84fc96cc9e7190e0df11d6f833ae830598f8c91 100644 --- a/interfaces/inner_api/native/backup_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/backup_kit_inner/BUILD.gn @@ -67,6 +67,7 @@ ohos_shared_library("backup_kit_inner") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index fbe375226771cf2380bbc96a46a613eed611a1b9..53ff7a4f5f6bc32b14b6312147c5b76ea5ff5197 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -63,6 +63,7 @@ ohos_shared_library("backup_sa") { "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 547fe51fd7136c82ff6f5e248debc6ae29b51518..da89e8db7dc90127a53a4ed26be437cff7246eaa 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -55,6 +55,7 @@ #include "module_ipc/svc_restore_deps_manager.h" #include "parameter.h" #include "system_ability_definition.h" +#include "hitrace_meter.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -81,6 +82,7 @@ static inline int32_t GetUserIdDefault() void Service::OnStart() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); bool res = SystemAbility::Publish(sptr(this)); sched_ = sptr(new SchedScheduler(wptr(this), wptr(session_))); sched_->StartTimer(); @@ -89,6 +91,7 @@ void Service::OnStart() void Service::OnStop() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Called"); int32_t oldMemoryParaSize = BConstants::DEFAULT_VFS_CACHE_PRESSURE; if (session_ != nullptr) { @@ -99,6 +102,7 @@ void Service::OnStop() UniqueFd Service::GetLocalCapabilities() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); /* @@ -139,11 +143,13 @@ UniqueFd Service::GetLocalCapabilities() void Service::StopAll(const wptr &obj, bool force) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); session_->Deactive(obj, force); } string Service::VerifyCallerAndGetCallerName() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); uint32_t tokenCaller = IPCSkeleton::GetCallingTokenID(); int tokenType = Security::AccessToken::AccessTokenKit::GetTokenType(tokenCaller); if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { @@ -161,6 +167,7 @@ string Service::VerifyCallerAndGetCallerName() void Service::VerifyCaller() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); uint32_t tokenCaller = IPCSkeleton::GetCallingTokenID(); int tokenType = Security::AccessToken::AccessTokenKit::GetTokenType(tokenCaller); switch (tokenType) { @@ -187,12 +194,14 @@ void Service::VerifyCaller() void Service::VerifyCaller(IServiceReverse::Scenario scenario) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); session_->VerifyCallerAndScenario(IPCSkeleton::GetCallingTokenID(), scenario); VerifyCaller(); } ErrCode Service::InitRestoreSession(sptr remote) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { VerifyCaller(); session_->Active({ @@ -216,6 +225,7 @@ ErrCode Service::InitRestoreSession(sptr remote) ErrCode Service::InitBackupSession(sptr remote) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { VerifyCaller(); int32_t oldSize = StorageMgrAdapter::UpdateMemPara(BConstants::BACKUP_VFS_CACHE_PRESSURE); @@ -236,6 +246,7 @@ ErrCode Service::InitBackupSession(sptr remote) ErrCode Service::Start() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); VerifyCaller(session_->GetScenario()); session_->Start(); @@ -257,6 +268,7 @@ static vector GetRestoreBundleNames(UniqueFd fd, sptr session, const vector &bundleNames) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 auto restoreInfos = BundleMgrAdapter::GetBundleInfos(bundleNames, session->GetSessionUserId()); BJsonCachedEntity cachedEntity(move(fd)); @@ -291,6 +303,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, RestoreTypeEnum restoreType, int32_t userId) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); session_->IncreaseSessionCnt(); @@ -342,6 +355,7 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, ErrCode Service::AppendBundlesBackupSession(const vector &bundleNames) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); session_->IncreaseSessionCnt(); // BundleMgrAdapter::GetBundleInfos可能耗时 @@ -377,6 +391,7 @@ ErrCode Service::AppendBundlesBackupSession(const vector &bundleName ErrCode Service::Finish() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Begin"); VerifyCaller(session_->GetScenario()); session_->Finish(); @@ -386,6 +401,7 @@ ErrCode Service::Finish() ErrCode Service::PublishFile(const BFileInfo &fileInfo) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); VerifyCaller(IServiceReverse::Scenario::RESTORE); @@ -415,6 +431,7 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); string callerName = VerifyCallerAndGetCallerName(); @@ -458,6 +475,7 @@ ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd) ErrCode Service::AppDone(ErrCode errCode) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); string callerName = VerifyCallerAndGetCallerName(); @@ -493,6 +511,7 @@ ErrCode Service::AppDone(ErrCode errCode) ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGE("begin %{public}s", bundleName.data()); IServiceReverse::Scenario scenario = session_->GetScenario(); @@ -535,6 +554,7 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); VerifyCaller(IServiceReverse::Scenario::RESTORE); @@ -572,6 +592,7 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) void Service::OnBackupExtensionDied(const string &&bundleName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { string callName = move(bundleName); session_->VerifyBundleName(callName); @@ -613,6 +634,7 @@ void Service::OnBackupExtensionDied(const string &&bundleName) void Service::ExtConnectDied(const string &callName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); /* Clear Timer */ @@ -633,6 +655,7 @@ void Service::ExtConnectDied(const string &callName) void Service::ExtStart(const string &bundleName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGE("begin %{public}s", bundleName.data()); if (IncrementalBackup(bundleName)) { @@ -690,6 +713,7 @@ int Service::Dump(int fd, const vector &args) void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGE("begin %{public}s", bundleName.data()); IServiceReverse::Scenario scenario = session_->GetScenario(); @@ -726,6 +750,7 @@ void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); auto scenario = session_->GetScenario(); if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); @@ -742,6 +767,7 @@ void Service::NoticeClientFinish(const string &bundleName, ErrCode errCode) void Service::ExtConnectDone(string bundleName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); /* Callback for App Ext Timeout Process. */ auto timeoutCallback = [ptr {wptr(this)}, bundleName]() { auto thisPtr = ptr.promote(); @@ -778,6 +804,7 @@ void Service::ExtConnectDone(string bundleName) void Service::ClearSessionAndSchedInfo(const string &bundleName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { session_->RemoveExtInfo(bundleName); sched_->RemoveExtConn(bundleName); @@ -796,6 +823,7 @@ void Service::ClearSessionAndSchedInfo(const string &bundleName) void Service::HandleRestoreDepsBundle(const string &bundleName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); if (session_->GetScenario() != IServiceReverse::Scenario::RESTORE) { return; } @@ -835,6 +863,7 @@ void Service::HandleRestoreDepsBundle(const string &bundleName) void Service::OnAllBundlesFinished(ErrCode errCode) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); if (session_->IsOnAllBundlesFinished()) { IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario == IServiceReverse::Scenario::BACKUP && session_->GetIsIncrementalBackup()) { @@ -855,6 +884,7 @@ void Service::OnAllBundlesFinished(ErrCode errCode) void Service::OnStartSched() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); if (session_->IsOnOnStartSched()) { for (int num = 0; num < BConstants::EXT_CONNECT_MAX_COUNT; num++) { sched_->Sched(); @@ -864,6 +894,7 @@ void Service::OnStartSched() void Service::SendAppGalleryNotify(const BundleName &bundleName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); IServiceReverse::Scenario scenario = session_->GetScenario(); if (scenario == IServiceReverse::Scenario::RESTORE) { DisposeErr disposeErr = AppGalleryDisposeProxy::GetInstance()->StartRestore(bundleName); @@ -874,6 +905,7 @@ void Service::SendAppGalleryNotify(const BundleName &bundleName) void Service::SessionDeactive() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { HILOGI("Begin"); // 结束定时器 diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp index 8d1c9276c23dbb5afcb0df488a4ec022b15f3e39..690a5241bfbb19a4aff54518ff9557cc490dabaa 100644 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp @@ -20,12 +20,14 @@ #include "filemgmt_libhilog.h" #include "iservice_registry.h" #include "system_ability_definition.h" +#include "hitrace_meter.h" namespace OHOS::FileManagement::Backup { using namespace std; UniqueFd SvcExtensionProxy::GetFileHandle(const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Start"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -52,6 +54,7 @@ UniqueFd SvcExtensionProxy::GetFileHandle(const string &fileName) ErrCode SvcExtensionProxy::HandleClear() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Start"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -72,6 +75,7 @@ ErrCode SvcExtensionProxy::HandleClear() ErrCode SvcExtensionProxy::HandleBackup() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Start"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -92,6 +96,7 @@ ErrCode SvcExtensionProxy::HandleBackup() ErrCode SvcExtensionProxy::PublishFile(const string &fileName) { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Start"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; @@ -117,6 +122,7 @@ ErrCode SvcExtensionProxy::PublishFile(const string &fileName) ErrCode SvcExtensionProxy::HandleRestore() { + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Start"); BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); MessageParcel data; diff --git a/tests/moduletests/backup_kit_inner/BUILD.gn b/tests/moduletests/backup_kit_inner/BUILD.gn index 84db4ecaf0eb3742472668d5343c4862fff3228f..802b75080f8c887ad6f3e7605f5060d7b53f71cc 100644 --- a/tests/moduletests/backup_kit_inner/BUILD.gn +++ b/tests/moduletests/backup_kit_inner/BUILD.gn @@ -51,6 +51,7 @@ ohos_unittest("b_session_test") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/tests/moduletests/backup_tool/BUILD.gn b/tests/moduletests/backup_tool/BUILD.gn index 177c8e10be98c52f48ab8b8b710de6a92d6e5b34..6606cc1645eb55d62011d92b366d2a4103b0f8c3 100644 --- a/tests/moduletests/backup_tool/BUILD.gn +++ b/tests/moduletests/backup_tool/BUILD.gn @@ -24,7 +24,10 @@ ohos_unittest("tools_op_test") { "${path_backup}/utils/:backup_utils", ] - external_deps = [ "hilog:libhilog" ] + external_deps = [ + "hilog:libhilog", + "hitrace:hitrace_meter", + ] use_exceptions = true } diff --git a/tests/unittests/backup_api/backup_impl/BUILD.gn b/tests/unittests/backup_api/backup_impl/BUILD.gn index 5f28f599ae17e10316bf72ad5ecb9b85cfcdff18..182e63235ea92d9141ad85e1a16cf11ff9890147 100644 --- a/tests/unittests/backup_api/backup_impl/BUILD.gn +++ b/tests/unittests/backup_api/backup_impl/BUILD.gn @@ -67,6 +67,7 @@ ohos_unittest("backup_sa_impl_test") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/tests/unittests/backup_ext/BUILD.gn b/tests/unittests/backup_ext/BUILD.gn index d41d18ddbf74a4bc70566ac65d9a7ec2caa002a5..7c7eb93983f7ce6120d3e6d6756639a19051f43c 100644 --- a/tests/unittests/backup_ext/BUILD.gn +++ b/tests/unittests/backup_ext/BUILD.gn @@ -64,6 +64,7 @@ ohos_unittest("tar_file_test") { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", + "hitrace:hitrace_meter", "ipc:ipc_core", "napi:ace_napi", "samgr:samgr_proxy", @@ -124,6 +125,7 @@ ohos_unittest("untar_file_test") { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", + "hitrace:hitrace_meter", "ipc:ipc_core", "napi:ace_napi", "samgr:samgr_proxy", diff --git a/tests/unittests/backup_sa/module_ipc/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index 5f22a9ed130c979e8cdb9eef770707ec1a4c28f0..e320f95e7aef27a9c89662dda858173b56396f75 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -100,6 +100,7 @@ ohos_unittest("backup_service_test") { "ability_runtime:ability_manager", "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", @@ -155,6 +156,7 @@ ohos_unittest("backup_service_session_test") { "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", @@ -250,6 +252,7 @@ ohos_unittest("backup_restore_deps_manager_test") { "ability_runtime:ability_manager", "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/utils/BUILD.gn b/utils/BUILD.gn index ff90af9810f2c75ce15b6e62199b1227553a9fd4..2547992219f6cf04466f5acc07192c09ebd266ec 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -101,6 +101,7 @@ ohos_shared_library("backup_utils") { "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", "hilog:libhilog", + "hitrace:hitrace_meter", "init:libbegetutil", ]