diff --git a/PerformanceAnalysisKit/HiAppEvent/EventSub/README_zh.md b/PerformanceAnalysisKit/HiAppEvent/EventSub/README_zh.md
index 9b83c21fa497145224ddb335660c4bcafd5bdc29..bd7013fb030a6bccd077b4711fdb875ed27b6d6c 100644
--- a/PerformanceAnalysisKit/HiAppEvent/EventSub/README_zh.md
+++ b/PerformanceAnalysisKit/HiAppEvent/EventSub/README_zh.md
@@ -4,7 +4,7 @@
本示例主要展示用HiAppEvent如何实现事件订阅(AppEvent),并列举了订阅如下系统事件的例子:
-崩溃事件(CrashEvent)、系统卡死事件(FreezeEvent)、系统资源泄漏事件(PssLeakEvent)、系统踩内存事件(ASANEvent)以及主线程超时事件
+崩溃事件(CrashEvent)、系统卡死事件(FreezeEvent)、系统资源泄漏事件(PssLeakEvent)、系统地址越界事件(ASANEvent)以及主线程超时事件
(TimeOutEvent)。
@@ -22,23 +22,29 @@
- [订阅卡死事件(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/dfx/hiappevent-watcher-freeze-events-ndk.md)
-- [订阅资源泄漏事件(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/dfx/hiappevent-watcher-resourceleak-events-arkts.md)
+- [订阅资源泄漏事件(ArkTS)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hiappevent-watcher-resourceleak-events-arkts.md)
-- [订阅资源泄漏事件(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/dfx/hiappevent-watcher-resourceleak-events-ndk.md)
+- [订阅资源泄漏事件(C/C++)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hiappevent-watcher-resourceleak-events-ndk.md)
-- [订阅踩内存事件(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/dfx/hiappevent-watcher-address-sanitizer-events-arkts.md)
+- [订阅地址越界事件(ArkTS)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hiappevent-watcher-address-sanitizer-events-arkts.md)
-- [订阅踩内存事件(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/dfx/hiappevent-watcher-address-sanitizer-events-ndk.md)
+- [订阅地址越界事件(C/C++)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hiappevent-watcher-address-sanitizer-events-ndk.md)
- [订阅主线程超时事件(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/dfx/hiappevent-watcher-mainthreadjank-events-arkts.md)
- [订阅主线程超时事件(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/dfx/hiappevent-watcher-mainthreadjank-events-ndk.md)
+- [订阅任务执行超时事件(C/C++)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hiappevent-watcher-apphicollie-events-ndk.md)
+
+- [订阅应用终止事件(ArkTS)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hiappevent-watcher-app-killed-events-arkts.md)
+
+- [订阅应用终止事件(C/C++)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/hiappevent-watcher-app-killed-events-ndk.md)
+
### 效果预览
| 主页 |
| :----------------------------------------------------------: |
-|
|
+|
|
#### 使用说明
@@ -290,7 +296,7 @@ HiAppEvent eventInfo.params.test_data=100
1.先在设备“开发者选项”中打开“系统资源泄漏日志”,并重启设备;
-2.在应用侧主界面,点击"pssLeak ArkTS&C++"按钮触发资源泄露事件,等待15~30分钟,会上报应用内存泄漏事件;
+2.在应用侧主界面,点击"pss leak"按钮触发资源泄露事件,等待15~30分钟,会上报应用内存泄漏事件;
3.在DevEco Studio侧下方导航栏,切换到"Log"窗口,日志过滤选择"All log of selected app",搜索内容设置为"HiAppevent"。此时窗口仅显示符合条件的日志,打印日志结果为:
@@ -337,11 +343,11 @@ HiAppEvent eventInfo={"domain":"OS","name":"RESOURCE_OVERLIMIT","eventType":1,"p
3.C++实现了onReceive和onTrigger两种观察者,ArkTS实现了onReceive观察者。
-##### 7.订阅踩内存事件(ArkTS&C++)
+##### 7.订阅地址越界事件(ArkTS&C++)
1.点击DevEco Studio界面中的“entry”,点击“Edit Configurations”,点击“Diagnostics”,勾选“Address Sanitizer”,保存设置。
-2.在应用侧主界面,点击"appAsanEvent ArkTS&C++"按钮触发踩内存事件,应用退出后重启应用;
+2.在应用侧主界面,点击"address-sanitizer"按钮触发地址越界事件,应用退出后重启应用;
3.在DevEco Studio侧下方导航栏,切换到"Log"窗口,日志过滤选择"All log of selected app",搜索内容设置为"HiAppevent"。此时窗口仅显示符合条件的日志,打印日志结果为:
@@ -444,6 +450,40 @@ HiAppEvent eventInfo.params.log_over_limit=0
3.C++实现了onReceive观察者,ArkTS实现了onReceive观察者。
+##### 9.订阅任务执行超时事件(C/C++)
+
+本示例主要展示了订阅任务执行超时事件的功能,包括构造任务执行超时事件及其订阅处理。OH_HiAppEvent_AddWatcher接口用于添加对该超时事件的订阅。
+
+1.在应用侧主界面,点击“TestHiCollieTimerNdk”按钮;
+2.在DevEco Studio侧下方导航栏,切换到"Log"窗口,日志过滤选择"No filters",搜索内容设置为"testTag"。此时窗口仅显示符合条件的日志,打印日志示例结果为:
+
+```text
+HiAppEvent eventInfo.domain=OS
+HiAppEvent eventInfo.name=APP_HICOLLIE
+HiAppEvent eventInfo.eventType=1
+HiAppEvent eventInfo.params.time=xx
+HiAppEvent eventInfo.params.foreground=1
+HiAppEvent eventInfo.params.bundle_version=1.0.0
+HiAppEvent eventInfo.params.process_name=xx
+HiAppEvent eventInfo.params.pid=xx
+HiAppEvent eventInfo.params.uid=xx
+HiAppEvent eventInfo.params.uuid=xx
+HiAppEvent eventInfo.params.exception={"message":"","name":"APP_HICOLLIE"}
+HiAppEvent eventInfo.params.hilog.size=xx
+HiAppEvent eventInfo.params.peer_binder.size=xx
+HiAppEvent eventInfo.params.memory={"pss":0,"rss":xx,"sys_avail_mem":xx,"sys_free_mem":xx,"sys_total_mem":xx,"vss":xx}
+HiAppEvent eventInfo.params.external_log=["/data/storage/el2/log/hiappevent/APP_HICOLLIE_xx_xx.log"]
+HiAppEvent eventInfo.params.log_over_limit=xx
+```
+
+注意:
+
+1.本示例适配API19及以上版本SDK。
+
+2.要确认日志输出中的eventInfo.name为APP_HICOLLIE。
+
+3.C++实现了onReceive和onTrigger两种观察者。
+
### 工程目录
```text
@@ -484,8 +524,8 @@ entry/src/main
### 约束与限制
-1. 本示例仅支持标准系统上运行,支持设备:华为手机;
-2. 本示例已适配API14版本SDK,版本号:5.0.2.58;
+1. 本示例仅支持标准系统上运行,支持设备:RK3568;
+2. 本示例已适配API14版本SDK,版本号:5.0.2.58,镜像版本号:OpenHarmony5.0.2.58;
3. 本示例需要使用DevEco Studio(5.0.3.910)及以上版本才可编译运行。
### 下载
diff --git a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/CMakeLists.txt b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/CMakeLists.txt
index fa2f9febd17f978b15af959a2b18032d46f06a46..44af7a4b3580327db4a8af0b7d2ae87fb7cf7d08 100644
--- a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/CMakeLists.txt
+++ b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/CMakeLists.txt
@@ -13,5 +13,5 @@ include_directories(${NATIVERENDER_ROOT_PATH}
# 新增jsoncpp.cpp(解析订阅事件中的json字符串)源文件
add_library(entry SHARED napi_init.cpp jsoncpp.cpp)
-# 新增动态库依赖libhiappevent_ndk.z.so和libhilog_ndk.z.so(日志输出)
-target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so libhiappevent_ndk.z.so)
+# 新增动态库依赖libhiappevent_ndk.z.so和libhilog_ndk.z.so(日志输出),libohhicollie.so(HiCollie对外检测接口)
+target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so libhiappevent_ndk.z.so libohhicollie.so)
\ No newline at end of file
diff --git a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/napi_init.cpp b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/napi_init.cpp
index e525f468ff2a39836e302a46debc2a2db111de58..859eec7d53a4730789f08306f677f2243eb1d7af 100644
--- a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/napi_init.cpp
+++ b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/napi_init.cpp
@@ -24,6 +24,11 @@
#define LOG_TAG "testTag"
// [End EventSub_napi_Header]
+// [Start Hicollie_Set_Timer_h]
+#include
+#include "hicollie/hicollie.h"
+// [End Hicollie_Set_Timer_h]
+
// 定义一变量,用来缓存创建的观察者的指针。
// [Start EventSub_onReceive_ptr]
static HiAppEvent_Watcher *eventWatcherR;
@@ -32,6 +37,15 @@ static HiAppEvent_Watcher *eventWatcherR;
static HiAppEvent_Watcher *eventWatcherT;
// [End EventSub_onTrigger_ptr]
+// [Start App_Hicollie_Watcher_R_ptr]
+// 定义一变量,用来缓存创建的观察者的指针。
+static HiAppEvent_Watcher *appHicollieWatcherR;
+// [End App_Hicollie_Watcher_R_ptr]
+// [Start App_Hicollie_Watcher_T_ptr]
+// 定义一变量,用来缓存创建的观察者的指针。
+static HiAppEvent_Watcher *appHicollieWatcherT;
+// [End App_Hicollie_Watcher_T_ptr]
+
// [Start CrashEvent_OnReceive]
static void OnReceiveCrashEvent(const struct HiAppEvent_AppEventGroup *appEventGroups, int i, int j)
{
@@ -142,14 +156,20 @@ static void OnReceiveFreezeEvent(const struct HiAppEvent_AppEventGroup *appEvent
}
// [End FreezeEvent_OnReceive]
// [Start PssLeakEvent_OnReceive]
-static void OnReceivePssLeakEvent(const struct HiAppEvent_AppEventGroup *appEventGroups, int i, int j)
+//定义一变量,用来缓存创建的观察者的指针。
+static HiAppEvent_Watcher *resouceLeakWatcherR;
+
+static void HandleLeakEventInfo(const struct HiAppEvent_AppEventInfo &appEventInfos)
{
- if (strcmp(appEventGroups[i].appEventInfos[j].domain, DOMAIN_OS) == 0 &&
- strcmp(appEventGroups[i].appEventInfos[j].name, EVENT_RESOURCE_OVERLIMIT) == 0) {
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.domain=%{public}s", appEventInfos.domain);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.name=%{public}s", appEventInfos.name);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.eventType=%{public}d", appEventInfos.type);
+ if (strcmp(appEventInfos.domain, DOMAIN_OS) == 0 &&
+ strcmp(appEventInfos.name, EVENT_RESOURCE_OVERLIMIT) == 0) {
Json::Value params;
Json::Reader reader(Json::Features::strictMode());
Json::FastWriter writer;
- if (reader.parse(appEventGroups[i].appEventInfos[j].params, params)) {
+ if (reader.parse(appEventInfos.params, params)) {
auto time = params["time"].asInt64();
auto pid = params["pid"].asInt();
auto uid = params["uid"].asInt();
@@ -158,58 +178,166 @@ static void OnReceivePssLeakEvent(const struct HiAppEvent_AppEventGroup *appEven
auto bundleVersion = params["bundle_version"].asString();
auto memory = writer.write(params["memory"]);
auto externalLog = writer.write(params["external_log"]);
- std::string logOverLimit = params["log_over_limit"].asBool() ? "true" : "false";
+ std::string logOverLimit = params["log_over_limit"].asBool() ? "true":"false";
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.pid=%{public}d", pid);
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uid=%{public}d", uid);
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.resource_type=%{public}s",
- resourceType.c_str());
+ resourceType.c_str());
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_name=%{public}s",
- bundleName.c_str());
+ bundleName.c_str());
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_version=%{public}s",
- bundleVersion.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.memory=%{public}s", memory.c_str());
+ bundleVersion.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.memory=%{public}s",
+ memory.c_str());
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.external_log=%{public}s",
- externalLog.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}d",
- logOverLimit.c_str());
+ externalLog.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}s",
+ logOverLimit.c_str());
}
}
}
+
+static void OnReceiveLeakEvent(const char *domain, const struct HiAppEvent_AppEventGroup *appEventGroups,
+ uint32_t groupLen)
+{
+ for (int i = 0; i < groupLen; ++i) {
+ for (int j = 0; j < appEventGroups[i].infoLen; ++j) {
+ HandleLeakEventInfo(appEventGroups[i].appEventInfos[j]);
+ }
+ }
+}
+
+static napi_value RegisterLeakReceiveWatcher(napi_env env, napi_callback_info info)
+{
+ // 开发者自定义观察者名称,系统根据不同的名称来识别不同的观察者。
+ resouceLeakWatcherR = OH_HiAppEvent_CreateWatcher("onLeakReceiveWatcher");
+ // 设置订阅的事件为EVENT_RESOURCE_OVERLIMIT。
+ const char *names[] = {EVENT_RESOURCE_OVERLIMIT};
+ // 开发者订阅感兴趣的事件,此处订阅了系统事件。
+ OH_HiAppEvent_SetAppEventFilter(resouceLeakWatcherR, DOMAIN_OS, 0, names, 1);
+ // 开发者设置已实现的回调函数,观察者接收到事件后回立即触发OnReceive回调。
+ OH_HiAppEvent_SetWatcherOnReceive(resouceLeakWatcherR, OnReceiveLeakEvent);
+ // 使观察者开始监听订阅的事件。
+ OH_HiAppEvent_AddWatcher(resouceLeakWatcherR);
+ return {};
+}
// [End PssLeakEvent_OnReceive]
+// [Start AppKillEvent_OnReceive]
+// 定义一变量,用来缓存创建的观察者的指针。
+static HiAppEvent_Watcher *appKillWatcherR;
+
+static void HandleAppKillEventInfo(const struct HiAppEvent_AppEventInfo &appEventInfos)
+{
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.domain=%{public}s", appEventInfos.domain);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.name=%{public}s", appEventInfos.name);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.eventType=%{public}d", appEventInfos.type);
+ if (strcmp(appEventInfos.domain, DOMAIN_OS) == 0 &&
+ strcmp(appEventInfos.name, EVENT_APP_KILLED) == 0) {
+ Json::Value params;
+ Json::Reader reader(Json::Features::strictMode());
+ Json::FastWriter writer;
+ if (reader.parse(appEventInfos.params, params)) {
+ auto time = params["time"].asInt64();
+ auto reason = params["reason"].asString();
+ auto foreground = params["foreground"].asString();
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.reason=%{public}s", reason.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.foreground=%{public}s", foreground.c_str());
+ }
+ }
+}
+
+static void OnReceiveAppKillEvent(const char *domain, const struct HiAppEvent_AppEventGroup *appEventGroups,
+ uint32_t groupLen)
+{
+ for (int i = 0; i < groupLen; ++i) {
+ for (int j = 0; j < appEventGroups[i].infoLen; ++j) {
+ HandleAppKillEventInfo(appEventGroups[i].appEventInfos[j]);
+ }
+ }
+}
+
+static napi_value RegisterAppKillReceiveWatcher(napi_env env, napi_callback_info info)
+{
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent RegisterWatcher");
+ // 开发者自定义观察者名称,系统根据不同的名称来识别不同的观察者。
+ appKillWatcherR = OH_HiAppEvent_CreateWatcher("onAppKillReceiverWatcher");
+ // 设置订阅的事件为EVENT_APP_KILLED。
+ const char *names[] = {EVENT_APP_KILLED};
+ // 开发者订阅感兴趣的事件,此处订阅了系统事件。
+ OH_HiAppEvent_SetAppEventFilter(appKillWatcherR, DOMAIN_OS, 0, names, 1);
+ // 开发者设置已实现的回调函数,观察者接收到事件后回立即触发OnReceive回调。
+ OH_HiAppEvent_SetWatcherOnReceive(appKillWatcherR, OnReceiveAppKillEvent);
+ // 使观察者开始监听订阅的事件。
+ OH_HiAppEvent_AddWatcher(appKillWatcherR);
+ return {};
+}
+// [End AppKillEvent_OnReceive]
// [Start AsanEvent_OnReceive]
-static void OnReceiveAsanEvent(const struct HiAppEvent_AppEventGroup *appEventGroups, int i, int j)
+//定义一变量,用来缓存创建的观察者的指针。
+static HiAppEvent_Watcher *sanitizerWatcherR;
+
+static void HandleSanitizerEventInfo(const struct HiAppEvent_AppEventInfo &appEventInfos)
{
- if (strcmp(appEventGroups[i].appEventInfos[j].domain, DOMAIN_OS) == 0 &&
- strcmp(appEventGroups[i].appEventInfos[j].name, EVENT_ADDRESS_SANITIZER) == 0) {
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.domain=%{public}s", appEventInfos.domain);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.name=%{public}s", appEventInfos.name);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.eventType=%{public}d", appEventInfos.type);
+ if (strcmp(appEventInfos.domain, DOMAIN_OS) == 0 &&
+ strcmp(appEventInfos.name, EVENT_ADDRESS_SANITIZER) == 0) {
Json::Value params;
Json::Reader reader(Json::Features::strictMode());
Json::FastWriter writer;
- if (reader.parse(appEventGroups[i].appEventInfos[j].params, params)) {
+ if (reader.parse(appEventInfos.params, params)) {
auto time = params["time"].asInt64();
auto bundleVersion = params["bundle_version"].asString();
auto bundleName = params["bundle_name"].asString();
auto pid = params["pid"].asInt();
auto uid = params["uid"].asInt();
auto type = params["type"].asString();
- auto boolFlag = params["log_over_limit"].asBool();
std::string logOverLimit = params["log_over_limit"].asBool() ? "true" : "false";
auto externalLog = writer.write(params["external_log"]);
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_version=%{public}s",
- bundleVersion.c_str());
+ bundleVersion.c_str());
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_name=%{public}s",
- bundleName.c_str());
+ bundleName.c_str());
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.pid=%{public}d", pid);
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uid=%{public}d", uid);
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.type=%{public}s", type.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.type=%{public}s",
+ type.c_str());
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.external_log=%{public}s",
- externalLog.c_str());
+ externalLog.c_str());
OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}s",
- logOverLimit.c_str());
+ logOverLimit.c_str());
}
}
}
+
+static void OnReceiveSanitizerEvent(const char *domain, const struct HiAppEvent_AppEventGroup *appEventGroups,
+ uint32_t groupLen)
+{
+ for (int i = 0; i < groupLen; ++i) {
+ for (int j = 0; j < appEventGroups[i].infoLen; ++j) {
+ HandleSanitizerEventInfo(appEventGroups[i].appEventInfos[j]);
+ }
+ }
+}
+
+static napi_value RegisterSanitizerReceiveWatcher(napi_env env, napi_callback_info info)
+{
+ // 开发者自定义观察者名称,系统根据不同的名称来识别不同的观察者。
+ sanitizerWatcherR = OH_HiAppEvent_CreateWatcher("onSanitizerReceiveWatcher");
+ // 设置订阅的事件为EVENT_ADDRESS_SANITIZER。
+ const char *names[] = {EVENT_ADDRESS_SANITIZER};
+ // 开发者订阅感兴趣的事件,此处订阅了系统事件。
+ OH_HiAppEvent_SetAppEventFilter(sanitizerWatcherR, DOMAIN_OS, 0, names, 1);
+ // 开发者设置已实现的回调函数,观察者接收到事件后回立即触发OnReceive回调。
+ OH_HiAppEvent_SetWatcherOnReceive(sanitizerWatcherR, OnReceiveSanitizerEvent);
+ // 使观察者开始监听订阅的事件。
+ OH_HiAppEvent_AddWatcher(sanitizerWatcherR);
+ return {};
+}
// [End AsanEvent_OnReceive]
// [Start TimeOutEvent_OnReceive]
static void OnReceiveTimeOutEvent(const struct HiAppEvent_AppEventGroup *appEventGroups, int i, int j)
@@ -367,10 +495,6 @@ static void OnReceive(const char *domain, const struct HiAppEvent_AppEventGroup
OnReceiveCrashEvent(appEventGroups, i, j);
// 处理卡死事件
OnReceiveFreezeEvent(appEventGroups, i, j);
- // 处理内存泄漏事件
- OnReceivePssLeakEvent(appEventGroups, i, j);
- // 处理ASAN事件
- OnReceiveAsanEvent(appEventGroups, i, j);
// 处理主线程卡顿事件
OnReceiveTimeOutEvent(appEventGroups, i, j);
}
@@ -460,59 +584,145 @@ static void OnTriggerFreezeEvent(std::string domain, std::string name, Json::Val
}
// [End FreezeEvent_OnTrigger]
// [Start PssLeakEvent_OnTrigger]
-static void OnTriggerPssLeakEvent(std::string domain, std::string name, Json::Value eventInfo, Json::FastWriter writer)
+//定义一变量,用来缓存创建的观察者的指针。
+static HiAppEvent_Watcher *resouceLeakWatcherT;
+
+// 开发者可以自行实现获取已监听到事件的回调函数,其中events指针指向内容仅在该函数内有效。
+static void OnTakeLeakEvent(const char *const *events, uint32_t eventLen)
{
- if (domain == DOMAIN_OS && name == EVENT_RESOURCE_OVERLIMIT) {
- auto time = eventInfo["time"].asInt64();
- auto pid = eventInfo["pid"].asInt();
- auto uid = eventInfo["uid"].asInt();
- auto resourceType = eventInfo["resourceType"].asString();
- auto bundleName = eventInfo["bundle_name"].asString();
- auto bundleVersion = eventInfo["bundle_version"].asString();
- auto memory = writer.write(eventInfo["memory"]);
- auto externalLog = writer.write(eventInfo["external_log"]);
- std::string logOverLimit = eventInfo["log_over_limit"].asBool() ? "true" : "false";
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.pid=%{public}d", pid);
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uid=%{public}d", uid);
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.resource_type=%{public}s",
+ Json::Reader reader(Json::Features::strictMode());
+ Json::FastWriter writer;
+ for (int i = 0; i < eventLen; ++i) {
+ Json::Value eventInfo;
+ if (reader.parse(events[i], eventInfo)) {
+ auto domain = eventInfo["domain_"].asString();
+ auto name = eventInfo["name_"].asString();
+ auto type = eventInfo["type_"].asInt();
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.domain=%{public}s", domain.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.name=%{public}s", name.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.eventType=%{public}d", type);
+ if (domain == DOMAIN_OS && name == EVENT_RESOURCE_OVERLIMIT) {
+ auto time = eventInfo["time"].asInt64();
+ auto pid = eventInfo["pid"].asInt();
+ auto uid = eventInfo["uid"].asInt();
+ auto resourceType = eventInfo["resourceType"].asString();
+ auto bundleName = eventInfo["bundle_name"].asString();
+ auto bundleVersion = eventInfo["bundle_version"].asString();
+ auto memory = writer.write(eventInfo["memory"]);
+ auto externalLog = writer.write(eventInfo["external_log"]);
+ std::string logOverLimit = eventInfo["log_over_limit"].asBool() ? "true":"false";
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.pid=%{public}d", pid);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uid=%{public}d", uid);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.resource_type=%{public}s",
resourceType.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_name=%{public}s", bundleName.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_version=%{public}s",
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_name=%{public}s",
+ bundleName.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_version=%{public}s",
bundleVersion.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.memory=%{public}s", memory.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.external_log=%{public}s",
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.memory=%{public}s",
+ memory.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.external_log=%{public}s",
externalLog.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}d",
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}s",
logOverLimit.c_str());
+ }
+ }
}
}
+
+// 开发者可以自行实现订阅回调函数,以便对获取到的事件打点数据进行自定义处理。
+static void OnTriggerLeakEvent(int row, int size)
+{
+ // 接收回调后,获取指定数量的已接收事件。
+ OH_HiAppEvent_TakeWatcherData(resouceLeakWatcherT, row, OnTakeLeakEvent);
+}
+
+static napi_value RegisterLeakTriggerWatcher(napi_env env, napi_callback_info info)
+{
+ // 开发者自定义观察者名称,系统根据不同的名称来识别不同的观察者。
+ resouceLeakWatcherT = OH_HiAppEvent_CreateWatcher("onLeakTriggerWatcher");
+ // 设置订阅的事件为EVENT_RESOURCE_OVERLIMIT。
+ const char *names[] = {EVENT_RESOURCE_OVERLIMIT};
+ // 开发者订阅感兴趣的事件,此处订阅了系统事件。
+ OH_HiAppEvent_SetAppEventFilter(resouceLeakWatcherT, DOMAIN_OS, 0, names, 1);
+ // 开发者设置已实现的回调函数,需OH_HiAppEvent_SetTriggerCondition设置的条件满足方可触发。
+ OH_HiAppEvent_SetWatcherOnTrigger(resouceLeakWatcherT, OnTriggerLeakEvent);
+ // 开发者可以设置订阅触发回调的条件,此处是设置新增事件打点数量为2个时,触发onTrigger回调。
+ OH_HiAppEvent_SetTriggerCondition(resouceLeakWatcherT, 1, 0, 0);
+ // 使观察者开始监听订阅的事件。
+ OH_HiAppEvent_AddWatcher(resouceLeakWatcherT);
+ return {};
+}
// [End PssLeakEvent_OnTrigger]
// [Start AsanEvent_OnTrigger]
-static void OnTriggerAsanEvent(std::string domain, std::string name, Json::Value eventInfo, Json::FastWriter writer)
+//定义一变量,用来缓存创建的观察者的指针。
+static HiAppEvent_Watcher *sanitizerTriggerWatcher;
+
+// 开发者可以自行实现获取已监听到事件的回调函数,其中events指针指向内容仅在该函数内有效。
+static void OnTakeSanitizerEvent(const char *const *events, uint32_t eventLen)
{
- if (domain == DOMAIN_OS && name == EVENT_ADDRESS_SANITIZER) {
- auto time = eventInfo["time"].asInt64();
- auto bundleVersion = eventInfo["bundle_version"].asString();
- auto bundleName = eventInfo["bundle_name"].asString();
- auto pid = eventInfo["pid"].asInt();
- auto uid = eventInfo["uid"].asInt();
- auto asanType = eventInfo["type"].asString();
- auto externalLog = writer.write(eventInfo["external_log"]);
- std::string logOverLimit = eventInfo["log_over_limit"].asBool() ? "true" : "false";
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_version=%{public}s",
+ Json::Reader reader(Json::Features::strictMode());
+ Json::FastWriter writer;
+ for (int i = 0; i < eventLen; ++i) {
+ Json::Value eventInfo;
+ if (reader.parse(events[i], eventInfo)) {
+ auto domain = eventInfo["domain_"].asString();
+ auto name = eventInfo["name_"].asString();
+ auto type = eventInfo["type_"].asInt();
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.domain=%{public}s", domain.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.name=%{public}s", name.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.eventType=%{public}d", type);
+ if (domain == DOMAIN_OS && name == EVENT_ADDRESS_SANITIZER) {
+ auto time = eventInfo["time"].asInt64();
+ auto bundleVersion = eventInfo["bundle_version"].asString();
+ auto bundleName = eventInfo["bundle_name"].asString();
+ auto pid = eventInfo["pid"].asInt();
+ auto uid = eventInfo["uid"].asInt();
+ auto asanType = eventInfo["type"].asString();
+ auto externalLog = writer.write(eventInfo["external_log"]);
+ std::string logOverLimit = eventInfo["log_over_limit"].asBool() ? "true" : "false";
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_version=%{public}s",
bundleVersion.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_name=%{public}s", bundleName.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.pid=%{public}d", pid);
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uid=%{public}d", uid);
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.crash_type=%{public}s", asanType.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.external_log=%{public}s",
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_name=%{public}s",
+ bundleName.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.pid=%{public}d", pid);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uid=%{public}d", uid);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.crash_type=%{public}s",
+ asanType.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.external_log=%{public}s",
externalLog.c_str());
- OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}s",
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}s",
logOverLimit.c_str());
+ }
+ }
}
}
+
+// 开发者可以自行实现订阅回调函数,以便对获取到的事件打点数据进行自定义处理。
+static void OnTriggerSanitizerEvent(int row, int size)
+{
+ // 接收回调后,获取指定数量的已接收事件。
+ OH_HiAppEvent_TakeWatcherData(sanitizerTriggerWatcher, row, OnTakeSanitizerEvent);
+}
+
+static napi_value RegisterSanitizerTriggerWatcher(napi_env env, napi_callback_info info)
+{
+ // 开发者自定义观察者名称,系统根据不同的名称来识别不同的观察者。
+ sanitizerTriggerWatcher = OH_HiAppEvent_CreateWatcher("sanitizerTriggerWatcher");
+ // 设置订阅的事件为EVENT_ADDRESS_SANITIZER。
+ const char *names[] = {EVENT_ADDRESS_SANITIZER};
+ // 开发者订阅感兴趣的事件,此处订阅了系统事件。
+ OH_HiAppEvent_SetAppEventFilter(sanitizerTriggerWatcher, DOMAIN_OS, 0, names, 1);
+ // 开发者设置已实现的回调函数,需OH_HiAppEvent_SetTriggerCondition设置的条件满足方可触发。
+ OH_HiAppEvent_SetWatcherOnTrigger(sanitizerTriggerWatcher, OnTriggerSanitizerEvent);
+ // 开发者可以设置订阅触发回调的条件,此处是设置新增事件打点数量为1个时,触发onTrigger回调。
+ OH_HiAppEvent_SetTriggerCondition(sanitizerTriggerWatcher, 1, 0, 0);
+ // 使观察者开始监听订阅的事件。
+ OH_HiAppEvent_AddWatcher(sanitizerTriggerWatcher);
+ return {};
+}
// [End AsanEvent_OnTrigger]
// [Start EventSub_OnTake_All]
// 开发者可以自行实现获取已监听到事件的回调函数,其中events指针指向内容仅在该函数内有效。
@@ -535,10 +745,6 @@ static void OnTake(const char *const *events, uint32_t eventLen)
OnTriggerCrashEvent(domain, name, eventInfo, writer);
// 处理卡死事件
OnTriggerFreezeEvent(domain, name, eventInfo, writer);
- // 处理内存泄漏事件
- OnTriggerPssLeakEvent(domain, name, eventInfo, writer);
- // 处理ASAN事件
- OnTriggerAsanEvent(domain, name, eventInfo, writer);
}
}
}
@@ -558,8 +764,7 @@ static napi_value RegisterWatcher(napi_env env, napi_callback_info info)
eventWatcherT = OH_HiAppEvent_CreateWatcher("onTriggerWatcher");
eventWatcherR = OH_HiAppEvent_CreateWatcher("onReceiverWatcher");
// 设置订阅的事件名称为click, EVENT_APP_CRASH。
- const char *names[] = {"click", EVENT_APP_CRASH, EVENT_APP_FREEZE, EVENT_RESOURCE_OVERLIMIT,
- EVENT_ADDRESS_SANITIZER, EVENT_MAIN_THREAD_JANK};
+ const char *names[] = {"click", EVENT_APP_CRASH, EVENT_APP_FREEZE, EVENT_MAIN_THREAD_JANK};
int namesSize = sizeof(names) / sizeof(names[0]);
// 开发者订阅感兴趣的应用事件
OH_HiAppEvent_SetAppEventFilter(eventWatcherT, "button", 0, names, namesSize);
@@ -580,26 +785,65 @@ static napi_value RegisterWatcher(napi_env env, napi_callback_info info)
return {};
}
// [End EventSub_RegisterWatcher_All]
+
// [Start EventSub_RemoveWatcher_All]
// [Start AppEvent_C++_RemoveWatcher]
+// [Start APP_Hicollie_RemoveWatcher]
+// [Start AsanEvent_RemoveWatcher]
+// [Start PssLeakEvent_RemoveWatcher]
+// [Start AppKillEvent_RemoveWatcher]
static napi_value RemoveWatcher(napi_env env, napi_callback_info info)
{
// 使观察者停止监听事件
+ // [StartExclude AppKillEvent_RemoveWatcher]
+ // [StartExclude PssLeakEvent_RemoveWatcher]
+ // [StartExclude AsanEvent_RemoveWatcher]
+ // [StartExclude APP_Hicollie_RemoveWatcher]
// [StartExclude AppEvent_C++_RemoveWatcher]
OH_HiAppEvent_RemoveWatcher(eventWatcherT);
OH_HiAppEvent_RemoveWatcher(eventWatcherR);
// [EndExclude AppEvent_C++_RemoveWatcher]
OH_HiAppEvent_RemoveWatcher(eventWatcherT1);
OH_HiAppEvent_RemoveWatcher(eventWatcherR1);
+ // [EndExclude APP_Hicollie_RemoveWatcher]
+ // [StartExclude AppEvent_C++_RemoveWatcher]
+ OH_HiAppEvent_RemoveWatcher(appHicollieWatcherR);
+ OH_HiAppEvent_RemoveWatcher(appHicollieWatcherT);
+ // [EndExclude AsanEvent_RemoveWatcher]
+ // [StartExclude APP_Hicollie_RemoveWatcher]
+ OH_HiAppEvent_RemoveWatcher(sanitizerWatcherR);
+ // [StartExclude AsanEvent_RemoveWatcher]
+ // [EndExclude PssLeakEvent_RemoveWatcher]
+ OH_HiAppEvent_RemoveWatcher(resouceLeakWatcherR);
+ // [EndExclude AppKillEvent_RemoveWatcher]
+ // [StartExclude PssLeakEvent_RemoveWatcher]
+ OH_HiAppEvent_RemoveWatcher(appKillWatcherR);
+ // [EndExclude AppEvent_C++_RemoveWatcher]
+ // [EndExclude AsanEvent_RemoveWatcher]
+ // [EndExclude PssLeakEvent_RemoveWatcher]
+ // [EndExclude APP_Hicollie_RemoveWatcher]
return {};
}
+// [End AppKillEvent_RemoveWatcher]
+// [End PssLeakEvent_RemoveWatcher]
+// [End AsanEvent_RemoveWatcher]
+// [End APP_Hicollie_RemoveWatcher]
// [End AppEvent_C++_RemoveWatcher]
// [End EventSub_RemoveWatcher_All]
+
// [Start EventSub_DestroyWatcher_All]
// [Start AppEvent_C++_DestroyWatcher]
+// [Start APP_Hicollie_DestroyWatcher]
+// [Start AsanEvent_DestroyWatcher]
+// [Start PssLeakEvent_DestroyWatcher]
+// [Start AppKillEvent_DestroyWatcher]
static napi_value DestroyWatcher(napi_env env, napi_callback_info info)
{
// 销毁创建的观察者,并置eventWatcher为nullptr。
+ // [StartExclude AppKillEvent_DestroyWatcher]
+ // [StartExclude PssLeakEvent_DestroyWatcher]
+ // [StartExclude AsanEvent_DestroyWatcher]
+ // [StartExclude APP_Hicollie_DestroyWatcher]
// [StartExclude AppEvent_C++_DestroyWatcher]
OH_HiAppEvent_DestroyWatcher(eventWatcherT);
OH_HiAppEvent_DestroyWatcher(eventWatcherR);
@@ -610,10 +854,37 @@ static napi_value DestroyWatcher(napi_env env, napi_callback_info info)
OH_HiAppEvent_DestroyWatcher(eventWatcherR1);
eventWatcherT1 = nullptr;
eventWatcherR1 = nullptr;
+ // [EndExclude APP_Hicollie_DestroyWatcher]
+ // [StartExclude AppEvent_C++_DestroyWatcher]
+ OH_HiAppEvent_DestroyWatcher(appHicollieWatcherR);
+ OH_HiAppEvent_DestroyWatcher(appHicollieWatcherT);
+ appHicollieWatcherR = nullptr;
+ appHicollieWatcherT = nullptr;
+ // [EndExclude AsanEvent_DestroyWatcher]
+ // [StartExclude APP_Hicollie_DestroyWatcher]
+ OH_HiAppEvent_DestroyWatcher(sanitizerWatcherR);
+ sanitizerWatcherR = nullptr;
+ // [EndExclude PssLeakEvent_DestroyWatcher]
+ // [StartExclude AsanEvent_DestroyWatcher]
+ OH_HiAppEvent_DestroyWatcher(resouceLeakWatcherR);
+ resouceLeakWatcherR = nullptr;
+ // [EndExclude AppKillEvent_DestroyWatcher]
+ // [StartExclude PssLeakEvent_DestroyWatcher]
+ OH_HiAppEvent_DestroyWatcher(appKillWatcherR);
+ appKillWatcherR = nullptr;
+ // [EndExclude APP_Hicollie_DestroyWatcher]
+ // [EndExclude AppEvent_C++_DestroyWatcher]
+ // [EndExclude AsanEvent_DestroyWatcher]
+ // [EndExclude PssLeakEvent_DestroyWatcher]
return {};
}
+// [End AppKillEvent_DestroyWatcher]
+// [End PssLeakEvent_DestroyWatcher]
+// [End AsanEvent_DestroyWatcher]
+// [End APP_Hicollie_DestroyWatcher]
// [End AppEvent_C++_DestroyWatcher]
// [End EventSub_DestroyWatcher_All]
+
// [Start AppEvent_Click_C++_WriteAppEvent]
static napi_value WriteAppEvent(napi_env env, napi_callback_info info)
{
@@ -626,33 +897,271 @@ static napi_value WriteAppEvent(napi_env env, napi_callback_info info)
}
// [End AppEvent_Click_C++_WriteAppEvent]
// [Start AsanEvent_AddressTest]
-static napi_value AddressTest(napi_env env, napi_callback_info info)
-{
- // 任意实数
- int num = 1;
- int length = 10;
- // 构造数组越界写入
- int a[length];
- a[length] = num;
+static napi_value AddressSanitizerTest(napi_env env, napi_callback_info info)
+{
+ constexpr int bufferSize = 42;
+ int subscript = 43;
+ char buffer[bufferSize];
+ buffer[subscript] = subscript;
+ printf("address: %p", buffer);
return {};
}
// [End AsanEvent_AddressTest]
+// [Start AppKillEvent_NativeLeak]
+#include
+
+static void NativeLeak()
+{
+ constexpr int leakSizePerTime = 500000;
+ constexpr int sleepTimeMs = 10;
+ while (true) {
+ char *p = (char *)malloc(leakSizePerTime + 1);
+ if (!p) {
+ break;
+ }
+ memset(p, 'a', leakSizePerTime);
+ std::this_thread::sleep_for(std::chrono::milliseconds(sleepTimeMs));
+ }
+}
+
+static napi_value Leak(napi_env env, napi_callback_info info)
+{
+ std::thread t1(NativeLeak);
+ t1.detach();
+ return {};
+}
+// [End AppKillEvent_NativeLeak]
// [Start EventSub_Init_All]
// [Start AppEvent_C++_Init]
+
+// [StartExclude AppEvent_C++_Init]
+// [Start Hicollie_Set_Timer]
+//定义回调函数
+void CallBack(void*)
+{
+ OH_LOG_INFO(LogType::LOG_APP, "HiCollieTimerNdk CallBack"); // 回调函数中打印日志
+}
+
+static napi_value TestHiCollieTimerNdk(napi_env env, napi_callback_info info)
+{
+ int id;
+ // 设置HiCollieTimer 参数(Timer任务名,超时时间,回调函数,回调函数参数,超时发生后行为)
+ HiCollie_SetTimerParam param = {"testTimer", 1, CallBack, nullptr, HiCollie_Flag::HICOLLIE_FLAG_LOG};
+ HiCollie_ErrorCode errorCode = OH_HiCollie_SetTimer(param, &id); // 注册HiCollieTimer函数执行时长超时检测一次性任务
+ if (errorCode == HICOLLIE_SUCCESS) { // HiCollieTimer任务注册成功
+ OH_LOG_INFO(LogType::LOG_APP, "HiCollieTimer taskId: %{public}d", id); // 打印任务id
+ sleep(2); // 模拟执行耗时函数,在这里简单的将线程阻塞2s
+ OH_HiCollie_CancelTimer(id); // 根据id取消已注册任务
+ }
+ return nullptr;
+}
+// [End Hicollie_Set_Timer]
+
+// [Start App_Hicollie_OnReceive]
+static void OnReceiveAppHicollie(const struct HiAppEvent_AppEventGroup *appEventGroups, int i, int j)
+{
+ if (strcmp(appEventGroups[i].appEventInfos[j].domain, DOMAIN_OS) == 0 &&
+ strcmp(appEventGroups[i].appEventInfos[j].name, EVENT_APP_HICOLLIE) == 0) {
+ Json::Value params;
+ Json::Reader reader(Json::Features::strictMode());
+ Json::FastWriter writer;
+ if (reader.parse(appEventGroups[i].appEventInfos[j].params, params)) {
+ auto time = params["time"].asInt64();
+ auto foreground = params["foreground"].asBool();
+ auto bundleVersion = params["bundle_version"].asString();
+ auto processName = params["process_name"].asString();
+ auto pid = params["pid"].asInt();
+ auto uid = params["uid"].asInt();
+ auto uuid = params["uuid"].asString();
+ auto exception = writer.write(params["exception"]);
+ auto hilogSize = params["hilog"].size();
+ auto peerBindSize = params["peer_binder"].size();
+ auto memory = writer.write(params["memory"]);
+ auto externalLog = writer.write(params["external_log"]);
+ auto logOverLimit = params["log_over_limit"].asBool();
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.foreground=%{public}d", foreground);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_version=%{public}s",
+ bundleVersion.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.process_name=%{public}s", processName.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.pid=%{public}d", pid);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uid=%{public}d", uid);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uuid=%{public}s", uuid.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.exception=%{public}s", exception.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.hilog.size=%{public}d", hilogSize);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.peer_binder.size=%{public}d", peerBindSize);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.memory=%{public}s", memory.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.external_log=%{public}s", externalLog.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}d", logOverLimit);
+ }
+ }
+}
+
+static void AppHicollieOnReceive(const char *domain, const struct HiAppEvent_AppEventGroup *appEventGroups,
+ uint32_t groupLen)
+{
+ for (int i = 0; i < groupLen; ++i) {
+ for (int j = 0; j < appEventGroups[i].infoLen; ++j) {
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.domain=%{public}s",
+ appEventGroups[i].appEventInfos[j].domain);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.name=%{public}s",
+ appEventGroups[i].appEventInfos[j].name);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.eventType=%{public}d",
+ appEventGroups[i].appEventInfos[j].type);
+ OnReceiveAppHicollie(appEventGroups, i, j);
+ }
+ }
+}
+
+static napi_value RegisterAppHicollieWatcherR(napi_env env, napi_callback_info info)
+{
+ // 开发者自定义观察者名称,系统根据不同的名称来识别不同的观察者。
+ appHicollieWatcherR = OH_HiAppEvent_CreateWatcher("appHicollieWatcherR");
+ // 设置订阅的事件为EVENT_APP_HICOLLIE。
+ const char *names[] = {EVENT_APP_HICOLLIE};
+ // 开发者订阅感兴趣的事件,此处订阅了系统事件。
+ OH_HiAppEvent_SetAppEventFilter(appHicollieWatcherR, DOMAIN_OS, 0, names, 1);
+ // 开发者设置已实现的回调函数,观察者接收到事件后回立即触发OnReceive回调。
+ OH_HiAppEvent_SetWatcherOnReceive(appHicollieWatcherR, AppHicollieOnReceive);
+ // 使观察者开始监听订阅的事件。
+ OH_HiAppEvent_AddWatcher(appHicollieWatcherR);
+ return {};
+}
+// [End App_Hicollie_OnReceive]
+
+// [Start App_Hicollie_Trigger]
+// 开发者可以自行实现获取已监听到事件的回调函数,其中events指针指向内容仅在该函数内有效。
+static void AppHicollieOnTake(const char *const *events, uint32_t eventLen)
+{
+ Json::Reader reader(Json::Features::strictMode());
+ Json::FastWriter writer;
+ for (int i = 0; i < eventLen; ++i) {
+ Json::Value eventInfo;
+ if (reader.parse(events[i], eventInfo)) {
+ auto domain = eventInfo["domain_"].asString();
+ auto name = eventInfo["name_"].asString();
+ auto type = eventInfo["type_"].asInt();
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.domain=%{public}s", domain.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.name=%{public}s", name.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.eventType=%{public}d", type);
+ if (domain == DOMAIN_OS && name == EVENT_APP_HICOLLIE) {
+ auto time = eventInfo["time"].asInt64();
+ auto foreground = eventInfo["foreground"].asBool();
+ auto bundleVersion = eventInfo["bundle_version"].asString();
+ auto processName = eventInfo["process_name"].asString();
+ auto pid = eventInfo["pid"].asInt();
+ auto uid = eventInfo["uid"].asInt();
+ auto uuid = eventInfo["uuid"].asString();
+ auto exception = writer.write(eventInfo["exception"]);
+ auto hilogSize = eventInfo["hilog"].size();
+ auto peerBindSize = eventInfo["peer_binder"].size();
+ auto memory = writer.write(eventInfo["memory"]);
+ auto externalLog = writer.write(eventInfo["external_log"]);
+ auto logOverLimit = eventInfo["log_over_limit"].asBool();
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.time=%{public}lld", time);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.foreground=%{public}d", foreground);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.bundle_version=%{public}s",
+ bundleVersion.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.process_name=%{public}s",
+ processName.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.pid=%{public}d", pid);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uid=%{public}d", uid);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.uuid=%{public}s", uuid.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.exception=%{public}s", exception.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.hilog.size=%{public}d", hilogSize);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.peer_binder.size=%{public}d", peerBindSize);
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.memory=%{public}s", memory.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.external_log=%{public}s",
+ externalLog.c_str());
+ OH_LOG_INFO(LogType::LOG_APP, "HiAppEvent eventInfo.params.log_over_limit=%{public}d", logOverLimit);
+ }
+ }
+ }
+}
+
+// 开发者可以自行实现订阅回调函数,以便对获取到的事件打点数据进行自定义处理。
+static void AppHicollieOnTrigger(int row, int size)
+{
+ // 接收回调后,获取指定数量的已接收事件。
+ OH_HiAppEvent_TakeWatcherData(appHicollieWatcherT, row, AppHicollieOnTake);
+}
+
+static napi_value RegisterAppHicollieWatcherT(napi_env env, napi_callback_info info)
+{
+ // 开发者自定义观察者名称,系统根据不同的名称来识别不同的观察者。
+ appHicollieWatcherT = OH_HiAppEvent_CreateWatcher("appHicollieWatcherT");
+ // 设置订阅的事件为EVENT_APP_HICOLLIE。
+ const char *names[] = {EVENT_APP_HICOLLIE};
+ // 开发者订阅感兴趣的事件,此处订阅了系统事件。
+ OH_HiAppEvent_SetAppEventFilter(appHicollieWatcherT, DOMAIN_OS, 0, names, 1);
+ // 开发者设置已实现的回调函数,需OH_HiAppEvent_SetTriggerCondition设置的条件满足方可触发。
+ OH_HiAppEvent_SetWatcherOnTrigger(appHicollieWatcherT, AppHicollieOnTrigger);
+ // 开发者可以设置订阅触发回调的条件,此处是设置新增事件打点数量为1个时,触发onTrigger回调。
+ OH_HiAppEvent_SetTriggerCondition(appHicollieWatcherT, 1, 0, 0);
+ // 使观察者开始监听订阅的事件。
+ OH_HiAppEvent_AddWatcher(appHicollieWatcherT);
+ return {};
+}
+// [End App_Hicollie_Trigger]
+// [EndExclude AppEvent_C++_Init]
+
+// [Start AsanEvent_Init]
+// [Start AsanEventTS_Init]
+// [Start PssLeakEvent_Init]
+// [Start AppKillEvent_Init]
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
+ // [StartExclude AppKillEvent_Init]
+ // [StartExclude PssLeakEvent_Init]
+ // [StartExclude AsanEvent_Init]
+ // [StartExclude AsanEventTS_Init]
// [StartExclude AppEvent_C++_Init]
{"registerWatcher", nullptr, RegisterWatcher, nullptr, nullptr, nullptr, napi_default, nullptr},
- {"addressTest", nullptr, AddressTest, nullptr, nullptr, nullptr, napi_default, nullptr},
// [EndExclude AppEvent_C++_Init]
{ "registerWatcherCrash", nullptr, RegisterWatcherCrash, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "registerWatcherClick", nullptr, RegisterWatcherClick, nullptr, nullptr, nullptr, napi_default, nullptr },
- { "writeAppEvent", nullptr, WriteAppEvent, nullptr, nullptr, nullptr, napi_default, nullptr }
+ { "writeAppEvent", nullptr, WriteAppEvent, nullptr, nullptr, nullptr, napi_default, nullptr },
+ // [StartExclude AppEvent_C++_Init]
+ // [Start test_hicollie_timer]
+ // 将TestHiCollieTimerNdk注册为ArkTS接口
+ { "TestHiCollieTimerNdk", nullptr, TestHiCollieTimerNdk, nullptr, nullptr, nullptr, napi_default, nullptr },
+ // [End test_hicollie_timer]
+ // [Start register_app_hicollie_watcherR]
+ { "RegisterAppHicollieWatcherR", nullptr, RegisterAppHicollieWatcherR, nullptr, nullptr, nullptr,
+ napi_default, nullptr },
+ // [End register_app_hicollie_watcherR]
+ // [Start register_app_hicollie_watcherT]
+ { "RegisterAppHicollieWatcherT", nullptr, RegisterAppHicollieWatcherT, nullptr, nullptr, nullptr,
+ napi_default, nullptr },
+ // [End register_app_hicollie_watcherT]
+ // [EndExclude AsanEvent_Init]
+ { "registerSanitizerReceiveWatcher", nullptr, RegisterSanitizerReceiveWatcher, nullptr, nullptr, nullptr,
+ napi_default, nullptr },
+ // [EndExclude AsanEventTS_Init]
+ { "addressSanitizerTest", nullptr, AddressSanitizerTest, nullptr, nullptr, nullptr, napi_default, nullptr},
+ // [EndExclude PssLeakEvent_Init]
+ // [StartExclude AsanEventTS_Init]
+ // [StartExclude AsanEvent_Init]
+ { "registerLeakReceiveWatcher", nullptr, RegisterLeakReceiveWatcher, nullptr, nullptr, nullptr,
+ napi_default, nullptr },
+ // [StartExclude PssLeakEvent_Init]
+ // [EndExclude AppKillEvent_Init]
+ { "registerAppKillReceiveWatcher", nullptr, RegisterAppKillReceiveWatcher, nullptr, nullptr, nullptr,
+ napi_default, nullptr },
+ { "leak", nullptr, Leak, nullptr, nullptr, nullptr, napi_default, nullptr}
+ // [EndExclude AsanEvent_Init]
+ // [EndExclude AsanEventTS_Init]
+ // [EndExclude PssLeakEvent_Init]
+ // [EndExclude AppEvent_C++_Init]
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports;
}
+// [End AppKillEvent_Init]
+// [End PssLeakEvent_Init]
+// [End AsanEventTS_Init]
+// [End AsanEvent_Init]
// [End AppEvent_C++_Init]
// [End EventSub_Init_All]
static napi_module demoModule = {
diff --git a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/types/libentry/Index.d.ts b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/types/libentry/Index.d.ts
index 6829fba35cdc34f11c08cadc1db975a10fda3d99..d57348cc5d931faeaa5d135283938a9345026c6d 100644
--- a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/types/libentry/Index.d.ts
+++ b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/cpp/types/libentry/Index.d.ts
@@ -15,10 +15,29 @@
// [Start EventSub_Index.d.ts_All]
export const registerWatcher: () => void;
-export const addressTest: () => void;
// [Start AppEvent_C++_Index.d.ts]
export const registerWatcherCrash: () => void;
export const registerWatcherClick: () => void;
export const writeAppEvent: () => void;
// [End AppEvent_C++_Index.d.ts]
+// [Start test_hicollie_timer_Index.d.ts]
+export const TestHiCollieTimerNdk: () => void;
+// [End test_hicollie_timer_Index.d.ts]
+// [Start AsanEvent_Index.d.ts]
+export const registerSanitizerReceiveWatcher: () => void;
+export const addressSanitizerTest: () => void;
+// [End AsanEvent_Index.d.ts]
+// [Start PssLeakEvent_Index.d.ts]
+export const registerLeakReceiveWatcher: () => void;
+// [End PssLeakEvent_Index.d.ts]
+// [Start AppKillEvent_Index.d.ts]
+export const registerAppKillReceiveWatcher: () => void;
+export const leak: () => void;
+// [End AppKillEvent_Index.d.ts]
+// [Start Register_AppHicollie_WatcherR.d.ts]
+export const RegisterAppHicollieWatcherR: () => void;
+// [End Register_AppHicollie_WatcherR.d.ts]
+// [Start Register_AppHicollie_WatcherT.d.ts]
+export const RegisterAppHicollieWatcherT: () => void;
+// [End Register_AppHicollie_WatcherT.d.ts]
// [End EventSub_Index.d.ts_All]
diff --git a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/ets/entryability/EntryAbility.ets b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/ets/entryability/EntryAbility.ets
index e049d357c7ec2b8e6ba66ed7dd60d050a3a8b0c8..eaa43d42207a8c202aa89f08ca5cb484e9dc0437 100644
--- a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/ets/entryability/EntryAbility.ets
+++ b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/ets/entryability/EntryAbility.ets
@@ -15,11 +15,13 @@
// [Start EventSub_EntryAbility_Header]
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
+// [Start PssLeakEvent_ArkTS_Header]
// [Start AppEvent_Crash_Click_ArkTS_Header]
import { hiAppEvent, hilog } from '@kit.PerformanceAnalysisKit';
// [End AppEvent_Crash_Click_ArkTS_Header]
-import { hidebug } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
+// [End PssLeakEvent_ArkTS_Header]
+import { hidebug } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
// [End EventSub_EntryAbility_Header]
// [Start EventSub_Capi_Header]
@@ -89,21 +91,26 @@ export default class EntryAbility extends UIAbility {
}
});
// [End AppEvent_Click_ArkTS_Add_Watcher]
- // [Start Crash&FreezeEvent_ArkTS_Add_Event]
+ // [Start ArkTS_Add_Event_Params]
// 开发者完成参数键值对赋值
let params: Record = {
'testData': 100,
};
+ // [End ArkTS_Add_Event_Params]
+ // [Start Crash_ArkTS_Add_Event]
// 开发者可以设置事件的自定义参数
hiAppEvent.setEventParam(params, hiAppEvent.domain.OS, hiAppEvent.event.APP_CRASH).then(() => {
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', `HiAppEvent code: ${err.code}, message: ${err.message}`);
});
+ // [End Crash_ArkTS_Add_Event]
+ // [Start FreezeEvent_ArkTS_Add_Event]
+ // 开发者可以设置事件的自定义参数
hiAppEvent.setEventParam(params, hiAppEvent.domain.OS, hiAppEvent.event.APP_FREEZE).then(() => {
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', `HiAppEvent code: ${err.code}, message: ${err.message}`);
});
- // [End Crash&FreezeEvent_ArkTS_Add_Event]
+ // [End FreezeEvent_ArkTS_Add_Event]
// [Start CrashEvent_ArkTS_Add_Watcher]
// 添加崩溃事件观察者
hiAppEvent.addWatcher({
@@ -231,18 +238,58 @@ export default class EntryAbility extends UIAbility {
}
});
// [End FreezeEvent_ArkTS_Add_Watcher]
- // [Start PssleakEvent_ArkTS_Add_Watcher]
- // 添加资源泄露事件观察者
+ // [Start PssLeakEvent_ArkTS_Add_Watcher]
+ // 完成参数键值对赋值
+ let pssParams: Record = {
+ "test_data": 100,
+ };
+ // 设置资源泄漏事件的自定义参数
+ hiAppEvent.setEventParam(pssParams, hiAppEvent.domain.OS, hiAppEvent.event.RESOURCE_OVERLIMIT).then(() => {
+ hilog.info(0x0000, 'testTag', `HiAppEvent success to set event param`);
+ }).catch((err: BusinessError) => {
+ hilog.error(0x0000, 'testTag', `HiAppEvent code: ${err.code}, message: ${err.message}`);
+ });
+ // 完成自定义配置键值对赋值
+ let configParams: Record = {
+ 'js_heap_logtype': 'event', // 仅获取事件
+ }
+ // 设置资源泄漏事件的自定义配置
+ hiAppEvent.setEventConfig(hiAppEvent.event.RESOURCE_OVERLIMIT, configParams);
hiAppEvent.addWatcher({
- // 开发者可以自定义观察者名称,系统会使用名称来标识不同的观察者
- name: 'pssleakwatcher',
- // 开发者可以订阅感兴趣的系统事件,此处是订阅了资源泄漏事件
+ // 自定义观察者名称,系统会使用名称来标识不同的观察者
+ name: 'pssLeakWatcher',
+ // 订阅感兴趣的系统事件,此处是订阅了资源泄漏事件
appEventFilters: [
{
domain: hiAppEvent.domain.OS,
names: [hiAppEvent.event.RESOURCE_OVERLIMIT]
}
],
+ // 自行实现订阅实时回调函数,以便对订阅获取到的事件数据进行自定义处理
+ onReceive: (domain: string, appEventGroups: Array) => {
+ hilog.info(0x0000, 'testTag', `HiAppEvent onReceive: domain=${domain}`);
+ for (const eventGroup of appEventGroups) {
+ // 根据事件集合中的事件名称区分不同的系统事件
+ hilog.info(0x0000, 'testTag', `HiAppEvent eventName=${eventGroup.name}`);
+ for (const eventInfo of eventGroup.appEventInfos) {
+ // 获取到资源泄漏事件发生时内存信息
+ hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo=${JSON.stringify(eventInfo)}`);
+ }
+ }
+ }
+ });
+ // [End PssLeakEvent_ArkTS_Add_Watcher]
+ // [Start AppKillEvent_ArkTS_Add_Watcher]
+ hiAppEvent.addWatcher({
+ // 开发者可以自定义观察者名称,系统会使用名称来标识不同的观察者
+ name: 'leakWatcher',
+ // 开发者可以订阅感兴趣的系统事件,此处是订阅了应用终止事件
+ appEventFilters: [
+ {
+ domain: hiAppEvent.domain.OS,
+ names: [hiAppEvent.event.APP_KILLED]
+ }
+ ],
// 开发者可以自行实现订阅实时回调函数,以便对订阅获取到的事件数据进行自定义处理
onReceive: (domain: string, appEventGroups: Array) => {
hilog.info(0x0000, 'testTag', `HiAppEvent onReceive: domain=${domain}`);
@@ -250,19 +297,25 @@ export default class EntryAbility extends UIAbility {
// 开发者可以根据事件集合中的事件名称区分不同的系统事件
hilog.info(0x0000, 'testTag', `HiAppEvent eventName=${eventGroup.name}`);
for (const eventInfo of eventGroup.appEventInfos) {
- // 开发者可以获取到资源泄漏事件发生时内存信息
- hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.params.memory=${JSON.stringify(eventInfo)}`);
+ // 开发者可以对事件集合中的事件数据进行自定义处理,此处是将事件数据打印在日志中
+ hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.domain=${eventInfo.domain}`);
+ hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.name=${eventInfo.name}`);
+ // 开发者可以获取到应用终止事件发生的时间戳
+ hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.params.time=${eventInfo.params['time']}`);
+ // 开发者可以获取到应用的前后台状态
+ hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.params.foreground=${eventInfo.params['foreground']}`);
+ // 开发者可以获取到应用终止事件发生的原因
+ hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.params.reason=${eventInfo.params['reason']}`);
}
}
}
});
- // [End PssleakEvent_ArkTS_Add_Watcher]
+ // [End AppKillEvent_ArkTS_Add_Watcher]
// [Start AsanEvent_ArkTS_Add_Watcher]
- // 添加踩地址事件观察者
hiAppEvent.addWatcher({
// 开发者可以自定义观察者名称,系统会使用名称来标识不同的观察者
- name: 'addressSanitizerWatcher',
- // 开发者可以订阅感兴趣的系统事件,此处是订阅了踩内存事件
+ name: 'sanitzierWatcher',
+ // 开发者可以订阅感兴趣的系统事件,此处是订阅了地址越界事件
appEventFilters: [
{
domain: hiAppEvent.domain.OS,
@@ -286,8 +339,7 @@ export default class EntryAbility extends UIAbility {
hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.pid=${eventInfo.params['pid']}`);
hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.uid=${eventInfo.params['uid']}`);
hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.type=${eventInfo.params['type']}`);
- hilog.info(0x0000, 'testTag',
- `HiAppEvent eventInfo.external_log=${JSON.stringify(eventInfo.params['external_log'])}`);
+ hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.external_log=${JSON.stringify(eventInfo.params['external_log'])}`);
hilog.info(0x0000, 'testTag', `HiAppEvent eventInfo.log_over_limit=${eventInfo.params['log_over_limit']}`);
}
}
@@ -351,6 +403,29 @@ export default class EntryAbility extends UIAbility {
// 启动时,注册按钮点击事件观察者
testNapi.registerWatcherClick();
// [End AppEvent_Call_Capi_Function]
+ // [Start Register_AppHicollie_WatcherR]
+ // 在onCreate()函数中新增接口调用,启动时注册系统事件观察者R
+ testNapi.RegisterAppHicollieWatcherR();
+ // [End Register_AppHicollie_WatcherR]
+ // [Start Register_AppHicollie_WatcherT]
+ // 在onCreate()函数中新增接口调用,启动时注册系统事件观察者T
+ testNapi.RegisterAppHicollieWatcherT();
+ // [End Register_AppHicollie_WatcherT]
+ // [Start AsanEvent_Call_Capi_Function]
+ // 在onCreate()函数中新增接口调用
+ // 启动时,注册系统事件观察者
+ testNapi.registerSanitizerReceiveWatcher();
+ // [End AsanEvent_Call_Capi_Function]
+ // [Start PssLeakEvent_Call_Capi_Function]
+ // 在onCreate()函数中新增接口调用
+ // 启动时,注册系统事件观察者
+ testNapi.registerLeakReceiveWatcher();
+ // [End PssLeakEvent_Call_Capi_Function]
+ // [Start AppKillEvent_Call_Capi_Function]
+ // 在onCreate()函数中新增接口调用
+ // 启动时,注册系统事件观察者
+ testNapi.registerAppKillReceiveWatcher();
+ // [End AppKillEvent_Call_Capi_Function]
}
onDestroy(): void {
diff --git a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/ets/pages/Index.ets b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/ets/pages/Index.ets
index 012f585f486d6aa13d409b327a955d2104c85541..741da179c79bcdcbb0931b351475d0bf754270b6 100644
--- a/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/ets/pages/Index.ets
+++ b/PerformanceAnalysisKit/HiAppEvent/EventSub/entry/src/main/ets/pages/Index.ets
@@ -17,9 +17,9 @@
import { BusinessError } from '@kit.BasicServicesKit';
import { hiAppEvent, hilog } from '@kit.PerformanceAnalysisKit';
// [End EventSub_Header]
-// [Start PssleakEvent_Header]
-import hidebug from '@ohos.hidebug';
-// [End PssleakEvent_Header]
+// [Start PssleakEvent_Button]
+import { hidebug } from '@kit.PerformanceAnalysisKit';
+// [End PssleakEvent_Button]
// [Start EventSub_Index_Capi_Header]
import testNapi from 'libentry.so';
// [End EventSub_Index_Capi_Header]
@@ -27,7 +27,9 @@ import testNapi from 'libentry.so';
@Component
struct Index {
@State leakedArray: string[][] = [];
-
+ // [Start AppKillEvent_Button]
+ @State message: string = 'Start To Leak';
+ // [End AppKillEvent_Button]
build() {
Row() {
Column() {
@@ -88,8 +90,9 @@ struct Index {
JSON.parse('');
})
// [End CrashEvent_Button]
+ // [Start PssleakEventTS_Button]
// [Start PssleakEvent_Button]
- Button($r('app.string.Pssleak_Button'))
+ Button('pss leak')
.type(ButtonType.Capsule)
.margin({
top: 20
@@ -104,9 +107,40 @@ struct Index {
this.leakedArray.push(new Array(1).fill('leak'));
}
})
- // [End PssleakEvent_Button]
- // [Start TimeOutEvent_Button]
- Button($r('app.string.TimeOut_Button'))
+ // [End PssleakEvent_Button]
+ Button('js leak')
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .backgroundColor('#0D9FFB')
+ .width('80%')
+ .height('5%')
+ .onClick(() => {
+ for (let i = 0; i < 10000; i++) {
+ this.leakedArray.push(new Array(500000).fill(1));
+ }
+ })
+ // [End PssleakEventTS_Button]
+ // [Start AppKillEvent_Button]
+ Button(this.message)
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .backgroundColor('#0D9FFB')
+ .width('80%')
+ .height('5%')
+ .onClick(() => {
+ if (this.message != 'Leaking') {
+ this.message = 'Leaking';
+ hilog.info(0x0000, 'testTag', 'Start leaking');
+ testNapi.leak();
+ }
+ })
+ // [End AppKillEvent_Button]
+ // [Start TimeOutEvent_Button]
+ Button($r('app.string.TimeOut_Button'))
.type(ButtonType.Capsule)
.margin({
top: 20
@@ -154,7 +188,7 @@ struct Index {
})
// [End FreezeEvent_Button]
// [Start AsanEvent_Button]
- Button($r('app.string.AsanEvent_Button'))
+ Button('address-sanitizer')
.type(ButtonType.Capsule)
.margin({
top: 20
@@ -163,9 +197,23 @@ struct Index {
.width('80%')
.height('5%')
.onClick(() => {
- testNapi.addressTest();
+ testNapi.addressSanitizerTest();
})
// [End AsanEvent_Button]
+ // [Start hicollie_timer_ndk_Button]
+ //添加点击事件,触发TestHiCollieTimerNdk方法。
+ Button('TestHiCollieTimerNdk')
+ .type(ButtonType.Capsule)
+ .margin({
+ top: 20
+ })
+ .backgroundColor('#0D9FFB')
+ .width('80%')
+ .height('5%')
+ .onClick(() => {
+ testNapi.TestHiCollieTimerNdk();
+ })
+ // [End hicollie_timer_ndk_Button]
}
.width('50%')
}
diff --git a/PerformanceAnalysisKit/HiAppEvent/EventSub/screenshots/Screenshot_EventSub_Index.jpg b/PerformanceAnalysisKit/HiAppEvent/EventSub/screenshots/Screenshot_EventSub_Index.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..fc42d269ce8fc8faaff78b003810830d699218f6
Binary files /dev/null and b/PerformanceAnalysisKit/HiAppEvent/EventSub/screenshots/Screenshot_EventSub_Index.jpg differ