From 1795510fa66187259996ea699d0c384f7136c125 Mon Sep 17 00:00:00 2001 From: chenraozhong Date: Mon, 3 Jun 2024 00:23:57 -0700 Subject: [PATCH] Add ReportData in JSVM Signed-off-by: chenraozhong --- node.gyp | 8 ++++++++ node.gypi | 3 +++ src/js_native_api_v8.cc | 25 +++++++++++++++++++++++++ src/js_native_api_v8.h | 25 +++++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/node.gyp b/node.gyp index 2b125de0d..fa8548435 100644 --- a/node.gyp +++ b/node.gyp @@ -717,12 +717,16 @@ # Warn when using deprecated V8 APIs. 'V8_DEPRECATION_WARNINGS=1', 'NODE_OPENSSL_SYSTEM_CERT_PATH="<(openssl_system_ca_path)"', + 'TARGET_OHOS', ], # - "C4244: conversion from 'type1' to 'type2', possible loss of data" # Ususaly safe. Disable for `dep`, enable for `src` 'msvs_disabled_warnings!': [4244], + 'ldflags' : [ + '<(NDK_SYS_ROOT)/usr/lib/aarch64-linux-ohos/libressched_client.z.so', + ], 'conditions': [ [ 'openssl_default_cipher_list!=""', { 'defines': [ @@ -1431,6 +1435,10 @@ ], 'defines': [ 'NODE_WANT_INTERNALS=1' ], + + 'ldflags' : [ + '<(NDK_SYS_ROOT)/usr/lib/aarch64-linux-ohos/libressched_client.z.so' + ], 'sources': [ 'src/node_snapshot_stub.cc', diff --git a/node.gypi b/node.gypi index 9138317c6..e4e736847 100644 --- a/node.gypi +++ b/node.gypi @@ -286,6 +286,9 @@ '-Wl,-z,noexecstack', '-Wl,--whole-archive <(v8_base)', '-Wl,--no-whole-archive', + ], + 'defines': [ + 'TARGET_OHOS', ] }], [ 'node_use_bundled_v8=="true" and v8_postmortem_support==1 and force_load=="true"', { diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 05f50953c..470a24977 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -17,6 +17,13 @@ #include "util.h" #include "sourcemap.def" +#ifdef TARGET_OHOS + #include + #include + extern "C" void ReportData(uint32_t resType, int64_t value, + const std::unordered_map& mapPayLoad); +#endif + #define CHECK_MAYBE_NOTHING(env, maybe, status) \ RETURN_STATUS_IF_FALSE((env), !((maybe).IsNothing()), (status)) @@ -1299,6 +1306,16 @@ v8::Platform* JSVM_Env__::platform() { JSVM_Status JSVM_CDECL OH_JSVM_Init(const JSVM_InitOptions* options) { + + #ifdef TARGET_OHOS + std::unordered_map payLoad = { + {"uid", std::to_string(getuid())}, + {"pid", std::to_string(getprocpid())}, + {"tid", std::to_string(getproctid())}, + {"role", std::to_string(v8impl::ResourceSchedule::ResType::ThreadRole::IMPORTANT_DISPLAY)}}; + ReportData(v8impl::ResourceSchedule::ResType::RES_TYPE_REPORT_KEY_THREAD, v8impl::ResourceSchedule::ResType::ReportChangeStatus::CREATE, payLoad); + #endif + v8::V8::InitializePlatform(v8impl::g_platform.get()); if (options && options->argc && options->argv) { @@ -1325,6 +1342,14 @@ JSVM_Status JSVM_CDECL OH_JSVM_GetVM(JSVM_Env env, JSVM_Status JSVM_CDECL OH_JSVM_CreateVM(const JSVM_CreateVMOptions* options, JSVM_VM* result) { + #ifdef TARGET_OHOS + std::unordered_map payLoad = { + {"uid", std::to_string(getuid())}, + {"pid", std::to_string(getprocpid())}, + {"tid", std::to_string(getproctid())}, + {"role", std::to_string(v8impl::ResourceSchedule::ResType::ThreadRole::IMPORTANT_DISPLAY)}}; + ReportData(v8impl::ResourceSchedule::ResType::RES_TYPE_REPORT_KEY_THREAD, v8impl::ResourceSchedule::ResType::ReportChangeStatus::CREATE, payLoad); + #endif v8::Isolate::CreateParams create_params; auto externalReferences = v8impl::externalReferenceRegistry.data(); create_params.external_references = externalReferences; diff --git a/src/js_native_api_v8.h b/src/js_native_api_v8.h index 9d4636298..3152ceac3 100644 --- a/src/js_native_api_v8.h +++ b/src/js_native_api_v8.h @@ -543,6 +543,31 @@ inline void CfgFinalizedCallback(JSVM_Env env, void* finalizeData, void* finaliz } delete cfg; } + +#ifdef TARGET_OHOS +namespace ResourceSchedule { +namespace ResType { + enum : uint32_t { + RES_TYPE_REPORT_KEY_THREAD = 39 + }; + + enum ReportChangeStatus : int64_t { + CREATE = 0, + REMOVE = 1, + }; + + enum ThreadRole : int64_t { + USER_INTERACT = 0, + NORMAL_DISPLAY = 1, + IMPORTANT_DISPLAY = 2, + NORMAL_AUDIO = 3, + IMPORTANT_AUDIO = 4, + IMAGE_DECODE = 5, + }; +} +} +#endif + } // end of namespace v8impl #endif // SRC_JS_NATIVE_API_V8_H_ -- Gitee