长短时任务统计,新增js调用栈与sysevent事件

Signed-off-by: fangz <fangz_zz@163.com>
This commit is contained in:
fangz 2023-04-06 20:01:00 +08:00
parent 961efc596b
commit 9f7d501212
13 changed files with 109 additions and 1 deletions

View File

@ -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) ||

View File

@ -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",

45
hisysevent.yaml Normal file
View File

@ -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}

View File

@ -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"

View File

@ -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");

View File

@ -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);

View File

@ -18,6 +18,9 @@
#include <uv.h>
#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<CallbackInstance> callback = nullptr;
std::u16string reason;
if (ParseParameters(env, info, reason, callback, isThrow) == nullptr) {

View File

@ -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",

View File

@ -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_ptr<Continuo
BGTASK_LOGD("continuous task start callback trigger");
(*iter)->OnContinuousTaskStart(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;
}
}

View File

@ -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",

View File

@ -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",

View File

@ -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<KeyInfo>& 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<KeyInfo>& 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);
}
}

View File

@ -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",