文件备份打点

issue:https://gitee.com/openharmony/filemanagement_app_file_service/issues/I9IEA7

Signed-off-by: liuxiaowei42 <liuxiaowei42@huawei.com>
This commit is contained in:
liuxiaowei42 2024-04-21 10:41:12 +08:00
parent 98d6ddc3c0
commit 60e2e9e567
7 changed files with 93 additions and 1 deletions

View File

@ -33,6 +33,7 @@
"file_api",
"hitrace",
"hilog",
"hisysevent",
"ipc",
"init",
"napi",
@ -40,7 +41,6 @@
"samgr",
"storage_service",
"sandbox_manager"
],
"third_party": [
"bounds_checking_function",
@ -55,6 +55,9 @@
],
"rom": "1024KB",
"ram": "1024KB",
"hisysevent_config": [
"//foundation/filemanagement/app_file_service/hisysevent.yaml"
],
"build": {
"group_type": {
"base_group": [],

21
hisysevent.yaml Normal file
View File

@ -0,0 +1,21 @@
# 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.
domain: FILEMANAGEMENT
FILE_BACKUP_EVENTS:
__BASE: {type: BEHAVIOR, level: MINOR, tag: BACKUP, desc: file backup time delay}
PROC_NAME: {type: STRING, desc: proc name}
BUNDLENAME: {type: STRING, desc: app bundlename}
PID: {type: INT32, desc: process id}
TIME: {type: STRING, desc: trigger time}

View File

@ -69,6 +69,7 @@ ohos_shared_library("backup_sa") {
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",

View File

@ -22,6 +22,7 @@
#include "module_ipc/service.h"
#include <algorithm>
#include <chrono>
#include <cerrno>
#include <cstddef>
#include <cstdint>
@ -29,6 +30,7 @@
#include <regex>
#include <fcntl.h>
#include <iomanip>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/vfs.h>
@ -47,6 +49,7 @@
#include "b_resources/b_constants.h"
#include "bundle_mgr_client.h"
#include "filemgmt_libhilog.h"
#include "hisysevent.h"
#include "ipc_skeleton.h"
#include "module_app_gallery/app_gallery_dispose_proxy.h"
#include "module_external/bms_adapter.h"
@ -65,7 +68,10 @@ REGISTER_SYSTEM_ABILITY_BY_ID(Service, FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, fals
namespace {
constexpr int32_t DEBUG_ID = 100;
constexpr int32_t INDEX = 3;
constexpr int32_t MS_1000 = 1000;
const static string COMMON_EVENT_TYPE = "broadcast";
const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS";
const int32_t CONNECT_WAIT_TIME_S = 15;
} // namespace
@ -570,6 +576,21 @@ ErrCode Service::AppDone(ErrCode errCode)
HILOGI("will notify clone data, scenario is: %{public}d", scenario);
if (scenario == IServiceReverse::Scenario::BACKUP) {
session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, callerName);
auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(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);
HiSysEventWrite(
OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT,
FILE_BACKUP_EVENTS,
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
"PROC_NAME", "ohos.appfileservice",
"BUNDLENAME", callerName,
"PID", getpid(),
"TIME", strTime.str()
);
} else if (scenario == IServiceReverse::Scenario::RESTORE) {
session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, callerName);
}

View File

@ -17,10 +17,12 @@
#include <algorithm>
#include <cerrno>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <fcntl.h>
#include <iomanip>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/vfs.h>
@ -37,6 +39,7 @@
#include "b_process/b_multiuser.h"
#include "b_resources/b_constants.h"
#include "filemgmt_libhilog.h"
#include "hisysevent.h"
#include "ipc_skeleton.h"
#include "module_external/bms_adapter.h"
#include "module_ipc/svc_backup_connection.h"
@ -47,9 +50,12 @@
namespace OHOS::FileManagement::Backup {
using namespace std;
const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS";
namespace {
constexpr int32_t DEBUG_ID = 100;
constexpr int32_t INDEX = 3;
constexpr int32_t MS_1000 = 1000;
} // namespace
static inline int32_t GetUserIdDefault()
@ -271,6 +277,21 @@ ErrCode Service::AppIncrementalDone(ErrCode errCode)
HILOGI("will notify clone data, scenario is: %{public}d", scenario);
if (scenario == IServiceReverse::Scenario::BACKUP) {
session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, callerName);
auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(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);
HiSysEventWrite(
OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT,
FILE_BACKUP_EVENTS,
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
"PROC_NAME", "ohos.appfileservice",
"BUNDLENAME", callerName,
"PID", getpid(),
"TIME", strTime.str()
);
} else if (scenario == IServiceReverse::Scenario::RESTORE) {
session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, callerName);
}

View File

@ -15,13 +15,20 @@
#include "module_ipc/svc_backup_connection.h"
#include <chrono>
#include <iomanip>
#include "ability_manager_client.h"
#include "filemgmt_libhilog.h"
#include "hisysevent.h"
#include "module_ipc/svc_extension_proxy.h"
#include "module_ipc/svc_session_manager.h"
namespace OHOS::FileManagement::Backup {
constexpr int WAIT_TIME = 3;
constexpr int32_t INDEX = 3;
constexpr int32_t MS_1000 = 1000;
const std::string FILE_BACKUP_EVENTS = "FILE_BACKUP_EVENTS";
using namespace std;
void SvcBackupConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
@ -40,6 +47,21 @@ void SvcBackupConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &el
}
isConnected_.store(true);
string bundleName = element.GetBundleName();
auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(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);
HiSysEventWrite(
OHOS::HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT,
FILE_BACKUP_EVENTS,
OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
"PROC_NAME", "ohos.appfileservice",
"BUNDLENAME", bundleName,
"PID", getpid(),
"TIME", strTime.str()
);
callConnDone_(move(bundleName));
HILOGI("called end");
}

View File

@ -49,6 +49,7 @@ ohos_unittest("module_ipc_test") {
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hilog:libhilog",
"hisysevent:libhisysevent",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
@ -108,6 +109,7 @@ ohos_unittest("backup_service_test") {
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
@ -281,6 +283,7 @@ ohos_unittest("backup_restore_deps_manager_test") {
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",