From 25b083fa160d15540996f17e7c040bda810db90f Mon Sep 17 00:00:00 2001 From: zzhengxiang <2646125453@qq.com> Date: Tue, 26 Aug 2025 10:36:01 +0800 Subject: [PATCH] enable hiSysEvent & add jitfort tarce Signed-off-by: zzhengxiang <2646125453@qq.com> --- build_jsvm_inter.sh | 2 +- src/js_native_api_v8.cpp | 18 +++++++++++++++--- src/platform/platform_ohos.cpp | 32 ++++++++++++++++++++++++++------ src/platform/platform_ohos.h | 2 +- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/build_jsvm_inter.sh b/build_jsvm_inter.sh index 52d2072..0f4b26c 100755 --- a/build_jsvm_inter.sh +++ b/build_jsvm_inter.sh @@ -130,7 +130,7 @@ do_env() { # alway rebuild mkdir -p ${workdir} - argurment+=" -D__MUSL__ -D_LIBCPP_HAS_MUSL_LIBC -DOHOS_JS_ENGINE" + argurment+=" -D__MUSL__ -D_LIBCPP_HAS_MUSL_LIBC -DOHOS_JS_ENGINE -DENABLE_HISYSEVENT" argurment+=" -fstack-protector-strong" argurment+=" -Wl,-z,noexecstack" argurment+=" -Wl,-z,relro" diff --git a/src/js_native_api_v8.cpp b/src/js_native_api_v8.cpp index 02b3e4f..5b4d54f 100644 --- a/src/js_native_api_v8.cpp +++ b/src/js_native_api_v8.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "v8-debug.h" @@ -244,6 +245,10 @@ static constexpr const char* INTERNAL_TRACE_CATEGORIES[] = { constexpr uint32_t DEFAULT_CATEGORY_COUNT = 4; static constexpr JSVM_TraceCategory DEFAULT_CATAGORIES[] = { JSVM_TRACE_VM, JSVM_TRACE_EXECUTE, JSVM_TRACE_COMPILE, JSVM_TRACE_RUNTIME }; +const std::string jitEventMessage = "The application does not have ACL certificate authorization or has enable " + "the Sercure Shield Mode. The WASM capability will be disabled, and the " + "performance of JS execution will degrade. For details, see " + "\"Requesting Restricted Permission\" in the developer documentation."; static inline v8::ArrayBuffer::Allocator* GetOrCreateDefaultArrayBufferAllocator() { @@ -1064,7 +1069,7 @@ JSVM_Status OH_JSVM_Init(const JSVM_InitOptions* options) } initialized.store(true); - OHOS_CALL(platform::ohos::WriteHisysevent()); + OHOS_CALL(platform::ohos::WriteHisysevent("Init jsvm.")); OHOS_CALL(platform::ohos::ReportKeyThread(platform::ohos::ThreadRole::IMPORTANT_DISPLAY)); v8::V8::InitializePlatform(v8impl::g_platform.get()); @@ -1554,8 +1559,12 @@ JSVM_Status OH_JSVM_RunScript(JSVM_Env env, JSVM_Script script, JSVM_Value* resu CHECK_ARG(env, result); if (OHOS_SELECT(!platform::ohos::InJitMode(), false)) { - LOG(Info) << "Run OH_JSVM_RunScript may failed: The application does not have ACL certificate authorization " - "or has enabled the Secure Shield Mode."; + static std::once_flag jitCheckFlag; + std::call_once(jitCheckFlag, []() { + LOG(Info) << "Run OH_JSVM_RunScript may failed: The application does not have ACL certificate " + "authorization or has enabled the Secure Shield Mode."; + OHOS_CALL(platform::ohos::WriteHisysevent(v8impl::jitEventMessage)); + }); } auto jsvmData = reinterpret_cast(script); @@ -4923,6 +4932,7 @@ JSVM_Status OH_JSVM_CompileWasmModule(JSVM_Env env, if (OHOS_SELECT(!platform::ohos::InJitMode(), false)) { LOG(Error) << "Run OH_JSVM_CompileWasmModule failed: The application does not have ACL certificate " "authorization or has enabled the Secure Shield Mode."; + OHOS_CALL(platform::ohos::WriteHisysevent(v8impl::jitEventMessage)); return SetLastError(env, JSVM_JIT_MODE_EXPECTED); } CHECK_ARG(env, wasmBytecode); @@ -4957,6 +4967,7 @@ JSVM_Status OH_JSVM_CompileWasmFunction(JSVM_Env env, if (OHOS_SELECT(!platform::ohos::InJitMode(), false)) { LOG(Error) << "Run OH_JSVM_CompileWasmFunction failed: The application does not have ACL certificate " "authorization or has enabled the Secure Shield Mode."; + OHOS_CALL(platform::ohos::WriteHisysevent(v8impl::jitEventMessage)); return SetLastError(env, JSVM_JIT_MODE_EXPECTED); } CHECK_ARG(env, wasmModule); @@ -5004,6 +5015,7 @@ JSVM_Status OH_JSVM_CreateWasmCache(JSVM_Env env, JSVM_Value wasmModule, const u if (OHOS_SELECT(!platform::ohos::InJitMode(), false)) { LOG(Error) << "Run OH_JSVM_CreateWasmCache failed: The application does not have ACL certificate authorization" " or has enabled the Secure Shield Mode."; + OHOS_CALL(platform::ohos::WriteHisysevent(v8impl::jitEventMessage)); return SetLastError(env, JSVM_JIT_MODE_EXPECTED); } CHECK_ARG(env, wasmModule); diff --git a/src/platform/platform_ohos.cpp b/src/platform/platform_ohos.cpp index 02aaede..8d65e53 100644 --- a/src/platform/platform_ohos.cpp +++ b/src/platform/platform_ohos.cpp @@ -272,15 +272,35 @@ bool ProcessBundleName(std::string& bundleName) return true; } -void WriteHisysevent() +void WriteHisysevent(const std::string& message) { #ifdef ENABLE_HISYSEVENT - std::string bundleName; - if (!ProcessBundleName(bundleName)) { - bundleName = "INVALID_BUNDLE_NAME"; + static std::string bundleName = ""; + if (bundleName == "") { + if (!ProcessBundleName(bundleName)) { + bundleName = "INVALID_BUNDLE_NAME"; + } } - HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::JSVM_RUNTIME, "APP_STATS", - OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, "BUNDLE_NAME", bundleName); + std::unique_ptr name = std::make_unique(bundleName.size() + 1); + strcpy_s(name.get(), bundleName.size() + 1, bundleName.c_str()); + HiSysEventParam param = { + .name = "BUNDLE_NAME", + .t = HISYSEVENT_STRING, + .v = { .s = name.get() }, + .arraySize = 0, + }; + std::unique_ptr eventMessage = std::make_unique(message.size() + 1); + strcpy_s(eventMessage.get(), message.size() + 1, message.c_str()); + HiSysEventParam messageParam = { + .name = "MESSAGE", + .t = HISYSEVENT_STRING, + .v = { .s = eventMessage.get() }, + .arraySize = 0, + }; + HiSysEventParam params[] = { param, messageParam }; + OH_HiSysEvent_Write(OHOS::HiviewDFX::HiSysEvent::Domain::JSVM_RUNTIME, "APP_STATS", + HiSysEventEventType::HISYSEVENT_STATISTIC, + params, sizeof(params) / sizeof(params[0])); #endif } } // namespace ohos diff --git a/src/platform/platform_ohos.h b/src/platform/platform_ohos.h index c89daaa..12caafd 100644 --- a/src/platform/platform_ohos.h +++ b/src/platform/platform_ohos.h @@ -34,7 +34,7 @@ void ReportKeyThread(ThreadRole role); void SetSecurityMode(); -void WriteHisysevent(); +void WriteHisysevent(const std::string& message); bool InJitMode(); } // namespace ohos -- Gitee