From 9f7d501212cff1c147cfd36a5cc5e3d52abe4498 Mon Sep 17 00:00:00 2001 From: fangz Date: Thu, 6 Apr 2023 20:01:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=95=BF=E7=9F=AD=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=EF=BC=8C=E6=96=B0=E5=A2=9Ejs=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=A0=88=E4=B8=8Esysevent=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangz --- bgtaskmgr.gni | 1 + bundle.json | 6 ++- hisysevent.yaml | 45 +++++++++++++++++++ interfaces/kits/BUILD.gn | 14 ++++++ .../src/bg_continuous_task_napi_module.cpp | 9 ++++ .../kits/napi/src/cancel_suspend_delay.cpp | 6 +++ .../kits/napi/src/request_suspend_delay.cpp | 6 +++ services/BUILD.gn | 1 + .../src/bg_continuous_task_mgr.cpp | 9 ++++ services/test/unittest/BUILD.gn | 4 ++ .../BUILD.gn | 1 + .../transient_task/src/decision_maker.cpp | 7 +++ test/systemtest/BUILD.gn | 1 + 13 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 hisysevent.yaml diff --git a/bgtaskmgr.gni b/bgtaskmgr.gni index 41d9beb..21a9c28 100644 --- a/bgtaskmgr.gni +++ b/bgtaskmgr.gni @@ -23,6 +23,7 @@ bgtaskmgr_services_path = "${bgtaskmgr_root_path}/services" declare_args() { background_task_mgr_graphics = true + background_task_mgr_jsstack = true } if (!defined(global_parts_info) || diff --git a/bundle.json b/bundle.json index 84b0c62..fa72e96 100644 --- a/bundle.json +++ b/bundle.json @@ -18,7 +18,8 @@ "SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply" ], "features": [ - "background_task_mgr_graphics" + "background_task_mgr_graphics", + "background_task_mgr_jsstack" ], "adapted_system_type": [ "mini", @@ -27,6 +28,9 @@ ], "rom": "2048KB", "ram": "10240KB", + "hisysevent": [ + "//foundation/resourceschedule/background_task_mgr/hisysevent.yaml" + ], "deps": { "components": [ "ability_base", diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 0000000..94f8783 --- /dev/null +++ b/hisysevent.yaml @@ -0,0 +1,45 @@ +# Copyright (c) 2022 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: BACKGROUND_TASK + +TRANSIENT_TASK_APPLY: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: apply transient task} + APP_UID: {type: INT32, desc: package uid} + APP_PID: {type: INT32, desc: thread pid} + APP_NAME: {type: STRING, desc: package name} + TASKID: {type: STRING, desc: task id} + VALUE: {type: INT32, desc: second of delay time} + +TRANSIENT_TASK_CANCEL: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: cancel transient task} + APP_UID: {type: INT32, desc: package uid} + APP_PID: {type: INT32, desc: thread pid} + APP_NAME: {type: STRING, desc: package name} + TASKID: {type: STRING, desc: task id} + +CONTINUOUS_TASK_APPLY: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: apply continuous task} + APP_UID: {type: INT32, desc: package uid} + APP_PID: {type: INT32, desc: thread pid} + APP_NAME: {type: STRING, desc: package name} + ABILITY: {type: STRING, desc: package ability} + BGMODE: {type: INT32, desc: task background mode} + +CONTINUOUS_TASK_CANCEL: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: cancel continuous task} + APP_UID: {type: INT32, desc: package uid} + APP_PID: {type: INT32, desc: thread pid} + APP_NAME: {type: STRING, desc: package name} + ABILITY: {type: STRING, desc: package ability} + BGMODE: {type: INT32, desc: task background mode} diff --git a/interfaces/kits/BUILD.gn b/interfaces/kits/BUILD.gn index 80618e1..3a715c3 100644 --- a/interfaces/kits/BUILD.gn +++ b/interfaces/kits/BUILD.gn @@ -48,6 +48,13 @@ ohos_shared_library("backgroundtaskmanager") { "napi:ace_napi", "samgr:samgr_proxy", ] + + defines = [] + if (background_task_mgr_jsstack) { + defines += [ "SUPPORT_JSSTACK" ] + external_deps += [ "hiview:libxpower_event_js" ] + } + relative_install_dir = "module" subsystem_name = "resourceschedule" part_name = "background_task_mgr" @@ -81,6 +88,13 @@ ohos_shared_library("backgroundtaskmanager_napi") { "napi:ace_napi", "samgr:samgr_proxy", ] + + defines = [] + if (background_task_mgr_jsstack) { + defines += [ "SUPPORT_JSSTACK" ] + external_deps += [ "hiview:libxpower_event_js" ] + } + relative_install_dir = "module/resourceschedule" subsystem_name = "resourceschedule" part_name = "background_task_mgr" diff --git a/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp b/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp index 238f76a..54cfb07 100644 --- a/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp +++ b/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp @@ -20,6 +20,9 @@ #include "napi_base_context.h" #include "system_ability_definition.h" #include "want_agent.h" +#ifdef SUPPORT_JSSTACK +#include "xpower_event_js.h" +#endif #include "background_mode.h" #include "background_task_mgr_helper.h" @@ -334,6 +337,9 @@ napi_value GetWantAgent(const napi_env &env, const napi_value &value, napi_value StartBackgroundRunning(napi_env env, napi_callback_info info, bool isThrow) { +#ifdef SUPPORT_JSSTACK + HiviewDFX::ReportXPowerJsStackSysEvent(env, "CONTINUOUS_TASK_APPLY"); +#endif AsyncCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncCallbackInfo(env); if (asyncCallbackInfo == nullptr) { BGTASK_LOGE("asyncCallbackInfo == nullpter"); @@ -497,6 +503,9 @@ napi_value StopBackgroundRunningPromise(napi_env env, AsyncCallbackInfo *asyncCa napi_value StopBackgroundRunning(napi_env env, napi_callback_info info, bool isThrow) { +#ifdef SUPPORT_JSSTACK + HiviewDFX::ReportXPowerJsStackSysEvent(env, "CONTINUOUS_TASK_CANCEL"); +#endif AsyncCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncCallbackInfo(env); if (asyncCallbackInfo == nullptr) { BGTASK_LOGE("asyncCallbackInfo is nullpter"); diff --git a/interfaces/kits/napi/src/cancel_suspend_delay.cpp b/interfaces/kits/napi/src/cancel_suspend_delay.cpp index 3d81f0b..6fcc359 100644 --- a/interfaces/kits/napi/src/cancel_suspend_delay.cpp +++ b/interfaces/kits/napi/src/cancel_suspend_delay.cpp @@ -16,6 +16,9 @@ #include "cancel_suspend_delay.h" #include "singleton.h" +#ifdef SUPPORT_JSSTACK +#include "xpower_event_js.h" +#endif #include "background_task_manager.h" #include "request_suspend_delay.h" @@ -51,6 +54,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value CancelSuspendDelay(napi_env env, napi_callback_info info, bool isThrow) { +#ifdef SUPPORT_JSSTACK + HiviewDFX::ReportXPowerJsStackSysEvent(env, "TRANSIENT_TASK_CANCEL"); +#endif int32_t requestId; if (ParseParameters(env, info, requestId, isThrow) == nullptr) { return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/src/request_suspend_delay.cpp b/interfaces/kits/napi/src/request_suspend_delay.cpp index 0110bd7..4ffea6f 100644 --- a/interfaces/kits/napi/src/request_suspend_delay.cpp +++ b/interfaces/kits/napi/src/request_suspend_delay.cpp @@ -18,6 +18,9 @@ #include #include "singleton.h" +#ifdef SUPPORT_JSSTACK +#include "xpower_event_js.h" +#endif #include "background_task_manager.h" #include "transient_task_log.h" @@ -237,6 +240,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value RequestSuspendDelay(napi_env env, napi_callback_info info, bool isThrow) { +#ifdef SUPPORT_JSSTACK + HiviewDFX::ReportXPowerJsStackSysEvent(env, "TRANSIENT_TASK_APPLY"); +#endif std::shared_ptr callback = nullptr; std::u16string reason; if (ParseParameters(env, info, reason, callback, isThrow) == nullptr) { diff --git a/services/BUILD.gn b/services/BUILD.gn index 6e53632..53d21f0 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -90,6 +90,7 @@ ohos_shared_library("bgtaskmgr_service") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "init:libbegetutil", diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index 9e38a69..4e5bc3d 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -25,6 +25,7 @@ #include "errors.h" #include "hitrace_meter.h" #include "if_system_ability_manager.h" +#include "hisysevent.h" #include "iremote_object.h" #include "iservice_registry.h" #ifdef HAS_OS_ACCOUNT_PART @@ -1058,12 +1059,20 @@ void BgContinuousTaskMgr::OnContinuousTaskChanged(const std::shared_ptrOnContinuousTaskStart(continuousTaskCallbackInfo); } + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::BACKGROUND_TASK, "CONTINUOUS_TASK_APPLY", + HiviewDFX::HiSysEvent::EventType::STATISTIC, "APP_UID", continuousTaskInfo->GetUid(), + "APP_PID", continuousTaskInfo->GetPid(), "APP_NAME", continuousTaskInfo->GetBundleName(), + "ABILITY", continuousTaskInfo->GetAbilityName(), "BGMODE", continuousTaskInfo->GetBgModeId()); break; case ContinuousTaskEventTriggerType::TASK_CANCEL: for (auto iter = bgTaskSubscribers_.begin(); iter != bgTaskSubscribers_.end(); ++iter) { BGTASK_LOGD("continuous task stop callback trigger"); (*iter)->OnContinuousTaskStop(continuousTaskCallbackInfo); } + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::BACKGROUND_TASK, "CONTINUOUS_TASK_CANCEL", + HiviewDFX::HiSysEvent::EventType::STATISTIC, "APP_UID", continuousTaskInfo->GetUid(), + "APP_PID", continuousTaskInfo->GetPid(), "APP_NAME", continuousTaskInfo->GetBundleName(), + "ABILITY", continuousTaskInfo->GetAbilityName(), "BGMODE", continuousTaskInfo->GetBgModeId()); break; } } diff --git a/services/test/unittest/BUILD.gn b/services/test/unittest/BUILD.gn index e580dbb..59de53d 100644 --- a/services/test/unittest/BUILD.gn +++ b/services/test/unittest/BUILD.gn @@ -57,6 +57,7 @@ ohos_unittest("bgtask_unit_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_single", "multimedia_image_framework:image_native", @@ -115,6 +116,7 @@ ohos_unittest("efficiency_mgr_unit_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_single", "multimedia_image_framework:image_native", @@ -172,6 +174,7 @@ ohos_unittest("bgtask_manager_unit_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_single", "multimedia_image_framework:image_native", @@ -232,6 +235,7 @@ ohos_unittest("bgtask_misc_unit_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_single", "multimedia_image_framework:image_native", diff --git a/services/test/unittest/bgtask_manager_abnormal_unit_test/BUILD.gn b/services/test/unittest/bgtask_manager_abnormal_unit_test/BUILD.gn index a4f66dd..6f45535 100644 --- a/services/test/unittest/bgtask_manager_abnormal_unit_test/BUILD.gn +++ b/services/test/unittest/bgtask_manager_abnormal_unit_test/BUILD.gn @@ -56,6 +56,7 @@ ohos_unittest("bgtask_manager_abnormal_unit_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_single", "multimedia_image_framework:image_native", diff --git a/services/transient_task/src/decision_maker.cpp b/services/transient_task/src/decision_maker.cpp index 416a100..5f3e48f 100644 --- a/services/transient_task/src/decision_maker.cpp +++ b/services/transient_task/src/decision_maker.cpp @@ -23,6 +23,7 @@ #include "time_provider.h" #include "iservice_registry.h" #include "system_ability_definition.h" +#include "hisysevent.h" using namespace std; @@ -181,6 +182,9 @@ ErrCode DecisionMaker::Decide(const std::shared_ptr& key, const std::sh if (CanStartAccountingLocked(pkgInfo)) { pkgInfo->StartAccounting(delayInfo->GetRequestId()); } + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::BACKGROUND_TASK, "TRANSIENT_TASK_APPLY", + HiviewDFX::HiSysEvent::EventType::STATISTIC, "APP_UID", key->GetUid(), "APP_PID", key->GetPid(), + "APP_NAME", key->GetPkg(), "TASKID", delayInfo->GetRequestId(), "VALUE", delayInfo->GetActualDelayTime()); return ERR_OK; } @@ -206,6 +210,9 @@ void DecisionMaker::RemoveRequest(const std::shared_ptr& key, const int ->HandleTransientTaskSuscriberTask(info, TransientTaskEventType::APP_TASK_END); } BGTASK_LOGD("Remove requestId: %{public}d", requestId); + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::BACKGROUND_TASK, "TRANSIENT_TASK_CANCEL", + HiviewDFX::HiSysEvent::EventType::STATISTIC, "APP_UID", key->GetUid(), "APP_PID", key->GetPid(), + "APP_NAME", key->GetPkg(), "TASKID", requestId); } } diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn index 71db141..fb3131c 100644 --- a/test/systemtest/BUILD.gn +++ b/test/systemtest/BUILD.gn @@ -55,6 +55,7 @@ ohos_systemtest("BgtaskDumpTest") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "init:libbegetutil", "ipc:ipc_single",